-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Allow for multiple aliases #531
Comments
I'd be happy to add this but would love feedback on the syntax. Some requirements:
Option 1import commander from 'commander';
commander
.command('link:create <a> <b>')
.alias('l', 'lc', 'link')
.action(...); Then
Which might get a bit excessive. Instead some aliases might be hidden instead. Option 2import commander from 'commander';
commander
.command('link:create <a> <b>')
.alias('link')
.hidden_alias('l', 'lc')
.action(...); Which would then result in:
Option 3The alternative would be to pass an object with the keys of the aliases and the values of the visibility: import commander from 'commander';
commander
.command('link:create <a> <b>')
.alias({ link: true, lc: false, l: false})
.action(...); Option 4Finally the last option would be to define aliases outside of the command scope: import commander from 'commander';
commander
.command('link:create <a> <b>')
.alias('link')
.action(...);
commander.alias('link:create', {lc: false, l: false}); I personally prefer option 2 but I'd love some feedback. |
Would love to see support for multiple aliases. I'd personally prefer something like this: import commander from 'commander';
commander
.command('list')
.alias('ls')
.alias('l', false)
.action(...); Where |
@kodie 's suggestion is what occurred to me to try naturally. That's how I discovered not yet implemented :) |
Well, Commander already has support for a kind of "aliasing" on options: import commander from 'commander';
commander
.option('-f, --foo', 'Foo option')
.parse(process.argv); Why not reuse the syntax for commands instead? It would look like this: import commander from 'commander';
commander
.command('link, link:create <a> <b>')
.action(...); |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Not consensus, throw in another idea @DuckyCrayfish I personally lean towards just repeating For the help, an approach I have used in another product is to list the aliases in a separate help section. This avoids cluttering up the main command help with the variations. e.g.
(The "real" commands are listed on the right.) |
This comment has been minimized.
This comment has been minimized.
I am interested in the approach of allowing repeated Hiding some aliases was listed in the original requirements and followed through in the examples. I am reluctant to add a plain boolean parameter for a somewhat uncommon feature, as it is not extensible or self documenting. But just listing all the aliases when there are lots will be a bit messy in the current format in the help! Would listing just the first alias in the built-in help be a usable compromise? So for @kodie example: #531 (comment)
|
I have written a PR with support for multiple aliases, the first of which is included in the autogenerated help: #1236 Interested readers, is this an adequate implementation for the feature request to allow multiple aliases? |
* Allow for multiple aliases #531 * Add tests for multiple alias behaviours * Add aliases() mainly for getter * Fix typo
Support for multiple aliases has been released in Command v5.1. Thank you for your contributions. |
I'd love for commander allow to allow for multiple aliases. I've found them to be useful for many reasons varying from default subcommands (
records:list
andrecords
,record:show
andrecord
), preventing typos (record:list
vsrecords:list
) and just shortcuts (records:list
andrl
).Currently I'm resorting to duplicating my
command
statements which feels far from effective.The text was updated successfully, but these errors were encountered: