* Define argument syntax for command, adding a prepared argument. * * @param {Argument} argument * @return {Command} `this` command for chaining
(argument)
| 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. |