question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RFC: Command Aliases

See original GitHub issue

Command 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:closed
  • Created 4 years ago
  • Reactions:7
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
lukeedcommented, Dec 8, 2019

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.

I actually reimplemented the whole Sade from scratch

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 👍

1reaction
lukeedcommented, Dec 9, 2019

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

RfC 5321 - IETF
85 Appendix B. Generating SMTP Commands from RFC 822 Header Fields . ... Local aliases MUST NOT appear in any SMTP transaction.
Read more >
RFC 2219: Use of DNS Aliases for Network Services
RFC 2219 DNS Aliases October 1997 Perhaps the most visible example of the latter approach at work is in the case of World-Wide...
Read more >
aliases(5) - Linux manual page - man7.org
The command is run under the privileges of the daemon's unprivileged account. :include:/path/to/file Include any definitions in file as alias entries.
Read more >
Setting Up Mail Aliases in /etc/aliases
Mail aliases in /etc/aliases are public. This means that if you set up a mail alias called softball, anyone can send to softball@...
Read more >
2515-type_alias_impl_trait - The Rust RFC Book
Summary. Allow type aliases and associated types to use impl Trait , replacing the prototype existential type as a way to declare type...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found