Skip to content

Commit b59adfc

Browse files
authored
Replace use of arguments.length (#1235)
1 parent b5d95ee commit b59adfc

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

index.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ class Command extends EventEmitter {
582582
* @api public
583583
*/
584584
allowUnknownOption(arg) {
585-
this._allowUnknownOption = arguments.length === 0 || arg;
585+
this._allowUnknownOption = (arg === undefined) || arg;
586586
return this;
587587
};
588588

@@ -1182,7 +1182,7 @@ class Command extends EventEmitter {
11821182
*/
11831183

11841184
version(str, flags, description) {
1185-
if (arguments.length === 0) return this._version;
1185+
if (str === undefined) return this._version;
11861186
this._version = str;
11871187
flags = flags || '-V, --version';
11881188
description = description || 'output the version number';
@@ -1206,7 +1206,7 @@ class Command extends EventEmitter {
12061206
*/
12071207

12081208
description(str, argsDescription) {
1209-
if (arguments.length === 0) return this._description;
1209+
if (str === undefined && argsDescription === undefined) return this._description;
12101210
this._description = str;
12111211
this._argsDescription = argsDescription;
12121212
return this;
@@ -1221,13 +1221,14 @@ class Command extends EventEmitter {
12211221
*/
12221222

12231223
alias(alias) {
1224+
if (alias === undefined) return this._alias;
1225+
12241226
let command = this;
1225-
if (this.commands.length !== 0) {
1227+
if (this.commands.length !== 0 && this.commands[this.commands.length - 1]._executableHandler) {
1228+
// assume adding alias for last added executable subcommand, rather than this
12261229
command = this.commands[this.commands.length - 1];
12271230
}
12281231

1229-
if (arguments.length === 0) return command._alias;
1230-
12311232
if (alias === command._name) throw new Error('Command alias can\'t be the same as its name');
12321233

12331234
command._alias = alias;
@@ -1243,17 +1244,18 @@ class Command extends EventEmitter {
12431244
*/
12441245

12451246
usage(str) {
1246-
const args = this._args.map((arg) => {
1247-
return humanReadableArgName(arg);
1248-
});
1247+
if (str === undefined) {
1248+
if (this._usage) return this._usage;
12491249

1250-
const usage = '[options]' +
1251-
(this.commands.length ? ' [command]' : '') +
1252-
(this._args.length ? ' ' + args.join(' ') : '');
1250+
const args = this._args.map((arg) => {
1251+
return humanReadableArgName(arg);
1252+
});
1253+
return '[options]' +
1254+
(this.commands.length ? ' [command]' : '') +
1255+
(this._args.length ? ' ' + args.join(' ') : '');
1256+
}
12531257

1254-
if (arguments.length === 0) return this._usage || usage;
12551258
this._usage = str;
1256-
12571259
return this;
12581260
};
12591261

@@ -1266,7 +1268,7 @@ class Command extends EventEmitter {
12661268
*/
12671269

12681270
name(str) {
1269-
if (arguments.length === 0) return this._name;
1271+
if (str === undefined) return this._name;
12701272
this._name = str;
12711273
return this;
12721274
};

0 commit comments

Comments
 (0)