cobra icon indicating copy to clipboard operation
cobra copied to clipboard

Minimal distance : <Suggestions when "unknown command" happens> only works at first level ?

Open dsgrangs-paul opened this issue 5 years ago • 4 comments

This is related to the 'minimal distance' between strings It seems that this functionality only works at first level of command, and not at sub-levels ?

Suggestions when "unknown command" happens only at first level of command

I have a three levels command, something like (presenting by level)
1/ mycmd 2/ mycmd list mycmd modify

3/ mycmd list volumes mycmd list disks mycmd list networks mycmd modify volumes mycmd modify disks mycmd modify networks

The suggestion works well for level 2 : if ever I do a typo on 'list' or 'modify' then I have the msg "Did you mean this?". But the suggestions does not work at all if I do a typo on the third level : a typo on 'volumes', 'disks', 'networks' does not generate the "Did you mean this?" message ?

I ve tried to play with such kind of code (see below), without success : volumesCmd.DisableSuggestions = false volumesCmd.SuggestionsMinimumDistance = 2 listCmd.AddCommand(volumesCmd)

Thank you for any help or clue !

dsgrangs-paul avatar Mar 12 '19 15:03 dsgrangs-paul

This issue is being marked as stale due to a long period of inactivity

github-actions[bot] avatar Apr 06 '20 00:04 github-actions[bot]

I am also interested in this ^

From this code it looks intentional but I'm wondering

  1. why is that?
  2. is there any way to make that configurable so that the lowest level commands (without subcommands) get suggestions for typos?

dpopp07 avatar Nov 05 '20 19:11 dpopp07

I agree on the surface that looks like a bug but may have been intentional due to some legacy support. Added tags to issue but still in need of someone to pick it up.

johnSchnake avatar Aug 15 '22 20:08 johnSchnake

Hi @johnSchnake I already implemented a solution on https://github.com/spf13/cobra/pull/1500 but the maintainers of the repository had mixed thoughts about it and didn't get to a consensus how to address this issue since it will break backward compatibility. @jpmcb let me know if you think it should be implemented or whether we can close this issue.

YuviGold avatar Sep 08 '22 16:09 YuviGold