Skip to content

Improve error message when port or fqbn flags are not set #523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🍰

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")
Expand All @@ -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) {
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions cli/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
3 changes: 3 additions & 0 deletions cli/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down