From f04ff741d15e0b6d23c22865e1909a0473b4dc10 Mon Sep 17 00:00:00 2001 From: Federico Bond Date: Wed, 18 Dec 2019 11:22:09 -0300 Subject: [PATCH 1/2] Improve error message when port or fqbn flags are missing --- cli/cli_test.go | 7 +++++-- cli/compile/compile.go | 2 ++ cli/upload/upload.go | 3 +++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/cli/cli_test.go b/cli/cli_test.go index 779c12616af..938c192f060 100644 --- a/cli/cli_test.go +++ b/cli/cli_test.go @@ -30,6 +30,7 @@ import ( "github.com/spf13/viper" + "github.com/arduino/arduino-cli/cli/errorcodes" "github.com/arduino/arduino-cli/cli/feedback" "bou.ke/monkey" @@ -168,7 +169,9 @@ func executeWithArgs(args ...string) (int, []byte) { ArduinoCli.ResetFlags() createCliCommandTree(ArduinoCli) ArduinoCli.SetArgs(args) - ArduinoCli.Execute() + if err := ArduinoCli.Execute(); err != nil { + exitCode = errorcodes.ErrGeneric + } }() return exitCode, output @@ -309,7 +312,7 @@ func TestCompileCommandsIntegration(t *testing.T) { // Build sketch without FQBN exitCode, d = executeWithArgs("compile", test1) require.NotZero(t, exitCode) - require.Contains(t, string(d), "no FQBN provided") + require.Contains(t, string(d), "required flag(s) \"fqbn\" not set") // Build sketch for arduino:avr:uno exitCode, d = executeWithArgs("compile", "-b", "arduino:avr:uno", test1) diff --git a/cli/compile/compile.go b/cli/compile/compile.go index f10d6d52f1e..311545db64b 100644 --- a/cli/compile/compile.go +++ b/cli/compile/compile.go @@ -80,6 +80,8 @@ func NewCommand() *cobra.Command { command.Flags().BoolVarP(&verify, "verify", "t", false, "Verify uploaded binary after the upload.") command.Flags().StringVar(&vidPid, "vid-pid", "", "When specified, VID/PID specific build properties are used, if boards supports them.") + command.MarkFlagRequired("fqbn") + return command } diff --git a/cli/upload/upload.go b/cli/upload/upload.go index 92abdc26fb1..f2609111355 100644 --- a/cli/upload/upload.go +++ b/cli/upload/upload.go @@ -56,6 +56,9 @@ func NewCommand() *cobra.Command { uploadCommand.Flags().BoolVarP(&verify, "verify", "t", false, "Verify uploaded binary after the upload.") uploadCommand.Flags().BoolVarP(&verbose, "verbose", "v", false, "Optional, turns on verbose mode.") + uploadCommand.MarkFlagRequired("fqbn") + uploadCommand.MarkFlagRequired("port") + return uploadCommand } From b1a643f731794271722bcaa26fdd911c38b07fe7 Mon Sep 17 00:00:00 2001 From: Federico Bond Date: Thu, 19 Dec 2019 14:24:20 -0300 Subject: [PATCH 2/2] Redirect stderr for integration tests too --- cli/cli_test.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/cli/cli_test.go b/cli/cli_test.go index 938c192f060..32039ae3bca 100644 --- a/cli/cli_test.go +++ b/cli/cli_test.go @@ -43,26 +43,28 @@ var ( // Redirecting stdOut so we can analyze output line by // line and check with what we want. stdOut = os.Stdout + stdErr = os.Stderr currDownloadDir string currDataDir string currSketchbookDir string ) -type stdOutRedirect struct { +type outputRedirect struct { tempFile *os.File } -func (grabber *stdOutRedirect) Open() { +func (grabber *outputRedirect) Open() { tempFile, err := ioutil.TempFile(os.TempDir(), "test") if err != nil { panic("Opening temp output file") } os.Stdout = tempFile + os.Stderr = tempFile grabber.tempFile = tempFile } -func (grabber *stdOutRedirect) GetOutput() []byte { +func (grabber *outputRedirect) GetOutput() []byte { _, err := grabber.tempFile.Seek(0, 0) if err != nil { panic("Rewinding temp output file") @@ -76,13 +78,14 @@ func (grabber *stdOutRedirect) GetOutput() []byte { return output } -func (grabber *stdOutRedirect) Close() { +func (grabber *outputRedirect) Close() { grabber.tempFile.Close() err := os.Remove(grabber.tempFile.Name()) if err != nil { panic("Removing temp output file") } os.Stdout = stdOut + os.Stderr = stdErr } func TestMain(m *testing.M) { @@ -135,7 +138,7 @@ func executeWithArgs(args ...string) (int, []byte) { // This closure is here because we won't that the defer are executed after the end of the "executeWithArgs" method func() { - redirect := &stdOutRedirect{} + redirect := &outputRedirect{} redirect.Open() // re-init feedback so it'll write to our grabber feedback.SetDefaultFeedback(feedback.New(os.Stdout, os.Stdout, feedback.Text)) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy