Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dsgrangs-paul opened this issue Mar 12, 2019 · 4 comments
Labels
area/flags-args Changes to functionality around command line flags and args kind/bug A bug in cobra; unintended behavior

Comments

@dsgrangs-paul
Copy link

dsgrangs-paul commented Mar 12, 2019

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 dsgrangs-paul changed the title <Suggestions when "unknown command" happens> only works at first level ? Minimal distance : <Suggestions when "unknown command" happens> only works at first level ? Mar 25, 2019
@github-actions
Copy link

github-actions bot commented Apr 6, 2020

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

@dpopp07
Copy link

dpopp07 commented Nov 5, 2020

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?

@johnSchnake johnSchnake added kind/bug A bug in cobra; unintended behavior area/flags-args Changes to functionality around command line flags and args labels Aug 15, 2022
@johnSchnake
Copy link
Collaborator

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.

@YuviGold
Copy link
Contributor

YuviGold commented Sep 8, 2022

Hi @johnSchnake I already implemented a solution on #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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/flags-args Changes to functionality around command line flags and args kind/bug A bug in cobra; unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants