@@ -51,16 +51,21 @@ var (
51
51
52
52
// NewCommand created a new `upload` command
53
53
func NewCommand () * cobra.Command {
54
+ uploadFields := map [string ]string {}
54
55
uploadCommand := & cobra.Command {
55
- Use : "upload" ,
56
- Short : tr ("Upload Arduino sketches." ),
57
- Long : tr ("Upload Arduino sketches. This does NOT compile the sketch prior to upload." ),
58
- Example : " " + os .Args [0 ] + " upload /home/user/Arduino/MySketch" ,
59
- Args : cobra .MaximumNArgs (1 ),
56
+ Use : "upload" ,
57
+ Short : tr ("Upload Arduino sketches." ),
58
+ Long : tr ("Upload Arduino sketches. This does NOT compile the sketch prior to upload." ),
59
+ Example : "" +
60
+ " " + os .Args [0 ] + " upload /home/user/Arduino/MySketch -p /dev/ttyACM0 -b arduino:avr:uno\n " +
61
+ " " + os .Args [0 ] + " upload -p 192.168.10.1 -b arduino:avr:uno --upload-field password=abc" ,
62
+ Args : cobra .MaximumNArgs (1 ),
60
63
PreRun : func (cmd * cobra.Command , args []string ) {
61
64
arguments .CheckFlagsConflicts (cmd , "input-file" , "input-dir" )
62
65
},
63
- Run : runUploadCommand ,
66
+ Run : func (cmd * cobra.Command , args []string ) {
67
+ runUploadCommand (args , uploadFields )
68
+ },
64
69
}
65
70
66
71
fqbnArg .AddToCommand (uploadCommand )
@@ -73,10 +78,11 @@ func NewCommand() *cobra.Command {
73
78
programmer .AddToCommand (uploadCommand )
74
79
uploadCommand .Flags ().BoolVar (& dryRun , "dry-run" , false , tr ("Do not perform the actual upload, just log out actions" ))
75
80
uploadCommand .Flags ().MarkHidden ("dry-run" )
81
+ arguments .AddKeyValuePFlag (uploadCommand , & uploadFields , "upload-field" , "F" , nil , tr ("Set a value for a field required to upload." ))
76
82
return uploadCommand
77
83
}
78
84
79
- func runUploadCommand (command * cobra. Command , args [ ]string ) {
85
+ func runUploadCommand (args [] string , uploadFieldsArgs map [ string ]string ) {
80
86
logrus .Info ("Executing `arduino-cli upload`" )
81
87
82
88
path := ""
@@ -147,12 +153,24 @@ func runUploadCommand(command *cobra.Command, args []string) {
147
153
148
154
fields := map [string ]string {}
149
155
if len (userFieldRes .UserFields ) > 0 {
150
- feedback .Print (tr ("Uploading to specified board using %s protocol requires the following info:" , port .Protocol ))
151
- if f , err := arguments .AskForUserFields (userFieldRes .UserFields ); err != nil {
152
- msg := fmt .Sprintf ("%s: %s" , tr ("Error getting user input" ), err )
153
- feedback .Fatal (msg , feedback .ErrGeneric )
156
+ if len (uploadFieldsArgs ) > 0 {
157
+ // If the user has specified some fields via cmd-line, we don't ask for them
158
+ for _ , field := range userFieldRes .UserFields {
159
+ if value , ok := uploadFieldsArgs [field .Name ]; ok {
160
+ fields [field .Name ] = value
161
+ } else {
162
+ feedback .Fatal (tr ("Missing required upload field: %s" , field .Name ), feedback .ErrBadArgument )
163
+ }
164
+ }
154
165
} else {
155
- fields = f
166
+ // Otherwise prompt the user for them
167
+ feedback .Print (tr ("Uploading to specified board using %s protocol requires the following info:" , port .Protocol ))
168
+ if f , err := arguments .AskForUserFields (userFieldRes .UserFields ); err != nil {
169
+ msg := fmt .Sprintf ("%s: %s" , tr ("Error getting user input" ), err )
170
+ feedback .Fatal (msg , feedback .ErrGeneric )
171
+ } else {
172
+ fields = f
173
+ }
156
174
}
157
175
}
158
176
0 commit comments