Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
arduino-cli
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Operations
Operations
Metrics
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
arduino-cli
Commits
e8e359b9
Commit
e8e359b9
authored
May 24, 2019
by
Cristian Maglie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed no more used formatter/output module
parent
c57b0755
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
0 additions
and
119 deletions
+0
-119
common/formatter/output/README.adoc
common/formatter/output/README.adoc
+0
-53
common/formatter/output/sketch_structs.go
common/formatter/output/sketch_structs.go
+0
-66
No files found.
common/formatter/output/README.adoc
deleted
100644 → 0
View file @
c57b0755
:source-highlighter: pygments
:pygments-style: manni
= Output Package
Alessandro Sanino <a.sanino@arduino.cc>
This package provides structs and helpers to be used in the rest of the project.
Usually it is paired to link:../https://github.com/bcmi-labs/arduino-cli/common/formatter[Formatter Package]
== Output structs
Any Output struct must implement a set of functions, depending on the formatter.
In the case of TextFormatter and JSONFormatter.
[source, go]
----
String() string // For Text Formatter.
marshalJSON() ([]byte, error) // For JSON formatter.
----
Normally `marshalJSON()` is already implemented using JSON Go Tags if using structs.
=== Example of correct output structs
This is a correct example about how to build an output struct:
[source, go]
----
// ExampleOutput is a struct which implements Formattable
// JSON tags are used automatically by marshalJSON.
type ExampleOutput struct {
ExampleOfField interface{} `json:"exampleOfField"`
ExampleOfAnotherField int `json:"ExampleOfAnotherField"`
ExampleOfRequiredField string `json:"ExampleOfRequiredField,required"`
ExampleOfOptionalField string `json:"ExampleOfOptionalField,omitempty"`
}
// String() is used by fmt.Printf, fmt.Sprintf, fmt.Fprintf families of functions,
// and TextFormatter.
func (eo ExampleOutput) String() string {
ret := fmt.Sprintln("ExampleOfField:", eo.ExampleOfField)
ret += fmt.Sprintln("ExampleOfAnotherField:", eo.ExampleOfAnotherField)
ret += fmt.Sprintln("ExampleOfRequiredField (error if not set):", eo.ExampleOfRequiredField)
// Do not show optional fields.
if eo.ExampleOfOptionalField != "" {
ret += fmt.Sprintln("ExampleOfOptionalField (may not appear if not set):", eo.ExampleOfField)
}
// Print that required variable is missing.
if eo.ExampleOfRequiredField == "" {
ret += fmt.Sprintln("WARNING : Required field ExampleOfRequiredField is not set")
}
return ret
}
----
common/formatter/output/sketch_structs.go
deleted
100644 → 0
View file @
c57b0755
/*
* This file is part of arduino-cli.
*
* Copyright 2018 ARDUINO SA (http://www.arduino.cc/)
*
* This software is released under the GNU General Public License version 3,
* which covers the main part of arduino-cli.
* The terms of this license can be found at:
* https://www.gnu.org/licenses/gpl-3.0.en.html
*
* You can be released from the requirements of the above licenses by purchasing
* a commercial license. Buying such a license is mandatory if you want to modify or
* otherwise use the software for commercial activities involving the Arduino
* software without disclosing the source code of your own applications. To purchase
* a commercial license, send an email to license@arduino.cc.
*/
package
output
import
"fmt"
// SketchSyncResult contains the result of an `arduino sketch sync` operation.
type
SketchSyncResult
struct
{
PushedSketches
[]
string
`json:"pushedSketches,required"`
PulledSketches
[]
string
`json:"pulledSketches,required"`
SkippedSketches
[]
string
`json:"skippedSketches,required"`
Errors
[]
SketchSyncError
`json:"errors,required"`
}
// SketchSyncError represents an error during a `arduino sketch sync` operation.
type
SketchSyncError
struct
{
Sketch
string
`json:"sketch,required"`
Error
error
`json:"error,required"`
}
// String returns a string representation of the object. For this object
// it is used to provide verbose info of a sync process.
func
(
ssr
SketchSyncResult
)
String
()
string
{
totalSketches
:=
len
(
ssr
.
SkippedSketches
)
+
len
(
ssr
.
PushedSketches
)
+
len
(
ssr
.
PulledSketches
)
+
len
(
ssr
.
Errors
)
//this function iterates an array and if it's not empty pretty prints it.
iterate
:=
func
(
array
[]
string
,
header
string
)
string
{
ret
:=
""
if
len
(
array
)
>
0
{
ret
+=
fmt
.
Sprintln
(
header
)
for
_
,
item
:=
range
array
{
ret
+=
fmt
.
Sprintln
(
" -"
,
item
)
}
}
return
ret
}
ret
:=
fmt
.
Sprintf
(
"%d sketches synced:
\n
"
,
totalSketches
)
ret
+=
iterate
(
ssr
.
PushedSketches
,
"Pushed Sketches:"
)
ret
+=
iterate
(
ssr
.
PulledSketches
,
"Pulled Sketches:"
)
ret
+=
iterate
(
ssr
.
SkippedSketches
,
"Skipped Sketches:"
)
if
len
(
ssr
.
Errors
)
>
0
{
ret
+=
fmt
.
Sprintln
(
"Errors:"
)
for
_
,
item
:=
range
ssr
.
Errors
{
ret
+=
fmt
.
Sprintf
(
" - Sketch %s : %s
\n
"
,
item
.
Sketch
,
item
.
Error
)
}
}
return
ret
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment