Skip to content

Commit 62bbbba

Browse files
committed
Avoid globals arguemnts in flash-certificate
1 parent a1b45b5 commit 62bbbba

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

Diff for: cli/certificates/flash.go

+10-7
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,20 @@ import (
3333
"github.com/arduino/arduino-fwuploader/flasher"
3434
"github.com/arduino/arduino-fwuploader/indexes/download"
3535
"github.com/arduino/arduino-fwuploader/indexes/firmwareindex"
36+
"github.com/arduino/arduino-fwuploader/plugin"
3637
"github.com/arduino/go-paths-helper"
3738
"github.com/sirupsen/logrus"
3839
"github.com/spf13/cobra"
3940
)
4041

4142
var (
42-
commonFlags arguments.Flags
43-
certificateURLs []string
44-
certificatePaths []string
43+
commonFlags arguments.Flags
4544
)
4645

4746
// NewFlashCommand creates a new `flash` command
4847
func NewFlashCommand() *cobra.Command {
48+
var certificateURLs []string
49+
var certificatePaths []string
4950
command := &cobra.Command{
5051
Use: "flash",
5152
Short: "Flashes certificates to board.",
@@ -55,15 +56,17 @@ func NewFlashCommand() *cobra.Command {
5556
" " + os.Args[0] + " certificates flash -b arduino:samd:mkr1000 -a COM10 -u arduino.cc:443 -u google.com:443\n" +
5657
" " + os.Args[0] + " certificates flash -b arduino:samd:mkr1000 -a COM10 -f /home/me/VeriSign.cer -f /home/me/Digicert.cer\n",
5758
Args: cobra.NoArgs,
58-
Run: runFlash,
59+
Run: func(cmd *cobra.Command, args []string) {
60+
runFlash(certificateURLs, certificatePaths)
61+
},
5962
}
6063
commonFlags.AddToCommand(command)
6164
command.Flags().StringSliceVarP(&certificateURLs, "url", "u", []string{}, "List of urls to download root certificates, e.g.: arduino.cc:443")
6265
command.Flags().StringSliceVarP(&certificatePaths, "file", "f", []string{}, "List of paths to certificate file, e.g.: /home/me/Digicert.cer")
6366
return command
6467
}
6568

66-
func runFlash(cmd *cobra.Command, args []string) {
69+
func runFlash(certificateURLs, certificatePaths []string) {
6770
// at the end cleanup the fwuploader temp dir
6871
defer globals.FwUploaderPath.RemoveAll()
6972

@@ -79,7 +82,7 @@ func runFlash(cmd *cobra.Command, args []string) {
7982
var res *flasher.FlashResult
8083
var err error
8184
if !board.IsPlugin() {
82-
res, err = flashCertificates(board, uploadToolDir)
85+
res, err = flashCertificates(board, uploadToolDir, certificateURLs, certificatePaths)
8386
} else {
8487
// TODO
8588
}
@@ -90,7 +93,7 @@ func runFlash(cmd *cobra.Command, args []string) {
9093
}
9194
}
9295

93-
func flashCertificates(board *firmwareindex.IndexBoard, uploadToolDir *paths.Path) (*flasher.FlashResult, error) {
96+
func flashCertificates(board *firmwareindex.IndexBoard, uploadToolDir *paths.Path, certificateURLs, certificatePaths []string) (*flasher.FlashResult, error) {
9497
loaderSketchPath, err := download.DownloadSketch(board.LoaderSketch)
9598
if err != nil {
9699
feedback.Fatal(fmt.Sprintf("Error downloading loader sketch from %s: %s", board.LoaderSketch.URL, err), feedback.ErrGeneric)

0 commit comments

Comments
 (0)