@@ -51,29 +51,20 @@ var (
51
51
52
52
// NewCommand created a new `upload` command
53
53
func NewCommand () * cobra.Command {
54
- var uploadFields []string
55
- var parsedUploadFields map [string ]string
54
+ uploadFields := map [string ]string {}
56
55
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 ),
62
63
PreRun : func (cmd * cobra.Command , args []string ) {
63
64
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
- }
74
65
},
75
66
Run : func (cmd * cobra.Command , args []string ) {
76
- runUploadCommand (args , parsedUploadFields )
67
+ runUploadCommand (args , uploadFields )
77
68
},
78
69
}
79
70
@@ -87,7 +78,7 @@ func NewCommand() *cobra.Command {
87
78
programmer .AddToCommand (uploadCommand )
88
79
uploadCommand .Flags ().BoolVar (& dryRun , "dry-run" , false , tr ("Do not perform the actual upload, just log out actions" ))
89
80
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." ))
91
82
return uploadCommand
92
83
}
93
84
0 commit comments