Skip to content

Commit

Permalink
Merge pull request docker#5233 from thaJeztah/nicer_errors
Browse files Browse the repository at this point in the history
cli: FlagErrorFunc: don't print long usage output for invalid flags
  • Loading branch information
thaJeztah authored Jul 17, 2024
2 parents ce4469a + f28fc7f commit 05a8081
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
6 changes: 1 addition & 5 deletions cli/cobra.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,8 @@ func FlagErrorFunc(cmd *cobra.Command, err error) error {
return nil
}

usage := ""
if cmd.HasSubCommands() {
usage = "\n\n" + cmd.UsageString()
}
return StatusError{
Status: fmt.Sprintf("%s\nSee '%s --help'.%s", err, cmd.CommandPath(), usage),
Status: fmt.Sprintf("%s\n\nUsage: %s\n\nRun '%s --help' for more information", err, cmd.UseLine(), cmd.CommandPath()),
StatusCode: 125,
}
}
Expand Down
2 changes: 1 addition & 1 deletion e2e/cli-plugins/help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ func TestGlobalHelp(t *testing.T) {
})
assert.Assert(t, is.Equal(res2.Stdout(), ""))
assert.Assert(t, is.Contains(res2.Stderr(), "unknown flag: --badopt"))
assert.Assert(t, is.Contains(res2.Stderr(), "See 'docker --help"))
assert.Assert(t, is.Contains(res2.Stderr(), "Run 'docker --help' for more information"))
})
}

0 comments on commit 05a8081

Please sign in to comment.