diff --git a/cli/cli_test.go b/cli/cli_test.go index 779c12616af..32039ae3bca 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" @@ -42,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") @@ -75,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) { @@ -134,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)) @@ -168,7 +172,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 +315,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 }
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: