@@ -51,29 +51,20 @@ var (
5151
5252// NewCommand created a new `upload` command
5353func NewCommand () * cobra.Command {
54- var uploadFields []string
55- var parsedUploadFields map [string ]string
54+ uploadFields := map [string ]string {}
5655 uploadCommand := & cobra.Command {
57- Use : "upload" ,
58- Short : tr ("Upload Arduino sketches." ),
59- Long : tr ("Upload Arduino sketches. This does NOT compile the sketch prior to upload." ),
60- Example : " " + os .Args [0 ] + " upload /home/user/Arduino/MySketch" ,
61- 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 ),
6263 PreRun : func (cmd * cobra.Command , args []string ) {
6364 arguments .CheckFlagsConflicts (cmd , "input-file" , "input-dir" )
64- if len (uploadFields ) > 0 {
65- parsedUploadFields = map [string ]string {}
66- for _ , field := range uploadFields {
67- split := strings .SplitN (field , "=" , 2 )
68- if len (split ) != 2 {
69- feedback .Fatal (tr ("Invalid upload field: %s" , field ), feedback .ErrBadArgument )
70- }
71- parsedUploadFields [split [0 ]] = split [1 ]
72- }
73- }
7465 },
7566 Run : func (cmd * cobra.Command , args []string ) {
76- runUploadCommand (args , parsedUploadFields )
67+ runUploadCommand (args , uploadFields )
7768 },
7869 }
7970
@@ -87,7 +78,7 @@ func NewCommand() *cobra.Command {
8778 programmer .AddToCommand (uploadCommand )
8879 uploadCommand .Flags ().BoolVar (& dryRun , "dry-run" , false , tr ("Do not perform the actual upload, just log out actions" ))
8980 uploadCommand .Flags ().MarkHidden ("dry-run" )
90- uploadCommand . Flags (). StringArrayVar ( & uploadFields , "upload-field" , uploadFields , tr ("Set a value for a field required to upload." )+ " (field=value)" )
81+ arguments . AddKeyValuePFlag ( uploadCommand , & uploadFields , "upload-field" , "F" , nil , tr ("Set a value for a field required to upload." ))
9182 return uploadCommand
9283}
9384
0 commit comments