Skip to content

Commit 49897ef

Browse files
federicobondMassimiliano Pippi
authored andcommitted
Improve error message when port or fqbn flags are not set (arduino#523)
* Improve error message when port or fqbn flags are missing * Redirect stderr for integration tests too
1 parent 4f4c98d commit 49897ef

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

cli/cli_test.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030

3131
"github.com/spf13/viper"
3232

33+
"github.com/arduino/arduino-cli/cli/errorcodes"
3334
"github.com/arduino/arduino-cli/cli/feedback"
3435

3536
"bou.ke/monkey"
@@ -42,26 +43,28 @@ var (
4243
// Redirecting stdOut so we can analyze output line by
4344
// line and check with what we want.
4445
stdOut = os.Stdout
46+
stdErr = os.Stderr
4547

4648
currDownloadDir string
4749
currDataDir string
4850
currUserDir string
4951
)
5052

51-
type stdOutRedirect struct {
53+
type outputRedirect struct {
5254
tempFile *os.File
5355
}
5456

55-
func (grabber *stdOutRedirect) Open() {
57+
func (grabber *outputRedirect) Open() {
5658
tempFile, err := ioutil.TempFile(os.TempDir(), "test")
5759
if err != nil {
5860
panic("Opening temp output file")
5961
}
6062
os.Stdout = tempFile
63+
os.Stderr = tempFile
6164
grabber.tempFile = tempFile
6265
}
6366

64-
func (grabber *stdOutRedirect) GetOutput() []byte {
67+
func (grabber *outputRedirect) GetOutput() []byte {
6568
_, err := grabber.tempFile.Seek(0, 0)
6669
if err != nil {
6770
panic("Rewinding temp output file")
@@ -75,13 +78,14 @@ func (grabber *stdOutRedirect) GetOutput() []byte {
7578
return output
7679
}
7780

78-
func (grabber *stdOutRedirect) Close() {
81+
func (grabber *outputRedirect) Close() {
7982
grabber.tempFile.Close()
8083
err := os.Remove(grabber.tempFile.Name())
8184
if err != nil {
8285
panic("Removing temp output file")
8386
}
8487
os.Stdout = stdOut
88+
os.Stderr = stdErr
8589
}
8690

8791
func TestMain(m *testing.M) {
@@ -136,7 +140,7 @@ func executeWithArgs(args ...string) (int, []byte) {
136140

137141
// This closure is here because we won't that the defer are executed after the end of the "executeWithArgs" method
138142
func() {
139-
redirect := &stdOutRedirect{}
143+
redirect := &outputRedirect{}
140144
redirect.Open()
141145
// re-init feedback so it'll write to our grabber
142146
feedback.SetDefaultFeedback(feedback.New(os.Stdout, os.Stdout, feedback.Text))
@@ -170,7 +174,9 @@ func executeWithArgs(args ...string) (int, []byte) {
170174
ArduinoCli.ResetFlags()
171175
createCliCommandTree(ArduinoCli)
172176
ArduinoCli.SetArgs(args)
173-
ArduinoCli.Execute()
177+
if err := ArduinoCli.Execute(); err != nil {
178+
exitCode = errorcodes.ErrGeneric
179+
}
174180
}()
175181

176182
return exitCode, output
@@ -307,7 +313,7 @@ func TestCompileCommandsIntegration(t *testing.T) {
307313
// Build sketch without FQBN
308314
exitCode, d = executeWithArgs("compile", sketchPath)
309315
require.NotZero(t, exitCode)
310-
require.Contains(t, string(d), "no FQBN provided")
316+
require.Contains(t, string(d), "required flag(s) \"fqbn\" not set")
311317

312318
// Build sketch for arduino:avr:uno
313319
exitCode, d = executeWithArgs("compile", "-b", "arduino:avr:uno", sketchPath)

cli/compile/compile.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ func NewCommand() *cobra.Command {
8080
command.Flags().BoolVarP(&verify, "verify", "t", false, "Verify uploaded binary after the upload.")
8181
command.Flags().StringVar(&vidPid, "vid-pid", "", "When specified, VID/PID specific build properties are used, if boards supports them.")
8282

83+
command.MarkFlagRequired("fqbn")
84+
8385
return command
8486
}
8587

cli/upload/upload.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ func NewCommand() *cobra.Command {
5656
uploadCommand.Flags().BoolVarP(&verify, "verify", "t", false, "Verify uploaded binary after the upload.")
5757
uploadCommand.Flags().BoolVarP(&verbose, "verbose", "v", false, "Optional, turns on verbose mode.")
5858

59+
uploadCommand.MarkFlagRequired("fqbn")
60+
uploadCommand.MarkFlagRequired("port")
61+
5962
return uploadCommand
6063
}
6164

0 commit comments

Comments
 (0)
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