MCPcopy
hub / github.com/tj/commander.js / addArgument

Method addArgument

lib/command.js:376–394  ·  view source on GitHub ↗

* Define argument syntax for command, adding a prepared argument. * * @param {Argument} argument * @return {Command} `this` command for chaining

(argument)

Source from the content-addressed store, hash-verified

374 * @return {Command} `this` command for chaining
375 */
376 addArgument(argument) {
377 const previousArgument = this.registeredArguments.slice(-1)[0];
378 if (previousArgument?.variadic) {
379 throw new Error(
380 `only the last argument can be variadic '${previousArgument.name()}'`,
381 );
382 }
383 if (
384 argument.required &&
385 argument.defaultValue !== undefined &&
386 argument.parseArg === undefined
387 ) {
388 throw new Error(
389 `a default value for a required argument is never used: '${argument.name()}'`,
390 );
391 }
392 this.registeredArguments.push(argument);
393 return this;
394 }
395
396 /**
397 * Customise or override default help command. By default a help command is automatically added if your command has subcommands.

Callers 11

argumentMethod · 0.95
getSingleArgCasesFunction · 0.80
getMultipleArgCasesFunction · 0.80
getTestCasesFunction · 0.80
arguments-extra.jsFile · 0.80

Calls 1

nameMethod · 0.45

Tested by 3

getSingleArgCasesFunction · 0.64
getMultipleArgCasesFunction · 0.64
getTestCasesFunction · 0.64