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

Allow command modules to define all command properties #414

Merged
merged 1 commit into from Mar 12, 2016
Merged

Allow command modules to define all command properties #414

merged 1 commit into from Mar 12, 2016

Conversation

nexdrew
Copy link
Member

@nexdrew nexdrew commented Mar 4, 2016

This just expands support for command modules such that the command string and description can also be defined by the module, like so:

// foo.js
module.exports = {
  command: 'foo <bar> [baz]',
  describe: 'foo all the things',
  builder: function (yargs) { return yargs },
  handler: function (argv) {}
}
// cli.js
var argv = require('yargs')
  .command(require('./foo.js'))
  .argv

A command string must be provided by the command property (and it must be a string).

A description is optional. If not provided, the command will be "hidden". If provided, it can be a string or a boolean, and for consistency with the options API it can be provided by a describe, a description, or a desc property (in that order).

I see this as an incremental step toward allowing command modules to be more self-sufficient and auto-discovered.

Note that I added a bunch of "API" tests to test/command.js to account for what the .command() method should accept as args, but I'm not sure they provide much value. But I figure, why not.

@nexdrew nexdrew changed the title Allow command modules to be define all command properties Allow command modules to define all command properties Mar 4, 2016
@nexdrew
Copy link
Member Author

nexdrew commented Mar 4, 2016

CI failures seem to be red herrings.

npm install failed on Travis, but only for Linux Node 0.12.

AppVeyor failed due to npm 1.x with Node 0.10, which will be fixed by #413.

@bcoe
Copy link
Member

bcoe commented Mar 4, 2016

@nexdrew mind rebasing with:

#413

should help some of the CI weirdness.

@nexdrew
Copy link
Member Author

nexdrew commented Mar 4, 2016

Rebased

bcoe added a commit that referenced this pull request Mar 12, 2016
Allow command modules to define all command properties
@bcoe bcoe merged commit b8da624 into yargs:master Mar 12, 2016
@nexdrew nexdrew deleted the expand-command-module branch March 30, 2016 15:10
bcoe pushed a commit that referenced this pull request Apr 4, 2016
* document additional command module props a la #414
* document Error instance for fail handler a la #382
* add missing locales to readme
* add "number" to en.json locale
* add "number" to it.json locale
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

2 participants