* Define a command. * * There are two styles of command: pay attention to where to put the description. * * @example * // Command implemented using action handler (description is supplied separately to `.command`) * program * .command('clone [destination]') * .de
(nameAndArgs, actionOptsOrExecDesc, execOpts)
| 154 | */ |
| 155 | |
| 156 | command(nameAndArgs, actionOptsOrExecDesc, execOpts) { |
| 157 | let desc = actionOptsOrExecDesc; |
| 158 | let opts = execOpts; |
| 159 | if (typeof desc === 'object' && desc !== null) { |
| 160 | opts = desc; |
| 161 | desc = null; |
| 162 | } |
| 163 | opts = opts || {}; |
| 164 | const [, name, args] = nameAndArgs.match(/([^ ]+) *(.*)/); |
| 165 | |
| 166 | const cmd = this.createCommand(name); |
| 167 | if (desc) { |
| 168 | cmd.description(desc); |
| 169 | cmd._executableHandler = true; |
| 170 | } |
| 171 | if (opts.isDefault) this._defaultCommandName = cmd._name; |
| 172 | cmd._hidden = !!(opts.noHelp || opts.hidden); // noHelp is deprecated old name for hidden |
| 173 | cmd._executableFile = opts.executableFile || null; // Custom name for executable file, set missing to null to match constructor |
| 174 | if (args) cmd.arguments(args); |
| 175 | this._registerCommand(cmd); |
| 176 | cmd.parent = this; |
| 177 | cmd.copyInheritedSettings(this); |
| 178 | |
| 179 | if (desc) return this; |
| 180 | return cmd; |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * Factory routine to create a new unattached command. |