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

Infer sub-commands/long-arguments if not fully typed/supplied but are fully unambiguous #863

Closed
neandrake opened this issue Feb 19, 2017 · 1 comment
Labels
A-parsing Area: Parser's logic and needs it changed somehow.
Milestone

Comments

@neandrake
Copy link

If a sub command or long argument is only partially entered, it would be an ergonomic benefit if clap could infer the right intended sub command or long argument as long as it's unambiguous.

This is currently possible by manually defining aliases for all possible partial matches, but is tedious and would be easy to make mistakes if there are many similar commands.

This is a feature I use heavily with Mercurial, here are some examples.

$ hg bookmark
  [snipped output]

$ hg book
  [snipped output]

$ hg bo
  [snipped output]

$ hg b
hg: command 'b' is ambiguous:
    backout bisect blame bookmarks branch branches bundle
$ hg push
  [snipped output]

$ hg pus
  [snipped output]

$ hg pu
hg: command 'pu' is ambiguous:
    pull purge push
$ hg stat --change master^
  [snipped output]

$ hg stat --cha master^
  [snipped output]

$ hg stat --ch master^
  [snipped output]

$ hg stat --c master^
hg status: option --c not a unique prefix
hg status [OPTION]... [FILE]...

show changed files in the working directory

options ([+] can be repeated):

 -A --all                 show status of all files
 -m --modified            show only modified files
 -a --added               show only added files
 -r --removed             show only removed files
 -d --deleted             show only deleted (but tracked) files
 -c --clean               show only files without changes
 -u --unknown             show only unknown (not tracked) files
 -i --ignored             show only ignored files
 -n --no-status           hide status prefix
 -C --copies              show source of copied files
 -0 --print0              end filenames with NUL, for use with xargs
    --rev REV [+]         show difference from revision
    --change REV          list the changed files of a revision
 -I --include PATTERN [+] include names matching the given patterns
 -X --exclude PATTERN [+] exclude names matching the given patterns
 -S --subrepos            recurse into subrepositories
    --mq                  operate on patch repository

(use 'hg status -h' to show more help)
@kbknapp
Copy link
Member

kbknapp commented Feb 19, 2017

I like it! Thanks for filing. I'll have to play around with how exactly I want to add this or how it will interact with the suggestions feature because I don't want misspelled words to get inferred, only shortened unambiguous words.

@kbknapp kbknapp added A-parsing Area: Parser's logic and needs it changed somehow. D: intermediate labels Feb 19, 2017
@kbknapp kbknapp added this to the 2.21.0 milestone Feb 22, 2017
kbknapp added a commit that referenced this issue Mar 9, 2017
…ened subcommands or aliases (i.e. for subcommmand "test", "t", "te", or "tes" would be allowed assuming no other ambiguities)

Closes #863
kbknapp added a commit that referenced this issue Mar 9, 2017
…ened subcommands or aliases (i.e. for subcommmand "test", "t", "te", or "tes" would be allowed assuming no other ambiguities)

Closes #863
@homu homu closed this as completed in 150756b Mar 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parsing Area: Parser's logic and needs it changed somehow.
Projects
None yet
Development

No branches or pull requests

2 participants