@@ -39,25 +39,25 @@ import (
39
39
)
40
40
41
41
var (
42
- fqbn string // Fully Qualified Board Name, e.g.: arduino:avr:uno.
43
- showProperties bool // Show all build preferences used instead of compiling.
44
- preprocess bool // Print preprocessed code to stdout.
45
- buildCachePath string // Builds of 'core.a' are saved into this path to be cached and reused.
46
- buildPath string // Path where to save compiled files.
47
- buildProperties []string // List of custom build properties separated by commas. Or can be used multiple times for multiple properties.
48
- warnings string // Used to tell gcc which warning level to use.
49
- verbose bool // Turns on verbose mode.
50
- quiet bool // Suppresses almost every output.
51
- vidPid string // VID/PID specific build properties.
52
- uploadAfterCompile bool // Upload the binary after the compilation.
53
- port arguments.Port // Upload port, e.g.: COM10 or /dev/ttyACM0.
54
- verify bool // Upload, verify uploaded binary after the upload.
55
- exportDir string // The compiled binary is written to this file
56
- optimizeForDebug bool // Optimize compile output for debug, not for release
57
- programmer string // Use the specified programmer to upload
58
- clean bool // Cleanup the build folder and do not use any cached build
59
- compilationDatabaseOnly bool // Only create compilation database without actually compiling
60
- sourceOverrides string // Path to a .json file that contains a set of replacements of the sketch source code.
42
+ fqbn arguments. Fqbn // Fully Qualified Board Name, e.g.: arduino:avr:uno.
43
+ showProperties bool // Show all build preferences used instead of compiling.
44
+ preprocess bool // Print preprocessed code to stdout.
45
+ buildCachePath string // Builds of 'core.a' are saved into this path to be cached and reused.
46
+ buildPath string // Path where to save compiled files.
47
+ buildProperties []string // List of custom build properties separated by commas. Or can be used multiple times for multiple properties.
48
+ warnings string // Used to tell gcc which warning level to use.
49
+ verbose bool // Turns on verbose mode.
50
+ quiet bool // Suppresses almost every output.
51
+ vidPid string // VID/PID specific build properties.
52
+ uploadAfterCompile bool // Upload the binary after the compilation.
53
+ port arguments.Port // Upload port, e.g.: COM10 or /dev/ttyACM0.
54
+ verify bool // Upload, verify uploaded binary after the upload.
55
+ exportDir string // The compiled binary is written to this file
56
+ optimizeForDebug bool // Optimize compile output for debug, not for release
57
+ programmer arguments. Programmer // Use the specified programmer to upload
58
+ clean bool // Cleanup the build folder and do not use any cached build
59
+ compilationDatabaseOnly bool // Only create compilation database without actually compiling
60
+ sourceOverrides string // Path to a .json file that contains a set of replacements of the sketch source code.
61
61
// library and libraries sound similar but they're actually different.
62
62
// library expects a path to the root folder of one single library.
63
63
// libraries expects a path to a directory containing multiple libraries, similarly to the <directories.user>/libraries path.
68
68
69
69
// NewCommand created a new `compile` command
70
70
func NewCommand () * cobra.Command {
71
- command := & cobra.Command {
71
+ compileCommand := & cobra.Command {
72
72
Use : "compile" ,
73
73
Short : tr ("Compiles Arduino sketches." ),
74
74
Long : tr ("Compiles Arduino sketches." ),
@@ -81,51 +81,45 @@ func NewCommand() *cobra.Command {
81
81
Run : run ,
82
82
}
83
83
84
- command .Flags ().StringVarP (& fqbn , "fqbn" , "b" , "" , tr ("Fully Qualified Board Name, e.g.: arduino:avr:uno" ))
85
- command .RegisterFlagCompletionFunc ("fqbn" , func (cmd * cobra.Command , args []string , toComplete string ) ([]string , cobra.ShellCompDirective ) {
86
- return arguments .GetInstalledBoards (), cobra .ShellCompDirectiveDefault
87
- })
88
- command .Flags ().BoolVar (& showProperties , "show-properties" , false , tr ("Show all build properties used instead of compiling." ))
89
- command .Flags ().BoolVar (& preprocess , "preprocess" , false , tr ("Print preprocessed code to stdout instead of compiling." ))
90
- command .Flags ().StringVar (& buildCachePath , "build-cache-path" , "" , tr ("Builds of 'core.a' are saved into this path to be cached and reused." ))
91
- command .Flags ().StringVarP (& exportDir , "output-dir" , "" , "" , tr ("Save build artifacts in this directory." ))
92
- command .Flags ().StringVar (& buildPath , "build-path" , "" ,
84
+ fqbn .AddToCommand (compileCommand )
85
+ compileCommand .Flags ().BoolVar (& showProperties , "show-properties" , false , tr ("Show all build properties used instead of compiling." ))
86
+ compileCommand .Flags ().BoolVar (& preprocess , "preprocess" , false , tr ("Print preprocessed code to stdout instead of compiling." ))
87
+ compileCommand .Flags ().StringVar (& buildCachePath , "build-cache-path" , "" , tr ("Builds of 'core.a' are saved into this path to be cached and reused." ))
88
+ compileCommand .Flags ().StringVarP (& exportDir , "output-dir" , "" , "" , tr ("Save build artifacts in this directory." ))
89
+ compileCommand .Flags ().StringVar (& buildPath , "build-path" , "" ,
93
90
tr ("Path where to save compiled files. If omitted, a directory will be created in the default temporary path of your OS." ))
94
- command .Flags ().StringSliceVar (& buildProperties , "build-properties" , []string {},
91
+ compileCommand .Flags ().StringSliceVar (& buildProperties , "build-properties" , []string {},
95
92
tr ("List of custom build properties separated by commas. Or can be used multiple times for multiple properties." ))
96
- command .Flags ().StringArrayVar (& buildProperties , "build-property" , []string {},
93
+ compileCommand .Flags ().StringArrayVar (& buildProperties , "build-property" , []string {},
97
94
tr ("Override a build property with a custom value. Can be used multiple times for multiple properties." ))
98
- command .Flags ().StringVar (& warnings , "warnings" , "none" ,
95
+ compileCommand .Flags ().StringVar (& warnings , "warnings" , "none" ,
99
96
tr (`Optional, can be: %s. Used to tell gcc which warning level to use (-W flag).` , "none, default, more, all" ))
100
- command .Flags ().BoolVarP (& verbose , "verbose" , "v" , false , tr ("Optional, turns on verbose mode." ))
101
- command .Flags ().BoolVar (& quiet , "quiet" , false , tr ("Optional, suppresses almost every output." ))
102
- command .Flags ().BoolVarP (& uploadAfterCompile , "upload" , "u" , false , tr ("Upload the binary after the compilation." ))
103
- port .AddToCommand (command )
104
- command .Flags ().BoolVarP (& verify , "verify" , "t" , false , tr ("Verify uploaded binary after the upload." ))
105
- command .Flags ().StringVar (& vidPid , "vid-pid" , "" , tr ("When specified, VID/PID specific build properties are used, if board supports them." ))
106
- command .Flags ().StringSliceVar (& library , "library" , []string {},
97
+ compileCommand .Flags ().BoolVarP (& verbose , "verbose" , "v" , false , tr ("Optional, turns on verbose mode." ))
98
+ compileCommand .Flags ().BoolVar (& quiet , "quiet" , false , tr ("Optional, suppresses almost every output." ))
99
+ compileCommand .Flags ().BoolVarP (& uploadAfterCompile , "upload" , "u" , false , tr ("Upload the binary after the compilation." ))
100
+ port .AddToCommand (compileCommand )
101
+ compileCommand .Flags ().BoolVarP (& verify , "verify" , "t" , false , tr ("Verify uploaded binary after the upload." ))
102
+ compileCommand .Flags ().StringVar (& vidPid , "vid-pid" , "" , tr ("When specified, VID/PID specific build properties are used, if board supports them." ))
103
+ compileCommand .Flags ().StringSliceVar (& library , "library" , []string {},
107
104
tr ("List of paths to libraries root folders. Libraries set this way have top priority in case of conflicts. Can be used multiple times for different libraries." ))
108
- command .Flags ().StringSliceVar (& libraries , "libraries" , []string {},
105
+ compileCommand .Flags ().StringSliceVar (& libraries , "libraries" , []string {},
109
106
tr ("List of custom libraries dir paths separated by commas. Or can be used multiple times for multiple libraries dir paths." ))
110
- command .Flags ().BoolVar (& optimizeForDebug , "optimize-for-debug" , false , tr ("Optional, optimize compile output for debugging, rather than for release." ))
111
- command .Flags ().StringVarP (& programmer , "programmer" , "P" , "" , tr ("Optional, use the specified programmer to upload." ))
112
- command .RegisterFlagCompletionFunc ("programmer" , func (cmd * cobra.Command , args []string , toComplete string ) ([]string , cobra.ShellCompDirective ) {
113
- return arguments .GetInstalledProgrammers (), cobra .ShellCompDirectiveDefault
114
- })
115
- command .Flags ().BoolVar (& compilationDatabaseOnly , "only-compilation-database" , false , tr ("Just produce the compilation database, without actually compiling. All build commands are skipped except pre* hooks." ))
116
- command .Flags ().BoolVar (& clean , "clean" , false , tr ("Optional, cleanup the build folder and do not use any cached build." ))
107
+ compileCommand .Flags ().BoolVar (& optimizeForDebug , "optimize-for-debug" , false , tr ("Optional, optimize compile output for debugging, rather than for release." ))
108
+ programmer .AddToCommand (compileCommand )
109
+ compileCommand .Flags ().BoolVar (& compilationDatabaseOnly , "only-compilation-database" , false , tr ("Just produce the compilation database, without actually compiling. All build commands are skipped except pre* hooks." ))
110
+ compileCommand .Flags ().BoolVar (& clean , "clean" , false , tr ("Optional, cleanup the build folder and do not use any cached build." ))
117
111
// We must use the following syntax for this flag since it's also bound to settings.
118
112
// This must be done because the value is set when the binding is accessed from viper. Accessing from cobra would only
119
113
// read the value if the flag is set explicitly by the user.
120
- command .Flags ().BoolP ("export-binaries" , "e" , false , tr ("If set built binaries will be exported to the sketch folder." ))
121
- command .Flags ().StringVar (& sourceOverrides , "source-override" , "" , tr ("Optional. Path to a .json file that contains a set of replacements of the sketch source code." ))
122
- command .Flag ("source-override" ).Hidden = true
114
+ compileCommand .Flags ().BoolP ("export-binaries" , "e" , false , tr ("If set built binaries will be exported to the sketch folder." ))
115
+ compileCommand .Flags ().StringVar (& sourceOverrides , "source-override" , "" , tr ("Optional. Path to a .json file that contains a set of replacements of the sketch source code." ))
116
+ compileCommand .Flag ("source-override" ).Hidden = true
123
117
124
- configuration .Settings .BindPFlag ("sketch.always_export_binaries" , command .Flags ().Lookup ("export-binaries" ))
118
+ configuration .Settings .BindPFlag ("sketch.always_export_binaries" , compileCommand .Flags ().Lookup ("export-binaries" ))
125
119
126
- command .Flags ().MarkDeprecated ("build-properties" , tr ("please use --build-property instead." ))
120
+ compileCommand .Flags ().MarkDeprecated ("build-properties" , tr ("please use --build-property instead." ))
127
121
128
- return command
122
+ return compileCommand
129
123
}
130
124
131
125
func run (cmd * cobra.Command , args []string ) {
@@ -164,7 +158,7 @@ func run(cmd *cobra.Command, args []string) {
164
158
165
159
compileRequest := & rpc.CompileRequest {
166
160
Instance : inst ,
167
- Fqbn : fqbn ,
161
+ Fqbn : fqbn . String () ,
168
162
SketchPath : sketchPath .String (),
169
163
ShowProperties : showProperties ,
170
164
Preprocess : preprocess ,
@@ -210,7 +204,7 @@ func run(cmd *cobra.Command, args []string) {
210
204
211
205
userFieldRes , err := upload .SupportedUserFields (context .Background (), & rpc.SupportedUserFieldsRequest {
212
206
Instance : inst ,
213
- Fqbn : fqbn ,
207
+ Fqbn : fqbn . String () ,
214
208
Protocol : discoveryPort .Protocol ,
215
209
})
216
210
if err != nil {
@@ -226,13 +220,13 @@ func run(cmd *cobra.Command, args []string) {
226
220
227
221
uploadRequest := & rpc.UploadRequest {
228
222
Instance : inst ,
229
- Fqbn : fqbn ,
223
+ Fqbn : fqbn . String () ,
230
224
SketchPath : sketchPath .String (),
231
225
Port : discoveryPort .ToRPC (),
232
226
Verbose : verbose ,
233
227
Verify : verify ,
234
228
ImportDir : buildPath ,
235
- Programmer : programmer ,
229
+ Programmer : programmer . String () ,
236
230
UserFields : fields ,
237
231
}
238
232
0 commit comments