Skip to content

Commit 6b4f285

Browse files
authored
cleanup code-base after refactoring (#55)
* cleanup code-base after refactoring * forgot go.mod
1 parent 6c0b703 commit 6b4f285

File tree

17 files changed

+2
-2135
lines changed

17 files changed

+2
-2135
lines changed

cli/cli.go

+1-78
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,25 @@
2020
package cli
2121

2222
import (
23-
"encoding/json"
2423
"fmt"
2524
"io/ioutil"
26-
"log"
2725
"os"
2826
"strings"
29-
"time"
3027

3128
"github.com/arduino/FirmwareUploader/cli/certificates"
3229
"github.com/arduino/FirmwareUploader/cli/firmware"
3330
"github.com/arduino/FirmwareUploader/cli/version"
34-
"github.com/arduino/FirmwareUploader/modules/nina"
35-
"github.com/arduino/FirmwareUploader/modules/sara"
36-
"github.com/arduino/FirmwareUploader/modules/winc"
37-
"github.com/arduino/FirmwareUploader/utils"
38-
"github.com/arduino/FirmwareUploader/utils/context"
31+
3932
v "github.com/arduino/FirmwareUploader/version"
4033
"github.com/arduino/arduino-cli/cli/errorcodes"
4134
"github.com/arduino/arduino-cli/cli/feedback"
42-
"github.com/arduino/go-paths-helper"
4335
"github.com/mattn/go-colorable"
4436
"github.com/rifflock/lfshook"
4537
"github.com/sirupsen/logrus"
4638
"github.com/spf13/cobra"
4739
)
4840

4941
var (
50-
ctx = &context.Context{}
5142
outputFormat string
5243
verbose bool
5344
logFile string
@@ -63,28 +54,14 @@ func NewCommand() *cobra.Command {
6354
Long: "FirmwareUploader (FirmwareUploader).",
6455
Example: " " + os.Args[0] + " <command> [flags...]",
6556
Args: cobra.NoArgs,
66-
Run: run,
6757
PersistentPreRun: preRun,
6858
}
6959

7060
rootCmd.AddCommand(version.NewCommand())
7161
rootCmd.AddCommand(firmware.NewCommand())
7262
rootCmd.AddCommand(certificates.NewCommand())
7363

74-
rootCmd.Flags().StringVar(&ctx.PortName, "port", "", "serial port to use for flashing")
75-
rootCmd.Flags().StringVar(&ctx.RootCertDir, "certs", "", "root certificate directory")
76-
rootCmd.Flags().StringSliceVar(&ctx.Addresses, "address", []string{}, "address (host:port) to fetch and flash root certificate for, multiple values allowed")
77-
rootCmd.Flags().StringVar(&ctx.FirmwareFile, "firmware", "", "firmware file to flash")
78-
rootCmd.Flags().BoolVar(&ctx.ReadAll, "read", false, "read all firmware and output to stdout")
79-
rootCmd.Flags().StringVar(&ctx.FWUploaderBinary, "flasher", "", "firmware upload binary (precompiled for the right target)")
80-
rootCmd.Flags().StringVar(&ctx.BinaryToRestore, "restore_binary", "", "binary to restore after the firmware upload (precompiled for the right target)")
81-
rootCmd.Flags().StringVar(&ctx.ProgrammerPath, "programmer", "", "path of programmer in use (avrdude/bossac)")
82-
rootCmd.Flags().StringVar(&ctx.Model, "model", "", "module model (winc, nina or sara)")
83-
rootCmd.Flags().StringVar(&ctx.BoardName, "get_available_for", "", "Ask for available firmwares matching a given board")
84-
rootCmd.Flags().IntVar(&ctx.Retries, "retries", 9, "Number of retries in case of upload failure")
85-
8664
rootCmd.PersistentFlags().StringVar(&outputFormat, "format", "text", "The output format, can be {text|json}.")
87-
8865
rootCmd.PersistentFlags().StringVar(&logFile, "log-file", "", "Path to the file where logs will be written")
8966
rootCmd.PersistentFlags().StringVar(&logFormat, "log-format", "", "The output format for the logs, can be {text|json}.")
9067
rootCmd.PersistentFlags().StringVar(&logLevel, "log-level", "info", "Messages with this level and above will be logged. Valid levels are: trace, debug, info, warn, error, fatal, panic")
@@ -93,60 +70,6 @@ func NewCommand() *cobra.Command {
9370
return rootCmd
9471
}
9572

96-
func run(cmd *cobra.Command, args []string) {
97-
if ctx.BoardName != "" {
98-
el, _ := json.Marshal(utils.GetCompatibleWith(ctx.BoardName, ""))
99-
fmt.Println(string(el))
100-
os.Exit(0)
101-
}
102-
103-
if ctx.PortName == "" {
104-
log.Fatal("Please specify a serial port")
105-
}
106-
107-
if ctx.BinaryToRestore != "" {
108-
// sanity check for BinaryToRestore
109-
f := paths.New(ctx.BinaryToRestore)
110-
info, err := f.Stat()
111-
if err != nil {
112-
log.Fatalf("Error opening restore_binary: %s", err)
113-
}
114-
if info.IsDir() {
115-
log.Fatalf("Error opening restore_binary: is a directory...")
116-
}
117-
if info.Size() == 0 {
118-
log.Println("WARNING: restore_binary is empty! Will not restore binary after upload.")
119-
ctx.BinaryToRestore = ""
120-
}
121-
}
122-
123-
retry := 0
124-
for {
125-
var err error
126-
if ctx.Model == "nina" || strings.Contains(ctx.FirmwareFile, "NINA") || strings.Contains(ctx.FWUploaderBinary, "NINA") {
127-
err = nina.Run(ctx)
128-
} else if ctx.Model == "winc" || strings.Contains(ctx.FirmwareFile, "WINC") || strings.Contains(ctx.FWUploaderBinary, "WINC") {
129-
err = winc.Run(ctx)
130-
} else {
131-
err = sara.Run(ctx)
132-
}
133-
if err == nil {
134-
log.Println("Operation completed: success! :-)")
135-
break
136-
}
137-
log.Println("Error: " + err.Error())
138-
139-
if retry >= ctx.Retries {
140-
log.Fatal("Operation failed. :-(")
141-
}
142-
143-
retry++
144-
log.Println("Waiting 1 second before retrying...")
145-
time.Sleep(time.Second)
146-
log.Printf("Retrying upload (%d of %d)", retry, ctx.Retries)
147-
}
148-
}
149-
15073
// Convert the string passed to the `--log-level` option to the corresponding
15174
// logrus formal level.
15275
func toLogLevel(s string) (t logrus.Level, found bool) {

go.mod

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ replace go.bug.st/serial => github.com/cmaglie/go-serial v0.0.0-20200923162623-b
88
require (
99
github.com/arduino/arduino-cli v0.0.0-20210603144340-aef5a54882fa
1010
github.com/arduino/go-paths-helper v1.6.0
11-
github.com/arduino/go-properties-orderedmap v1.3.0 // indirect
11+
github.com/arduino/go-properties-orderedmap v1.3.0
1212
github.com/cmaglie/go.rice v1.0.3
1313
github.com/mattn/go-colorable v0.1.8
14-
github.com/pkg/errors v0.9.1
1514
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5
1615
github.com/sirupsen/logrus v1.8.1
1716
github.com/spf13/cobra v1.1.3

modules/nina/certificates.go

-134
This file was deleted.

0 commit comments

Comments
 (0)