Add special case for unsupported gh <command> help

This commit is contained in:
Mislav Marohnić 2020-06-16 16:06:51 +02:00
parent 311536433c
commit f64e5f16eb

View file

@ -42,21 +42,26 @@ func HasFailed() bool {
// This matches Cobra's behavior for root command, which Cobra
// confusingly doesn't apply to nested commands.
func nestedSuggestFunc(command *cobra.Command, arg string) {
command.Printf("unknown command %q for `%s`\n", arg, command.UseLine())
command.Printf("unknown command %q for %q\n", arg, command.CommandPath())
if command.SuggestionsMinimumDistance <= 0 {
command.SuggestionsMinimumDistance = 2
var candidates []string
if arg == "help" {
candidates = []string{"--help"}
} else {
if command.SuggestionsMinimumDistance <= 0 {
command.SuggestionsMinimumDistance = 2
}
candidates = command.SuggestionsFor(arg)
}
candidates := command.SuggestionsFor(arg)
if len(candidates) > 0 {
command.Print("\nDid you mean this?\n")
for _, c := range candidates {
command.Printf("\t%s\n", c)
}
command.Print("\n")
}
command.Print("\n")
_ = rootUsageFunc(command)
}