Skip to content

Commit

Permalink
Alias desc to description in argument/option config
Browse files Browse the repository at this point in the history
  • Loading branch information
SBoudrias committed Dec 4, 2016
1 parent 1b6eede commit 9aa4e02
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
8 changes: 3 additions & 5 deletions lib/actions/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ help.argumentsHelp = function argumentsHelp() {
return [
'',
config.name ? config.name : '',
config.desc ? '# ' + config.desc : '',
config.description ? '# ' + config.description : '',
config.type ? 'Type: ' + config.type.name : '',
'Required: ' + config.required
];
Expand All @@ -125,14 +125,12 @@ help.optionsHelp = function optionsHelp() {
});

var rows = options.map(function (opt) {
var defaults = opt.default;

return [
'',
opt.alias ? '-' + opt.alias + ', ' : '',
'--' + opt.name,
opt.desc ? '# ' + opt.desc : '',
defaults == null || defaults === '' ? '' : 'Default: ' + defaults
opt.description ? '# ' + opt.description : '',
opt.default != null && opt.default !== '' ? 'Default: ' + opt.default : ''
];
});

Expand Down
21 changes: 13 additions & 8 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,18 @@ var Base = module.exports = function Base(args, options) {

this.option('help', {
alias: 'h',
desc: 'Print the generator\'s options and usage'
description: 'Print the generator\'s options and usage'
});

this.option('skip-cache', {
type: Boolean,
desc: 'Do not remember prompt answers',
description: 'Do not remember prompt answers',
default: false
});

this.option('skip-install', {
type: Boolean,
desc: 'Do not automatically install dependencies',
description: 'Do not automatically install dependencies',
default: false
});

Expand Down Expand Up @@ -179,7 +179,7 @@ Base.prototype.prompt = function (questions) {
*
* ### Options:
*
* - `desc` Description for the option
* - `description` Description for the option
* - `type` Either Boolean, String or Number
* - `alias` Option name alias (example `-h` and --help`)
* - `default` Default value
Expand All @@ -191,11 +191,15 @@ Base.prototype.prompt = function (questions) {

Base.prototype.option = function option(name, config) {
config = config || {};

// alias default to defaults for backward compatibility.
config.default = config.default != null ? config.default : config.defaults;
config.description = config.description || config.desc;

_.defaults(config, {
name: name,
desc: 'Description for ' + name,
description: 'Description for ' + name,
type: Boolean,
default: config.defaults,
hide: false
});

Expand All @@ -219,7 +223,7 @@ Base.prototype.option = function option(name, config) {
*
* ### Options:
*
* - `desc` Description for the argument
* - `description` Description for the argument
* - `required` Boolean whether it is required
* - `optional` Boolean whether it is optional
* - `type` String, Number, Array, or Object
Expand All @@ -233,7 +237,8 @@ Base.prototype.argument = function argument(name, config) {
config = config || {};

// alias default to defaults for backward compatibility.
config.default = config.default || config.defaults;
config.default = config.default != null ? config.default : config.defaults;
config.description = config.description || config.desc;

_.defaults(config, {
name: name,
Expand Down
2 changes: 1 addition & 1 deletion test/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ describe('Base', function () {

generator.option('foo');
assert.deepEqual(generator._options.foo, {
desc: 'Description for foo',
description: 'Description for foo',
name: 'foo',
type: Boolean,
default: undefined,
Expand Down

0 comments on commit 9aa4e02

Please sign in to comment.