Merge pull request #10771 from infiniteregrets/cli
[NO TESTS NEEDED] Suggestions for typos/ incorrect commands for Podman CLI
This commit is contained in:
commit
d1f57a07c2
|
|
@ -3,6 +3,7 @@ package validate
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/containers/podman/v3/cmd/podman/registry"
|
"github.com/containers/podman/v3/cmd/podman/registry"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
@ -20,7 +21,11 @@ func NoArgs(cmd *cobra.Command, args []string) error {
|
||||||
// SubCommandExists returns an error if no sub command is provided
|
// SubCommandExists returns an error if no sub command is provided
|
||||||
func SubCommandExists(cmd *cobra.Command, args []string) error {
|
func SubCommandExists(cmd *cobra.Command, args []string) error {
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
return errors.Errorf("unrecognized command `%[1]s %[2]s`\nTry '%[1]s --help' for more information.", cmd.CommandPath(), args[0])
|
suggestions := cmd.SuggestionsFor(args[0])
|
||||||
|
if len(suggestions) == 0 {
|
||||||
|
return errors.Errorf("unrecognized command `%[1]s %[2]s`\nTry '%[1]s --help' for more information.", cmd.CommandPath(), args[0])
|
||||||
|
}
|
||||||
|
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"))
|
||||||
}
|
}
|
||||||
return errors.Errorf("missing command '%[1]s COMMAND'\nTry '%[1]s --help' for more information.", cmd.CommandPath())
|
return errors.Errorf("missing command '%[1]s COMMAND'\nTry '%[1]s --help' for more information.", cmd.CommandPath())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue