Skip to content

Commit 9aa4e02

Browse files
committedDec 4, 2016
Alias desc to description in argument/option config
1 parent 1b6eede commit 9aa4e02

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed
 

‎lib/actions/help.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ help.argumentsHelp = function argumentsHelp() {
106106
return [
107107
'',
108108
config.name ? config.name : '',
109-
config.desc ? '# ' + config.desc : '',
109+
config.description ? '# ' + config.description : '',
110110
config.type ? 'Type: ' + config.type.name : '',
111111
'Required: ' + config.required
112112
];
@@ -125,14 +125,12 @@ help.optionsHelp = function optionsHelp() {
125125
});
126126

127127
var rows = options.map(function (opt) {
128-
var defaults = opt.default;
129-
130128
return [
131129
'',
132130
opt.alias ? '-' + opt.alias + ', ' : '',
133131
'--' + opt.name,
134-
opt.desc ? '# ' + opt.desc : '',
135-
defaults == null || defaults === '' ? '' : 'Default: ' + defaults
132+
opt.description ? '# ' + opt.description : '',
133+
opt.default != null && opt.default !== '' ? 'Default: ' + opt.default : ''
136134
];
137135
});
138136

‎lib/index.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,18 @@ var Base = module.exports = function Base(args, options) {
7373

7474
this.option('help', {
7575
alias: 'h',
76-
desc: 'Print the generator\'s options and usage'
76+
description: 'Print the generator\'s options and usage'
7777
});
7878

7979
this.option('skip-cache', {
8080
type: Boolean,
81-
desc: 'Do not remember prompt answers',
81+
description: 'Do not remember prompt answers',
8282
default: false
8383
});
8484

8585
this.option('skip-install', {
8686
type: Boolean,
87-
desc: 'Do not automatically install dependencies',
87+
description: 'Do not automatically install dependencies',
8888
default: false
8989
});
9090

@@ -179,7 +179,7 @@ Base.prototype.prompt = function (questions) {
179179
*
180180
* ### Options:
181181
*
182-
* - `desc` Description for the option
182+
* - `description` Description for the option
183183
* - `type` Either Boolean, String or Number
184184
* - `alias` Option name alias (example `-h` and --help`)
185185
* - `default` Default value
@@ -191,11 +191,15 @@ Base.prototype.prompt = function (questions) {
191191

192192
Base.prototype.option = function option(name, config) {
193193
config = config || {};
194+
195+
// alias default to defaults for backward compatibility.
196+
config.default = config.default != null ? config.default : config.defaults;
197+
config.description = config.description || config.desc;
198+
194199
_.defaults(config, {
195200
name: name,
196-
desc: 'Description for ' + name,
201+
description: 'Description for ' + name,
197202
type: Boolean,
198-
default: config.defaults,
199203
hide: false
200204
});
201205

@@ -219,7 +223,7 @@ Base.prototype.option = function option(name, config) {
219223
*
220224
* ### Options:
221225
*
222-
* - `desc` Description for the argument
226+
* - `description` Description for the argument
223227
* - `required` Boolean whether it is required
224228
* - `optional` Boolean whether it is optional
225229
* - `type` String, Number, Array, or Object
@@ -233,7 +237,8 @@ Base.prototype.argument = function argument(name, config) {
233237
config = config || {};
234238

235239
// alias default to defaults for backward compatibility.
236-
config.default = config.default || config.defaults;
240+
config.default = config.default != null ? config.default : config.defaults;
241+
config.description = config.description || config.desc;
237242

238243
_.defaults(config, {
239244
name: name,

‎test/base.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ describe('Base', function () {
658658

659659
generator.option('foo');
660660
assert.deepEqual(generator._options.foo, {
661-
desc: 'Description for foo',
661+
description: 'Description for foo',
662662
name: 'foo',
663663
type: Boolean,
664664
default: undefined,

0 commit comments

Comments
 (0)
Please sign in to comment.