@@ -39,25 +39,25 @@ import (
3939)
4040
4141var (
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.
6161 // library and libraries sound similar but they're actually different.
6262 // library expects a path to the root folder of one single library.
6363 // libraries expects a path to a directory containing multiple libraries, similarly to the <directories.user>/libraries path.
6868
6969// NewCommand created a new `compile` command
7070func NewCommand () * cobra.Command {
71- command := & cobra.Command {
71+ compileCommand := & cobra.Command {
7272 Use : "compile" ,
7373 Short : tr ("Compiles Arduino sketches." ),
7474 Long : tr ("Compiles Arduino sketches." ),
@@ -81,51 +81,45 @@ func NewCommand() *cobra.Command {
8181 Run : run ,
8282 }
8383
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" , "" ,
9390 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 {},
9592 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 {},
9794 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" ,
9996 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 {},
107104 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 {},
109106 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." ))
117111 // We must use the following syntax for this flag since it's also bound to settings.
118112 // This must be done because the value is set when the binding is accessed from viper. Accessing from cobra would only
119113 // 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
123117
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" ))
125119
126- command .Flags ().MarkDeprecated ("build-properties" , tr ("please use --build-property instead." ))
120+ compileCommand .Flags ().MarkDeprecated ("build-properties" , tr ("please use --build-property instead." ))
127121
128- return command
122+ return compileCommand
129123}
130124
131125func run (cmd * cobra.Command , args []string ) {
@@ -164,7 +158,7 @@ func run(cmd *cobra.Command, args []string) {
164158
165159 compileRequest := & rpc.CompileRequest {
166160 Instance : inst ,
167- Fqbn : fqbn ,
161+ Fqbn : fqbn . String () ,
168162 SketchPath : sketchPath .String (),
169163 ShowProperties : showProperties ,
170164 Preprocess : preprocess ,
@@ -210,7 +204,7 @@ func run(cmd *cobra.Command, args []string) {
210204
211205 userFieldRes , err := upload .SupportedUserFields (context .Background (), & rpc.SupportedUserFieldsRequest {
212206 Instance : inst ,
213- Fqbn : fqbn ,
207+ Fqbn : fqbn . String () ,
214208 Protocol : discoveryPort .Protocol ,
215209 })
216210 if err != nil {
@@ -226,13 +220,13 @@ func run(cmd *cobra.Command, args []string) {
226220
227221 uploadRequest := & rpc.UploadRequest {
228222 Instance : inst ,
229- Fqbn : fqbn ,
223+ Fqbn : fqbn . String () ,
230224 SketchPath : sketchPath .String (),
231225 Port : discoveryPort .ToRPC (),
232226 Verbose : verbose ,
233227 Verify : verify ,
234228 ImportDir : buildPath ,
235- Programmer : programmer ,
229+ Programmer : programmer . String () ,
236230 UserFields : fields ,
237231 }
238232
0 commit comments