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

Command abbreviation support #1463

Closed
glensc opened this issue Feb 4, 2021 · 5 comments
Closed

Command abbreviation support #1463

glensc opened this issue Feb 4, 2021 · 5 comments

Comments

@glensc
Copy link

glensc commented Feb 4, 2021

Coming from php background, symfony/console allows to abbreviate commands to lessen typing:

➔ ./bin/console.ts --help
Usage: console [options] [command]

Options:
  -h, --help      display help for command

Commands:
  sync <worker>   Run sync for worker
  help [command]  display help for command

it should be able to find 'sync' command, as it's unique enough:

➔ ./bin/console.ts s
error: unknown command 's'. See 'console --help'.
@shadowspawn
Copy link
Collaborator

I got used to this with Mercurial, but not supported by Git and I am out of the habit now. With options, getopt_long supports unambiguous abbreviations.

@glensc
Copy link
Author

glensc commented Feb 5, 2021

@shadowspawn implementing this on your own is very trivial:

  1. iterate over all command names and aliases:
    1. push name to candidates array if substring(0, length(argument_from_commandline)) matches
  2. return candidates[0] if candidates.length === 1
  3. return null otherwise

additionally, the commander could do:

  1. if a non-unique match was found print names that were found
  2. if nothing was found, print out all command names suggestion

@shadowspawn
Copy link
Collaborator

shadowspawn commented Feb 5, 2021

I think step 2 is incomplete, but I get the intent.

However, the hard part for me is not implementing it, but deciding whether it is appropriate as the behaviour for all users of the library and all ways Commander could have been used. If it is popular enough but not appropriate as the default, then making it opt-in is a possibility.

@glensc

This comment has been minimized.

@shadowspawn
Copy link
Collaborator

This issue has not had any activity in over six months. It isn't likely to get acted on due to this report.

My main reservation about using abbreviation support with a program is that it can make adding a command a breaking change. Users who have used a previously unambiguous abbreviation in a script will get an error if the new command is also a candidate.

On a related note, I am open to offering an unambiguous match as a candidate for unknown commands. See #1590

Feel free to open a new issue if it comes up again, with new information and renewed interest.

Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants