Merge pull request #5234 from thaJeztah/nicer_missing_commands

cli: improve output and consistency for unknown (sub)commands
This commit is contained in:
Sebastiaan van Stijn
2024-07-17 01:22:03 +02:00
committed by GitHub
41 changed files with 91 additions and 84 deletions

View File

@ -82,7 +82,7 @@ func newDockerCommand(dockerCli *command.DockerCli) *cli.TopLevelCommand {
if len(args) == 0 {
return command.ShowHelp(dockerCli.Err())(cmd, args)
}
return fmt.Errorf("docker: '%s' is not a docker command.\nSee 'docker --help'", args[0])
return fmt.Errorf("docker: unknown command: docker %s\n\nRun 'docker --help' for more information", args[0])
},
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
return isSupported(cmd, dockerCli)

View File

@ -66,7 +66,7 @@ func TestExitStatusForInvalidSubcommandWithHelpFlag(t *testing.T) {
func TestExitStatusForInvalidSubcommand(t *testing.T) {
err := runCliCommand(t, nil, nil, "invalid")
assert.Check(t, is.ErrorContains(err, "docker: 'invalid' is not a docker command."))
assert.Check(t, is.ErrorContains(err, "docker: unknown command: docker invalid"))
}
func TestVersion(t *testing.T) {