* Add a prepared subcommand. * * See .command() for creating an attached subcommand which inherits settings from its parent. * * @param {Command} cmd - new subcommand * @param {object} [opts] - configuration options * @return {Command} `this` command for chaining
(cmd, opts)
| 287 | */ |
| 288 | |
| 289 | addCommand(cmd, opts) { |
| 290 | if (!cmd._name) { |
| 291 | throw new Error(`Command passed to .addCommand() must have a name |
| 292 | - specify the name in Command constructor or using .name()`); |
| 293 | } |
| 294 | |
| 295 | opts = opts || {}; |
| 296 | if (opts.isDefault) this._defaultCommandName = cmd._name; |
| 297 | if (opts.noHelp || opts.hidden) cmd._hidden = true; // modifying passed command due to existing implementation |
| 298 | |
| 299 | this._registerCommand(cmd); |
| 300 | cmd.parent = this; |
| 301 | cmd._checkForBrokenPassThrough(); |
| 302 | |
| 303 | return this; |
| 304 | } |
| 305 | |
| 306 | /** |
| 307 | * Factory routine to create a new unattached argument. |