Skip to content

Commit 05a8081

Browse files
authored
Merge pull request #5233 from thaJeztah/nicer_errors
cli: FlagErrorFunc: don't print long usage output for invalid flags
2 parents ce4469a + f28fc7f commit 05a8081

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
lines changed

cli/cobra.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,8 @@ func FlagErrorFunc(cmd *cobra.Command, err error) error {
9292
return nil
9393
}
9494

95-
usage := ""
96-
if cmd.HasSubCommands() {
97-
usage = "\n\n" + cmd.UsageString()
98-
}
9995
return StatusError{
100-
Status: fmt.Sprintf("%s\nSee '%s --help'.%s", err, cmd.CommandPath(), usage),
96+
Status: fmt.Sprintf("%s\n\nUsage: %s\n\nRun '%s --help' for more information", err, cmd.UseLine(), cmd.CommandPath()),
10197
StatusCode: 125,
10298
}
10399
}

e2e/cli-plugins/help_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,6 @@ func TestGlobalHelp(t *testing.T) {
7878
})
7979
assert.Assert(t, is.Equal(res2.Stdout(), ""))
8080
assert.Assert(t, is.Contains(res2.Stderr(), "unknown flag: --badopt"))
81-
assert.Assert(t, is.Contains(res2.Stderr(), "See 'docker --help"))
81+
assert.Assert(t, is.Contains(res2.Stderr(), "Run 'docker --help' for more information"))
8282
})
8383
}

0 commit comments

Comments
 (0)