Skip to content

Commit dd2c548

Browse files
committed
factor out the programmer flag handling
1 parent 394fab7 commit dd2c548

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
lines changed

cli/arguments/programmer.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to license@arduino.cc.
15+
16+
package arguments
17+
18+
import "github.com/spf13/cobra"
19+
20+
// Programmer contains the programmer flag data.
21+
// This is useful so all flags used by commands that need
22+
// this information are consistent with each other.
23+
type Programmer struct {
24+
programmer string
25+
}
26+
27+
// AddToCommand adds the flags used to set the programmer to the specified Command
28+
func (p *Programmer) AddToCommand(cmd *cobra.Command) {
29+
cmd.Flags().StringVarP(&p.programmer, "programmer", "P", "", tr("Programmer to use, e.g: atmel_ice"))
30+
cmd.RegisterFlagCompletionFunc("programmer", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
31+
return GetInstalledProgrammers(), cobra.ShellCompDirectiveDefault
32+
})
33+
}
34+
35+
// String returns the programmer
36+
func (p *Programmer) String() string {
37+
return p.programmer
38+
}

cli/burnbootloader/burnbootloader.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ var (
3434
port arguments.Port
3535
verbose bool
3636
verify bool
37-
programmer string
37+
programmer arguments.Programmer
3838
dryRun bool
3939
tr = i18n.Tr
4040
)
@@ -52,12 +52,9 @@ func NewCommand() *cobra.Command {
5252

5353
fqbn.AddToCommand(burnBootloaderCommand)
5454
port.AddToCommand(burnBootloaderCommand)
55+
programmer.AddToCommand(burnBootloaderCommand)
5556
burnBootloaderCommand.Flags().BoolVarP(&verify, "verify", "t", false, tr("Verify uploaded binary after the upload."))
5657
burnBootloaderCommand.Flags().BoolVarP(&verbose, "verbose", "v", false, tr("Turns on verbose mode."))
57-
burnBootloaderCommand.Flags().StringVarP(&programmer, "programmer", "P", "", tr("Use the specified programmer to upload."))
58-
burnBootloaderCommand.RegisterFlagCompletionFunc("programmer", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
59-
return arguments.GetInstalledProgrammers(), cobra.ShellCompDirectiveDefault
60-
})
6158
burnBootloaderCommand.Flags().BoolVar(&dryRun, "dry-run", false, tr("Do not perform the actual upload, just log out actions"))
6259
burnBootloaderCommand.Flags().MarkHidden("dry-run")
6360

@@ -80,7 +77,7 @@ func run(command *cobra.Command, args []string) {
8077
Port: discoveryPort.ToRPC(),
8178
Verbose: verbose,
8279
Verify: verify,
83-
Programmer: programmer,
80+
Programmer: programmer.String(),
8481
DryRun: dryRun,
8582
}, os.Stdout, os.Stderr); err != nil {
8683
feedback.Errorf(tr("Error during Upload: %v"), err)

0 commit comments

Comments
 (0)