Suggestions for sub command names as well

This commit is contained in:
Kovid Goyal
2022-09-30 19:37:59 +05:30
parent 0dab006733
commit e536ef7844
2 changed files with 30 additions and 7 deletions

View File

@@ -101,6 +101,10 @@ func (self *Command) parse_args(ctx *Context, args []string) error {
}
if !self.SubCommandIsOptional {
if len(possible_cmds) == 0 {
possibles := self.SuggestionsForCommand(arg, 2)
if len(possibles) > 0 {
return &ParseError{Message: fmt.Sprintf("Unknown subcommand: :yellow:`%s`. Did you mean:\n\t%s", arg, strings.Join(possibles, "\n\t"))}
}
return &ParseError{Message: fmt.Sprintf(":yellow:`%s` is not a known subcommand for :emph:`%s`. Use --help to get a list of valid subcommands.", arg, self.Name)}
}
cn := make([]string, len(possible_cmds))