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

feat: initial support for command aliases #647

Merged
merged 7 commits into from Oct 10, 2016
Merged

feat: initial support for command aliases #647

merged 7 commits into from Oct 10, 2016

Conversation

nexdrew
Copy link
Member

@nexdrew nexdrew commented Oct 4, 2016

Allows a command to have aliases if given as an array, e.g.

.command(['start', 'run', 'go'], 'Start the app', builder, handler)

The first element in the array is treated as the canonical command, which supports positional args; the remaining elements are considered aliases. Aliases inherit their positional args from the canonical command and, thus, any positional args defined for an alias are ignored.

For example, all of the following are equivalent and only the <name> required positional arg will be parsed/validated:

.command(['hi <name>', 'hello'], 'Say hi', builder, handler)
.command(['hi <name>', 'hello <name>'], 'Say hi', builder, handler)
.command(['hi <name>', 'hello <someone> [others..]'], 'Say hi', builder, handler)

For help text, command aliases are displayed in a new right-aligned column after the canonical command and description, e.g.

$ node test.js help
Commands:
  start      Start the app                                    [aliases: go, run]
  hi <name>  Say hi                                             [aliases: hello]

Options:
  --help  Show help                                                    [boolean]

TODO:

  • Tests
  • Add "aliases:" to all locales Will create a new issue for this
  • Docs

{text: command[0], padding: [0, 2, 0, 2], width: maxWidth(commands, theWrap) + 4},
{text: command[1]}
)
if (command[2] && command[2].length) {
ui.div({text: '[' + __('aliases:') + ' ' + command[2].join(', ') + ']', padding: [0, 0, 0, 2], align: 'right'})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this implementation of aliases 👍 it's nice to see cliui being dusted off.

@bcoe
Copy link
Member

bcoe commented Oct 6, 2016

@nexdrew for the locale files; feel free to open an issue and not let this block landing this feature.

@nexdrew nexdrew changed the title [WIP] feat: initial support for command aliases feat: initial support for command aliases Oct 6, 2016
@nexdrew
Copy link
Member Author

nexdrew commented Oct 6, 2016

This should be ready for final review. Added the ability for command modules to export an aliases property so they don't have to use an array for the command property, because why not.

@bcoe @maxrimue Let me know what you think.

@nexdrew nexdrew mentioned this pull request Oct 6, 2016
@maxrimue
Copy link
Member

maxrimue commented Oct 9, 2016

LGTM, nice work 👍

We should probably open a new issue to call for translations of aliases once this PR is merged. Btw, the German translation would be Aliase, maybe you can implement this right into this PR @nexdrew?
I think we also still need to call for translations for Did you mean?, could do this in the same issue.

@nexdrew
Copy link
Member Author

nexdrew commented Oct 9, 2016

Oh good point! Thanks @maxrimue, I'll do that.

Copy link
Member

@bcoe bcoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wonderful @nexdrew, I'm hoping to take on default commands tomorrow using this as a jumping off point.

@nexdrew nexdrew merged commit 127a040 into master Oct 10, 2016
@nexdrew nexdrew deleted the command-alias branch October 10, 2016 03:34
@nexdrew nexdrew mentioned this pull request Oct 10, 2016
18 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants