RFC: Command Aliases
See original GitHub issueCommand aliases are (generally) an abbreviated form of the command. Theyâre typically geared for lazy typers and/or power users đ
The most common example that many of us are probably familiar with is npm install
, which is also accessible via npm i
. All options and arguments still carry over identically.
Hereâs how it would/could be added in a Sade program:
sade('npm')
.command('install [package]', 'Install a package', { alias: 'i' })
.option('-P, --save-prod', 'Package will appear in your dependencies.')
.option('-D, --save-dev', 'Package will appear in your devDependencies.')
.option('-O, --save-optional', 'Package will appear in your optionalDependencies')
.option('-E, --save-exact', 'Save exact versions instead of using a semver range operator')
.action(handler);
When running npm --help
, youâll see this:
Usage
$ npm <command> [options]
Available Commands
install Install a package
For more info, run any command with the `--help` flag
$ npm install --help
Options
-v, --version Displays current version
-h, --help Displays this message
Note: Thereâs no mention of aliases here. This output is unchanged
And when running npm install --help
youâd see this:
Description
Install a package
Usage
$ npm install [package] [options]
Aliases
$ npm i
Options
-P, --save-prod Package will appear in your dependencies.
-D, --save-dev Package will appear in your devDependencies.
-O, --save-optional Package will appear in your optionalDependencies
-E, --save-exact Save exact versions instead of using a semver range operator
-h, --help Displays this message
Of course, running npm install
and npm i
are synonymous, which also means that running npm i -h
would also print the above output.
And now, some options and voting đ
1. Do we even want this?
2. Should multiple aliases be allowed?
Back to the npm install
example â they actually have 3 aliases: i, isntall, add
For the same Sade program, this would mean the alias
option accepts an array:
prog.command('install [package]', '...', { alias: ['i', 'add', 'isntall'] })
Description
Install a package
Usage
$ npm install [package] [options]
Aliases
$ npm i
$ npm add
$ npm isntall
Options
-P, --save-prod Package will appear in your dependencies.
-D, --save-dev Package will appear in your devDependencies.
-O, --save-optional Package will appear in your optionalDependencies
-E, --save-exact Save exact versions instead of using a semver range operator
-h, --help Displays this message
3. Should aliases be added through a method?
Personally, a new .alias()
method would only make sense if we allow multiple aliases. Otherwise itâd be awkward and a no-go from me, I think.
Another drawback is that this would be the only API method that requires declaration after a .command()
usage. Unlike .option()
, you canât declare a âglobal aliasâ since that means nothing.
A final drawback is that a commandâs aliases is declared across two methods, whereas an optionâs alias is declared in one fell swoop. Keeping command aliases within the command()
options will keep it âin one fell swoopâ
// Proposed:
prog.command('install [package]', '...', {
alias: ['i', 'add', 'isntall']
})
// Alternative:
prog
.command('install [package]', '...')
.alias('i', 'add', 'isntall')
Thanks for dropping by!
PS: Votes are anonymous đ
Issue Analytics
- State:
- Created 4 years ago
- Reactions:7
- Comments:14 (5 by maintainers)
Top GitHub Comments
PR open, will publish tomorrow unless something major comes up in feedback.
I went with the âdeveloper bewareâ approach, which does always leave room for a non-breaking patch release if people want the checks in place.
Maybe youâll drop your fork now, haha. Otherwise Iâm confused as to why youâre leading the charge on this feature. Also, too late now, but I would have appreciated an actual fork if you planned on doing so. I see & appreciate the NOTICES/other mentions, but thereâs still a lack of continuity and history there. Not a big deal, just a sidenote đ
No worries! Sorry didnât mean for you to try to defend yourself, my bad. I actually dunno how youâd do it within a monorepo