Replace use of arguments.length (#1235)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by John Gee · committed by GitHub · parent b5d95ee · Browse files · 1 file·+17 added−15 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+17 added−15 removed
- other:+17 added−15 removed
Provenance
- Commit
b59adfc- Tree
2628ba4- Author
John Gee <john@ruru.gen.nz>- Committer
GitHub <noreply@github.com>- Parent
b5d95ee
1 file changed+17 added−15 removed
modified:index.js+17 added-15 removed
580 unmodified lines581 * for unknown options.582 * @api public583 */584 allowUnknownOption(arg) {585- this._allowUnknownOption = arguments.length === 0 || arg;585+ this._allowUnknownOption = (arg === undefined) || arg;586 return this;587 };588 589 /**591 unmodified lines1181 * @api public1182 */1183 1184 version(str, flags, description) {1185- if (arguments.length === 0) return this._version;1185+ if (str === undefined) return this._version;1186 this._version = str;1187 flags = flags || '-V, --version';1188 description = description || 'output the version number';1189 const versionOption = new Option(flags, description);15 unmodified lines1205 * @api public1206 */1207 1208 description(str, argsDescription) {1209- if (arguments.length === 0) return this._description;1209+ if (str === undefined && argsDescription === undefined) return this._description;1210 this._description = str;1211 this._argsDescription = argsDescription;1212 return this;1213 };6 unmodified lines1220 * @api public1221 */1222 1223 alias(alias) {1224+ if (alias === undefined) return this._alias;1225+1226 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 this1229 command = this.commands[this.commands.length - 1];1230 }1231 1229- if (arguments.length === 0) return command._alias;1230-1232 if (alias === command._name) throw new Error('Command alias can\'t be the same as its name');1233 1234 command._alias = alias;1235 return this;7 unmodified lines1243 * @api public1244 */1245 1246 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;1249 1250+ const args = this._args.map((arg) => {1251+ return humanReadableArgName(arg);1252+ });1250- const usage = '[options]' +1251- (this.commands.length ? ' [command]' : '') +1252- (this._args.length ? ' ' + args.join(' ') : '');1253+ return '[options]' +1254+ (this.commands.length ? ' [command]' : '') +1255+ (this._args.length ? ' ' + args.join(' ') : '');1256+ }1257 1254- if (arguments.length === 0) return this._usage || usage;1258 this._usage = str;1256-1259 return this;1260 };1261 1262 /**4 unmodified lines1267 * @api public1268 */1269 1270 name(str) {1269- if (arguments.length === 0) return this._name;1271+ if (str === undefined) return this._name;1272 this._name = str;1273 return this;1274 };1275 444 unmodified lines