From dfededbfc29bf3df98c97580ef9019e5e21e4e80 Mon Sep 17 00:00:00 2001 From: umbynos Date: Tue, 15 Jun 2021 12:23:59 +0200 Subject: [PATCH 1/6] enable programmer output to be printed in json --- cli/firmware/flash.go | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/cli/firmware/flash.go b/cli/firmware/flash.go index 3d3f98fe..1e6e8eab 100644 --- a/cli/firmware/flash.go +++ b/cli/firmware/flash.go @@ -169,11 +169,11 @@ func run(cmd *cobra.Command, args []string) { } // Flash loader Sketch - flashOut := new(bytes.Buffer) - flashErr := new(bytes.Buffer) + programmerOut := new(bytes.Buffer) + programmerErr := new(bytes.Buffer) // var err error if feedback.GetFormat() == feedback.JSON { - err = programmer.Flash(commandLine, flashOut, flashErr) + err = programmer.Flash(commandLine, programmerOut, programmerErr) } else { err = programmer.Flash(commandLine, os.Stdout, os.Stderr) } @@ -206,4 +206,24 @@ func run(cmd *cobra.Command, args []string) { feedback.Errorf("Error during firmware flashing: %s", err) os.Exit(errorcodes.ErrGeneric) } + + // Print the results + feedback.PrintResult(&flashResult{ + ProgrammerOut: programmerOut.String(), + ProgrammerErr: programmerErr.String(), + }) +} + +type flashResult struct { + ProgrammerOut string + ProgrammerErr string +} + +func (r *flashResult) Data() interface{} { + return r +} + +func (r *flashResult) String() string { + // The output is already printed via os.Stdout/os.Stdin + return "" } From 56397f3043cc3b0a5160d47674f63ede8a6748b0 Mon Sep 17 00:00:00 2001 From: umbynos Date: Tue, 15 Jun 2021 17:36:05 +0200 Subject: [PATCH 2/6] minor optimizations --- cli/firmware/flash.go | 1 - flasher/nina.go | 7 +++---- flasher/sara.go | 3 ++- flasher/winc.go | 10 +++++++--- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/cli/firmware/flash.go b/cli/firmware/flash.go index 1e6e8eab..1a3676da 100644 --- a/cli/firmware/flash.go +++ b/cli/firmware/flash.go @@ -171,7 +171,6 @@ func run(cmd *cobra.Command, args []string) { // Flash loader Sketch programmerOut := new(bytes.Buffer) programmerErr := new(bytes.Buffer) - // var err error if feedback.GetFormat() == feedback.JSON { err = programmer.Flash(commandLine, programmerOut, programmerErr) } else { diff --git a/flasher/nina.go b/flasher/nina.go index a9eb42cc..475ccfae 100644 --- a/flasher/nina.go +++ b/flasher/nina.go @@ -86,13 +86,12 @@ func (f *NinaFlasher) FlashFirmware(firmwareFile *paths.Path) error { } logrus.Debugf("Checking md5") - err = f.md5sum(data) - if err != nil { + if err := f.md5sum(data); err != nil { logrus.Error(err) return err } - logrus.Debugf("Flashed all the things") - return nil + logrus.Infof("Flashed all the things") + return err //should be nil } func (f *NinaFlasher) FlashCertificates(certificatePaths *paths.PathList, URLs []string) error { diff --git a/flasher/sara.go b/flasher/sara.go index 876143b4..7f7c9a40 100644 --- a/flasher/sara.go +++ b/flasher/sara.go @@ -101,7 +101,8 @@ func (f *SaraFlasher) FlashFirmware(firmwareFile *paths.Path) error { if err != nil { logrus.Error(err) } - return err + logrus.Infof("Flashed all the things") + return err //should be nil } func (f *SaraFlasher) FlashCertificates(certificatePaths *paths.PathList, URLs []string) error { diff --git a/flasher/winc.go b/flasher/winc.go index 4ef972a4..bb785322 100644 --- a/flasher/winc.go +++ b/flasher/winc.go @@ -27,7 +27,6 @@ import ( "encoding/binary" "errors" "fmt" - "log" "strconv" "time" @@ -68,7 +67,12 @@ func (f *WincFlasher) FlashFirmware(firmwareFile *paths.Path) error { return err } firmwareOffset := 0x0000 - return f.flashChunk(firmwareOffset, data) + if err = f.flashChunk(firmwareOffset, data); err != nil { + logrus.Error(err) + return err + } + logrus.Infof("Flashed all the things") + return err //should be nil } func (f *WincFlasher) FlashCertificates(certificatePaths *paths.PathList, URLs []string) error { @@ -431,7 +435,7 @@ func (f *WincFlasher) erase(address uint32, length uint32) error { return err } - log.Printf("Erasing %d bytes from address 0x%X\n", length, address) + logrus.Debugf("Erasing %d bytes from address 0x%X\n", length, address) // wait acknowledge ack := make([]byte, 2) From 09bedb5647487365cccbc1a28ea4ecfc892cad87 Mon Sep 17 00:00:00 2001 From: umbynos Date: Tue, 15 Jun 2021 17:44:35 +0200 Subject: [PATCH 3/6] add buffer to FlashFirmware func to capture output for json printing --- cli/certificates/flash.go | 1 + cli/firmware/flash.go | 36 ++++++++++++++++++++++++++++++------ flasher/flasher.go | 3 ++- flasher/nina.go | 7 ++++++- flasher/sara.go | 7 ++++++- flasher/winc.go | 7 ++++++- 6 files changed, 51 insertions(+), 10 deletions(-) diff --git a/cli/certificates/flash.go b/cli/certificates/flash.go index 421209f9..abcc8ad0 100644 --- a/cli/certificates/flash.go +++ b/cli/certificates/flash.go @@ -21,6 +21,7 @@ package certificates import ( "bytes" + "fmt" "os" "path/filepath" "strings" diff --git a/cli/firmware/flash.go b/cli/firmware/flash.go index 1a3676da..6c6a218e 100644 --- a/cli/firmware/flash.go +++ b/cli/firmware/flash.go @@ -21,6 +21,7 @@ package firmware import ( "bytes" + "fmt" "os" "path/filepath" "strings" @@ -201,21 +202,44 @@ func run(cmd *cobra.Command, args []string) { } defer f.Close() - if err := f.FlashFirmware(firmwareFile); err != nil { + // now flash the actual firmware + flasherOut := new(bytes.Buffer) + flasherErr := new(bytes.Buffer) + if feedback.GetFormat() == feedback.JSON { + err = f.FlashFirmware(firmwareFile, flasherOut) + } else { + err = f.FlashFirmware(firmwareFile, os.Stdout) + } + if err != nil { feedback.Errorf("Error during firmware flashing: %s", err) - os.Exit(errorcodes.ErrGeneric) + flasherErr.Write([]byte(fmt.Sprintf("Error during firmware flashing: %s", err))) } // Print the results feedback.PrintResult(&flashResult{ - ProgrammerOut: programmerOut.String(), - ProgrammerErr: programmerErr.String(), + Programmer: (&ExecOutput{ + Stdout: programmerOut.String(), + Stderr: programmerErr.String(), + }), + Flasher: (&ExecOutput{ + Stdout: flasherOut.String(), + Stderr: flasherErr.String(), + }), }) + // Exit if something went wrong but after printing + if err != nil { + os.Exit(errorcodes.ErrGeneric) + } } type flashResult struct { - ProgrammerOut string - ProgrammerErr string + Programmer *ExecOutput `json:"programmer"` + Flasher *ExecOutput `json:"flasher"` +} + +type ExecOutput struct { + Stdout string `json:"stdout"` + Stderr string `json:"stderr"` } func (r *flashResult) Data() interface{} { diff --git a/flasher/flasher.go b/flasher/flasher.go index 7dae5c11..f7d6e504 100644 --- a/flasher/flasher.go +++ b/flasher/flasher.go @@ -21,6 +21,7 @@ package flasher import ( "fmt" + "io" "time" "github.com/arduino/go-paths-helper" @@ -48,7 +49,7 @@ func (e FlasherError) Error() string { } type Flasher interface { - FlashFirmware(firmwareFile *paths.Path) error + FlashFirmware(firmwareFile *paths.Path, flasherOut io.Writer) error FlashCertificates(certificatePaths *paths.PathList, URLs []string) error Close() error diff --git a/flasher/nina.go b/flasher/nina.go index 475ccfae..a8082f96 100644 --- a/flasher/nina.go +++ b/flasher/nina.go @@ -27,6 +27,7 @@ import ( "encoding/binary" "encoding/pem" "fmt" + "io" "strconv" "time" @@ -64,8 +65,10 @@ type NinaFlasher struct { } // FlashFirmware in board connected to port using data from firmwareFile -func (f *NinaFlasher) FlashFirmware(firmwareFile *paths.Path) error { +func (f *NinaFlasher) FlashFirmware(firmwareFile *paths.Path, flasherOut io.Writer) error { logrus.Infof("Flashing firmware %s", firmwareFile) + flasherOut.Write([]byte(fmt.Sprintf("Flashing firmware %s", firmwareFile))) + flasherOut.Write([]byte(fmt.Sprintln())) if err := f.hello(); err != nil { logrus.Error(err) return err @@ -91,6 +94,8 @@ func (f *NinaFlasher) FlashFirmware(firmwareFile *paths.Path) error { return err } logrus.Infof("Flashed all the things") + flasherOut.Write([]byte("Flashed all the things")) + flasherOut.Write([]byte(fmt.Sprintln())) return err //should be nil } diff --git a/flasher/sara.go b/flasher/sara.go index 7f7c9a40..9f5bcf09 100644 --- a/flasher/sara.go +++ b/flasher/sara.go @@ -21,6 +21,7 @@ package flasher import ( "fmt" + "io" "strconv" "strings" "time" @@ -45,8 +46,10 @@ type SaraFlasher struct { payloadSize int } -func (f *SaraFlasher) FlashFirmware(firmwareFile *paths.Path) error { +func (f *SaraFlasher) FlashFirmware(firmwareFile *paths.Path, flasherOut io.Writer) error { logrus.Infof("Flashing firmware %s", firmwareFile) + flasherOut.Write([]byte(fmt.Sprintf("Flashing firmware %s", firmwareFile))) + flasherOut.Write([]byte(fmt.Sprintln())) data, err := firmwareFile.ReadFile() if err != nil { logrus.Error(err) @@ -102,6 +105,8 @@ func (f *SaraFlasher) FlashFirmware(firmwareFile *paths.Path) error { logrus.Error(err) } logrus.Infof("Flashed all the things") + flasherOut.Write([]byte("Flashed all the things")) + flasherOut.Write([]byte(fmt.Sprintln())) return err //should be nil } diff --git a/flasher/winc.go b/flasher/winc.go index bb785322..031226bd 100644 --- a/flasher/winc.go +++ b/flasher/winc.go @@ -27,6 +27,7 @@ import ( "encoding/binary" "errors" "fmt" + "io" "strconv" "time" @@ -59,8 +60,10 @@ type WincFlasher struct { payloadSize int } -func (f *WincFlasher) FlashFirmware(firmwareFile *paths.Path) error { +func (f *WincFlasher) FlashFirmware(firmwareFile *paths.Path, flasherOut io.Writer) error { logrus.Infof("Flashing firmware %s", firmwareFile) + flasherOut.Write([]byte(fmt.Sprintf("Flashing firmware %s", firmwareFile))) + flasherOut.Write([]byte(fmt.Sprintln())) data, err := firmwareFile.ReadFile() if err != nil { logrus.Error(err) @@ -72,6 +75,8 @@ func (f *WincFlasher) FlashFirmware(firmwareFile *paths.Path) error { return err } logrus.Infof("Flashed all the things") + flasherOut.Write([]byte("Flashed all the things")) + flasherOut.Write([]byte(fmt.Sprintln())) return err //should be nil } From 225fbbd9f5d891e598ba694a839c335f76cb4a42 Mon Sep 17 00:00:00 2001 From: umbynos Date: Tue, 15 Jun 2021 18:46:18 +0200 Subject: [PATCH 4/6] apply same enhancements to FlashCertificates func --- cli/certificates/flash.go | 52 +++++++++++++++++++++++++++++++++++---- flasher/flasher.go | 2 +- flasher/nina.go | 15 +++++++++-- flasher/sara.go | 2 +- flasher/winc.go | 15 +++++++++-- 5 files changed, 75 insertions(+), 11 deletions(-) diff --git a/cli/certificates/flash.go b/cli/certificates/flash.go index abcc8ad0..b1f7c6a2 100644 --- a/cli/certificates/flash.go +++ b/cli/certificates/flash.go @@ -143,11 +143,10 @@ func run(cmd *cobra.Command, args []string) { } // Flash loader Sketch - flashOut := new(bytes.Buffer) - flashErr := new(bytes.Buffer) - // var err error + programmerOut := new(bytes.Buffer) + programmerErr := new(bytes.Buffer) if feedback.GetFormat() == feedback.JSON { - err = programmer.Flash(commandLine, flashOut, flashErr) + err = programmer.Flash(commandLine, programmerOut, programmerErr) } else { err = programmer.Flash(commandLine, os.Stdout, os.Stderr) } @@ -176,9 +175,52 @@ func run(cmd *cobra.Command, args []string) { } defer f.Close() + // now flash the certificate + flasherOut := new(bytes.Buffer) + flasherErr := new(bytes.Buffer) certFileList := paths.NewPathList(certificatePaths...) - if err := f.FlashCertificates(&certFileList, certificateURLs); err != nil { + if feedback.GetFormat() == feedback.JSON { + err = f.FlashCertificates(&certFileList, certificateURLs, flasherOut) + } else { + err = f.FlashCertificates(&certFileList, certificateURLs, os.Stdout) + } + if err != nil { feedback.Errorf("Error during certificates flashing: %s", err) + flasherErr.Write([]byte(fmt.Sprintf("Error during certificates flashing: %s", err))) + } + + // Print the results + feedback.PrintResult(&flashResult{ + Programmer: (&ExecOutput{ + Stdout: programmerOut.String(), + Stderr: programmerErr.String(), + }), + Flasher: (&ExecOutput{ + Stdout: flasherOut.String(), + Stderr: flasherErr.String(), + }), + }) + // Exit if something went wrong but after printing + if err != nil { os.Exit(errorcodes.ErrGeneric) } } + +type flashResult struct { + Programmer *ExecOutput `json:"programmer"` + Flasher *ExecOutput `json:"flasher"` +} + +type ExecOutput struct { + Stdout string `json:"stdout"` + Stderr string `json:"stderr"` +} + +func (r *flashResult) Data() interface{} { + return r +} + +func (r *flashResult) String() string { + // The output is already printed via os.Stdout/os.Stdin + return "" +} diff --git a/flasher/flasher.go b/flasher/flasher.go index f7d6e504..1ed1e4a3 100644 --- a/flasher/flasher.go +++ b/flasher/flasher.go @@ -50,7 +50,7 @@ func (e FlasherError) Error() string { type Flasher interface { FlashFirmware(firmwareFile *paths.Path, flasherOut io.Writer) error - FlashCertificates(certificatePaths *paths.PathList, URLs []string) error + FlashCertificates(certificatePaths *paths.PathList, URLs []string, flasherOut io.Writer) error Close() error hello() error diff --git a/flasher/nina.go b/flasher/nina.go index a8082f96..61d4fe94 100644 --- a/flasher/nina.go +++ b/flasher/nina.go @@ -99,10 +99,12 @@ func (f *NinaFlasher) FlashFirmware(firmwareFile *paths.Path, flasherOut io.Writ return err //should be nil } -func (f *NinaFlasher) FlashCertificates(certificatePaths *paths.PathList, URLs []string) error { +func (f *NinaFlasher) FlashCertificates(certificatePaths *paths.PathList, URLs []string, flasherOut io.Writer) error { var certificatesData []byte for _, certPath := range *certificatePaths { logrus.Infof("Converting and flashing certificate %s", certPath) + flasherOut.Write([]byte(fmt.Sprintf("Converting and flashing certificate %s", certPath))) + flasherOut.Write([]byte(fmt.Sprintln())) data, err := f.certificateFromFile(certPath) if err != nil { @@ -113,6 +115,8 @@ func (f *NinaFlasher) FlashCertificates(certificatePaths *paths.PathList, URLs [ for _, URL := range URLs { logrus.Infof("Converting and flashing certificate from %s", URL) + flasherOut.Write([]byte(fmt.Sprintf("Converting and flashing certificate from %s", URL))) + flasherOut.Write([]byte(fmt.Sprintln())) data, err := f.certificateFromURL(URL) if err != nil { return err @@ -133,7 +137,14 @@ func (f *NinaFlasher) FlashCertificates(certificatePaths *paths.PathList, URLs [ } certificatesOffset := 0x10000 - return f.flashChunk(certificatesOffset, certificatesData) + if err := f.flashChunk(certificatesOffset, certificatesData); err != nil { + logrus.Error(err) + return err + } + logrus.Infof("Flashed all the things") + flasherOut.Write([]byte("Flashed all the things")) + flasherOut.Write([]byte(fmt.Sprintln())) + return nil } func (f *NinaFlasher) certificateFromFile(certificateFile *paths.Path) ([]byte, error) { diff --git a/flasher/sara.go b/flasher/sara.go index 9f5bcf09..169c1676 100644 --- a/flasher/sara.go +++ b/flasher/sara.go @@ -110,7 +110,7 @@ func (f *SaraFlasher) FlashFirmware(firmwareFile *paths.Path, flasherOut io.Writ return err //should be nil } -func (f *SaraFlasher) FlashCertificates(certificatePaths *paths.PathList, URLs []string) error { +func (f *SaraFlasher) FlashCertificates(certificatePaths *paths.PathList, URLs []string, _ io.Writer) error { return fmt.Errorf("not supported by SaraFlasher") } diff --git a/flasher/winc.go b/flasher/winc.go index 031226bd..aeac7318 100644 --- a/flasher/winc.go +++ b/flasher/winc.go @@ -80,11 +80,13 @@ func (f *WincFlasher) FlashFirmware(firmwareFile *paths.Path, flasherOut io.Writ return err //should be nil } -func (f *WincFlasher) FlashCertificates(certificatePaths *paths.PathList, URLs []string) error { +func (f *WincFlasher) FlashCertificates(certificatePaths *paths.PathList, URLs []string, flasherOut io.Writer) error { var certificatesData []byte certificatesNumber := 0 for _, certPath := range *certificatePaths { logrus.Infof("Converting and flashing certificate %s", certPath) + flasherOut.Write([]byte(fmt.Sprintf("Converting and flashing certificate %s", certPath))) + flasherOut.Write([]byte(fmt.Sprintln())) data, err := f.certificateFromFile(certPath) if err != nil { @@ -96,6 +98,8 @@ func (f *WincFlasher) FlashCertificates(certificatePaths *paths.PathList, URLs [ for _, URL := range URLs { logrus.Infof("Converting and flashing certificate from %s", URL) + flasherOut.Write([]byte(fmt.Sprintf("Converting and flashing certificate from %s", URL))) + flasherOut.Write([]byte(fmt.Sprintln())) data, err := f.certificateFromURL(URL) if err != nil { return err @@ -105,7 +109,14 @@ func (f *WincFlasher) FlashCertificates(certificatePaths *paths.PathList, URLs [ } certificatesOffset := 0x4000 - return f.flashChunk(certificatesOffset, certificatesData) + if err := f.flashChunk(certificatesOffset, certificatesData); err != nil { + logrus.Error(err) + return err + } + logrus.Infof("Flashed all the things") + flasherOut.Write([]byte("Flashed all the things")) + flasherOut.Write([]byte(fmt.Sprintln())) + return nil } func (f *WincFlasher) certificateFromFile(certificateFile *paths.Path) ([]byte, error) { From 4b36452c40ae53140b1ec038c5b6b0740285538a Mon Sep 17 00:00:00 2001 From: umbynos Date: Tue, 15 Jun 2021 18:55:26 +0200 Subject: [PATCH 5/6] remove some code duplication --- cli/certificates/flash.go | 25 +++---------------------- cli/firmware/flash.go | 25 +++---------------------- flasher/flasher.go | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+), 44 deletions(-) diff --git a/cli/certificates/flash.go b/cli/certificates/flash.go index b1f7c6a2..6093457c 100644 --- a/cli/certificates/flash.go +++ b/cli/certificates/flash.go @@ -190,12 +190,12 @@ func run(cmd *cobra.Command, args []string) { } // Print the results - feedback.PrintResult(&flashResult{ - Programmer: (&ExecOutput{ + feedback.PrintResult(&flasher.FlashResult{ + Programmer: (&flasher.ExecOutput{ Stdout: programmerOut.String(), Stderr: programmerErr.String(), }), - Flasher: (&ExecOutput{ + Flasher: (&flasher.ExecOutput{ Stdout: flasherOut.String(), Stderr: flasherErr.String(), }), @@ -205,22 +205,3 @@ func run(cmd *cobra.Command, args []string) { os.Exit(errorcodes.ErrGeneric) } } - -type flashResult struct { - Programmer *ExecOutput `json:"programmer"` - Flasher *ExecOutput `json:"flasher"` -} - -type ExecOutput struct { - Stdout string `json:"stdout"` - Stderr string `json:"stderr"` -} - -func (r *flashResult) Data() interface{} { - return r -} - -func (r *flashResult) String() string { - // The output is already printed via os.Stdout/os.Stdin - return "" -} diff --git a/cli/firmware/flash.go b/cli/firmware/flash.go index 6c6a218e..744c7db9 100644 --- a/cli/firmware/flash.go +++ b/cli/firmware/flash.go @@ -216,12 +216,12 @@ func run(cmd *cobra.Command, args []string) { } // Print the results - feedback.PrintResult(&flashResult{ - Programmer: (&ExecOutput{ + feedback.PrintResult(&flasher.FlashResult{ + Programmer: (&flasher.ExecOutput{ Stdout: programmerOut.String(), Stderr: programmerErr.String(), }), - Flasher: (&ExecOutput{ + Flasher: (&flasher.ExecOutput{ Stdout: flasherOut.String(), Stderr: flasherErr.String(), }), @@ -231,22 +231,3 @@ func run(cmd *cobra.Command, args []string) { os.Exit(errorcodes.ErrGeneric) } } - -type flashResult struct { - Programmer *ExecOutput `json:"programmer"` - Flasher *ExecOutput `json:"flasher"` -} - -type ExecOutput struct { - Stdout string `json:"stdout"` - Stderr string `json:"stderr"` -} - -func (r *flashResult) Data() interface{} { - return r -} - -func (r *flashResult) String() string { - // The output is already printed via os.Stdout/os.Stdin - return "" -} diff --git a/flasher/flasher.go b/flasher/flasher.go index 1ed1e4a3..6e25cfe6 100644 --- a/flasher/flasher.go +++ b/flasher/flasher.go @@ -93,3 +93,22 @@ func openSerial(portAddress string) (serial.Port, error) { return nil, lastError } + +type FlashResult struct { + Programmer *ExecOutput `json:"programmer"` + Flasher *ExecOutput `json:"flasher"` +} + +type ExecOutput struct { + Stdout string `json:"stdout"` + Stderr string `json:"stderr"` +} + +func (r *FlashResult) Data() interface{} { + return r +} + +func (r *FlashResult) String() string { + // The output is already printed via os.Stdout/os.Stdin + return "" +} From 0bd5a8c543f7fe6fed4e311056d3b7c2c2d3c058 Mon Sep 17 00:00:00 2001 From: Umberto Baldi Date: Wed, 16 Jun 2021 12:03:12 +0200 Subject: [PATCH 6/6] apply suggestion from code review --- flasher/nina.go | 17 ++++++----------- flasher/sara.go | 8 +++----- flasher/winc.go | 17 ++++++----------- 3 files changed, 15 insertions(+), 27 deletions(-) diff --git a/flasher/nina.go b/flasher/nina.go index 61d4fe94..aa07cd38 100644 --- a/flasher/nina.go +++ b/flasher/nina.go @@ -67,8 +67,7 @@ type NinaFlasher struct { // FlashFirmware in board connected to port using data from firmwareFile func (f *NinaFlasher) FlashFirmware(firmwareFile *paths.Path, flasherOut io.Writer) error { logrus.Infof("Flashing firmware %s", firmwareFile) - flasherOut.Write([]byte(fmt.Sprintf("Flashing firmware %s", firmwareFile))) - flasherOut.Write([]byte(fmt.Sprintln())) + flasherOut.Write([]byte(fmt.Sprintf("Flashing firmware %s\n", firmwareFile))) if err := f.hello(); err != nil { logrus.Error(err) return err @@ -94,17 +93,15 @@ func (f *NinaFlasher) FlashFirmware(firmwareFile *paths.Path, flasherOut io.Writ return err } logrus.Infof("Flashed all the things") - flasherOut.Write([]byte("Flashed all the things")) - flasherOut.Write([]byte(fmt.Sprintln())) - return err //should be nil + flasherOut.Write([]byte("Flashed all the things\n")) + return nil } func (f *NinaFlasher) FlashCertificates(certificatePaths *paths.PathList, URLs []string, flasherOut io.Writer) error { var certificatesData []byte for _, certPath := range *certificatePaths { logrus.Infof("Converting and flashing certificate %s", certPath) - flasherOut.Write([]byte(fmt.Sprintf("Converting and flashing certificate %s", certPath))) - flasherOut.Write([]byte(fmt.Sprintln())) + flasherOut.Write([]byte(fmt.Sprintf("Converting and flashing certificate %s\n", certPath))) data, err := f.certificateFromFile(certPath) if err != nil { @@ -115,8 +112,7 @@ func (f *NinaFlasher) FlashCertificates(certificatePaths *paths.PathList, URLs [ for _, URL := range URLs { logrus.Infof("Converting and flashing certificate from %s", URL) - flasherOut.Write([]byte(fmt.Sprintf("Converting and flashing certificate from %s", URL))) - flasherOut.Write([]byte(fmt.Sprintln())) + flasherOut.Write([]byte(fmt.Sprintf("Converting and flashing certificate from %s\n", URL))) data, err := f.certificateFromURL(URL) if err != nil { return err @@ -142,8 +138,7 @@ func (f *NinaFlasher) FlashCertificates(certificatePaths *paths.PathList, URLs [ return err } logrus.Infof("Flashed all the things") - flasherOut.Write([]byte("Flashed all the things")) - flasherOut.Write([]byte(fmt.Sprintln())) + flasherOut.Write([]byte("Flashed all the things\n")) return nil } diff --git a/flasher/sara.go b/flasher/sara.go index 169c1676..12ec9751 100644 --- a/flasher/sara.go +++ b/flasher/sara.go @@ -48,8 +48,7 @@ type SaraFlasher struct { func (f *SaraFlasher) FlashFirmware(firmwareFile *paths.Path, flasherOut io.Writer) error { logrus.Infof("Flashing firmware %s", firmwareFile) - flasherOut.Write([]byte(fmt.Sprintf("Flashing firmware %s", firmwareFile))) - flasherOut.Write([]byte(fmt.Sprintln())) + flasherOut.Write([]byte(fmt.Sprintf("Flashing firmware %s\n", firmwareFile))) data, err := firmwareFile.ReadFile() if err != nil { logrus.Error(err) @@ -105,9 +104,8 @@ func (f *SaraFlasher) FlashFirmware(firmwareFile *paths.Path, flasherOut io.Writ logrus.Error(err) } logrus.Infof("Flashed all the things") - flasherOut.Write([]byte("Flashed all the things")) - flasherOut.Write([]byte(fmt.Sprintln())) - return err //should be nil + flasherOut.Write([]byte("Flashed all the things\n")) + return nil } func (f *SaraFlasher) FlashCertificates(certificatePaths *paths.PathList, URLs []string, _ io.Writer) error { diff --git a/flasher/winc.go b/flasher/winc.go index aeac7318..a28a70fb 100644 --- a/flasher/winc.go +++ b/flasher/winc.go @@ -62,8 +62,7 @@ type WincFlasher struct { func (f *WincFlasher) FlashFirmware(firmwareFile *paths.Path, flasherOut io.Writer) error { logrus.Infof("Flashing firmware %s", firmwareFile) - flasherOut.Write([]byte(fmt.Sprintf("Flashing firmware %s", firmwareFile))) - flasherOut.Write([]byte(fmt.Sprintln())) + flasherOut.Write([]byte(fmt.Sprintf("Flashing firmware %s\n", firmwareFile))) data, err := firmwareFile.ReadFile() if err != nil { logrus.Error(err) @@ -75,9 +74,8 @@ func (f *WincFlasher) FlashFirmware(firmwareFile *paths.Path, flasherOut io.Writ return err } logrus.Infof("Flashed all the things") - flasherOut.Write([]byte("Flashed all the things")) - flasherOut.Write([]byte(fmt.Sprintln())) - return err //should be nil + flasherOut.Write([]byte("Flashed all the things\n")) + return nil } func (f *WincFlasher) FlashCertificates(certificatePaths *paths.PathList, URLs []string, flasherOut io.Writer) error { @@ -85,8 +83,7 @@ func (f *WincFlasher) FlashCertificates(certificatePaths *paths.PathList, URLs [ certificatesNumber := 0 for _, certPath := range *certificatePaths { logrus.Infof("Converting and flashing certificate %s", certPath) - flasherOut.Write([]byte(fmt.Sprintf("Converting and flashing certificate %s", certPath))) - flasherOut.Write([]byte(fmt.Sprintln())) + flasherOut.Write([]byte(fmt.Sprintf("Converting and flashing certificate %s\n", certPath))) data, err := f.certificateFromFile(certPath) if err != nil { @@ -98,8 +95,7 @@ func (f *WincFlasher) FlashCertificates(certificatePaths *paths.PathList, URLs [ for _, URL := range URLs { logrus.Infof("Converting and flashing certificate from %s", URL) - flasherOut.Write([]byte(fmt.Sprintf("Converting and flashing certificate from %s", URL))) - flasherOut.Write([]byte(fmt.Sprintln())) + flasherOut.Write([]byte(fmt.Sprintf("Converting and flashing certificate from %s\n", URL))) data, err := f.certificateFromURL(URL) if err != nil { return err @@ -114,8 +110,7 @@ func (f *WincFlasher) FlashCertificates(certificatePaths *paths.PathList, URLs [ return err } logrus.Infof("Flashed all the things") - flasherOut.Write([]byte("Flashed all the things")) - flasherOut.Write([]byte(fmt.Sprintln())) + flasherOut.Write([]byte("Flashed all the things\n")) return nil }