@@ -30,13 +30,13 @@ import (
30
30
)
31
31
32
32
var (
33
- fqbn string
33
+ fqbn arguments. Fqbn
34
34
port arguments.Port
35
35
verbose bool
36
36
verify bool
37
37
importDir string
38
38
importFile string
39
- programmer string
39
+ programmer arguments. Programmer
40
40
dryRun bool
41
41
tr = i18n .Tr
42
42
)
@@ -49,36 +49,25 @@ func NewCommand() *cobra.Command {
49
49
Long : tr ("Upload Arduino sketches. This does NOT compile the sketch prior to upload." ),
50
50
Example : " " + os .Args [0 ] + " upload /home/user/Arduino/MySketch" ,
51
51
Args : cobra .MaximumNArgs (1 ),
52
- PreRun : checkFlagsConflicts ,
53
- Run : run ,
52
+ PreRun : func (cmd * cobra.Command , args []string ) {
53
+ arguments .CheckFlagsConflicts (cmd , "input-file" , "input-dir" )
54
+ },
55
+ Run : runUploadCommand ,
54
56
}
55
57
56
- uploadCommand .Flags ().StringVarP (& fqbn , "fqbn" , "b" , "" , tr ("Fully Qualified Board Name, e.g.: arduino:avr:uno" ))
57
- uploadCommand .RegisterFlagCompletionFunc ("fqbn" , func (cmd * cobra.Command , args []string , toComplete string ) ([]string , cobra.ShellCompDirective ) {
58
- return arguments .GetInstalledBoards (), cobra .ShellCompDirectiveDefault
59
- })
58
+ fqbn .AddToCommand (uploadCommand )
60
59
port .AddToCommand (uploadCommand )
61
60
uploadCommand .Flags ().StringVarP (& importDir , "input-dir" , "" , "" , tr ("Directory containing binaries to upload." ))
62
61
uploadCommand .Flags ().StringVarP (& importFile , "input-file" , "i" , "" , tr ("Binary file to upload." ))
63
62
uploadCommand .Flags ().BoolVarP (& verify , "verify" , "t" , false , tr ("Verify uploaded binary after the upload." ))
64
63
uploadCommand .Flags ().BoolVarP (& verbose , "verbose" , "v" , false , tr ("Optional, turns on verbose mode." ))
65
- uploadCommand .Flags ().StringVarP (& programmer , "programmer" , "P" , "" , tr ("Optional, use the specified programmer to upload." ))
66
- uploadCommand .RegisterFlagCompletionFunc ("programmer" , func (cmd * cobra.Command , args []string , toComplete string ) ([]string , cobra.ShellCompDirective ) {
67
- return arguments .GetInstalledProgrammers (), cobra .ShellCompDirectiveDefault
68
- })
64
+ programmer .AddToCommand (uploadCommand )
69
65
uploadCommand .Flags ().BoolVar (& dryRun , "dry-run" , false , tr ("Do not perform the actual upload, just log out actions" ))
70
66
uploadCommand .Flags ().MarkHidden ("dry-run" )
71
67
return uploadCommand
72
68
}
73
69
74
- func checkFlagsConflicts (command * cobra.Command , args []string ) {
75
- if importFile != "" && importDir != "" {
76
- feedback .Errorf (tr ("error: %s and %s flags cannot be used together" , "--input-file" , "--input-dir" ))
77
- os .Exit (errorcodes .ErrBadArgument )
78
- }
79
- }
80
-
81
- func run (command * cobra.Command , args []string ) {
70
+ func runUploadCommand (command * cobra.Command , args []string ) {
82
71
instance := instance .CreateAndInit ()
83
72
84
73
path := ""
@@ -90,15 +79,15 @@ func run(command *cobra.Command, args []string) {
90
79
sk := arguments .NewSketch (sketchPath )
91
80
discoveryPort := port .GetDiscoveryPort (instance , sk )
92
81
93
- if fqbn == "" && sk != nil && sk .Metadata != nil {
82
+ if fqbn . String () == "" && sk != nil && sk .Metadata != nil {
94
83
// If the user didn't specify an FQBN and a sketch.json file is present
95
84
// read it from there.
96
- fqbn = sk .Metadata .CPU .Fqbn
85
+ fqbn . Set ( sk .Metadata .CPU .Fqbn )
97
86
}
98
87
99
88
userFieldRes , err := upload .SupportedUserFields (context .Background (), & rpc.SupportedUserFieldsRequest {
100
89
Instance : instance ,
101
- Fqbn : fqbn ,
90
+ Fqbn : fqbn . String () ,
102
91
Protocol : discoveryPort .Protocol ,
103
92
})
104
93
if err != nil {
@@ -118,14 +107,14 @@ func run(command *cobra.Command, args []string) {
118
107
119
108
if _ , err := upload .Upload (context .Background (), & rpc.UploadRequest {
120
109
Instance : instance ,
121
- Fqbn : fqbn ,
110
+ Fqbn : fqbn . String () ,
122
111
SketchPath : path ,
123
112
Port : discoveryPort .ToRPC (),
124
113
Verbose : verbose ,
125
114
Verify : verify ,
126
115
ImportFile : importFile ,
127
116
ImportDir : importDir ,
128
- Programmer : programmer ,
117
+ Programmer : programmer . String () ,
129
118
DryRun : dryRun ,
130
119
UserFields : fields ,
131
120
}, os .Stdout , os .Stderr ); err != nil {
0 commit comments