Skip to content

Commit d1f57a0

Browse files
Merge pull request containers#10771 from infiniteregrets/cli
[NO TESTS NEEDED] Suggestions for typos/ incorrect commands for Podman CLI
2 parents 21d80fa + ee7a9d7 commit d1f57a0

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

cmd/podman/validate/args.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package validate
33
import (
44
"fmt"
55
"strconv"
6+
"strings"
67

78
"github.com/containers/podman/v3/cmd/podman/registry"
89
"github.com/pkg/errors"
@@ -20,7 +21,11 @@ func NoArgs(cmd *cobra.Command, args []string) error {
2021
// SubCommandExists returns an error if no sub command is provided
2122
func SubCommandExists(cmd *cobra.Command, args []string) error {
2223
if len(args) > 0 {
23-
return errors.Errorf("unrecognized command `%[1]s %[2]s`\nTry '%[1]s --help' for more information.", cmd.CommandPath(), args[0])
24+
suggestions := cmd.SuggestionsFor(args[0])
25+
if len(suggestions) == 0 {
26+
return errors.Errorf("unrecognized command `%[1]s %[2]s`\nTry '%[1]s --help' for more information.", cmd.CommandPath(), args[0])
27+
}
28+
return errors.Errorf("unrecognized command `%[1]s %[2]s`\n\nDid you mean this?\n\t%[3]s\n\nTry '%[1]s --help' for more information.", cmd.CommandPath(), args[0], strings.Join(suggestions, "\n\t"))
2429
}
2530
return errors.Errorf("missing command '%[1]s COMMAND'\nTry '%[1]s --help' for more information.", cmd.CommandPath())
2631
}

0 commit comments

Comments
 (0)