178
return;
179
}
181
>
// The 'cmd' provided was a string, we apply the command DSL:
182
>
// https://github.com/yargs/yargs/blob/main/docs/advanced.md#advanced-topics
183
>
if (typeof cmd === 'string') {
184
>
// parse positionals out of cmd string
185
>
const parsedCommand = parseCommand(cmd);
186
>
187
>
// remove positional args from aliases only
188
>
aliases = aliases.map(alias => parseCommand(alias).cmd);
189
>
190
>
// check for default and filter out '*'
191
>
let isDefault = false;
192
>
const parsedAliases = [parsedCommand.cmd].concat(aliases).filter(c => {
193
>
if (DEFAULT_MARKER.test(c)) {
194
isDefault = true;
195
return false;
196
}
197
return true;
199
>
200
>
// standardize on $0 for default command.
201
>
if (parsedAliases.length === 0 && isDefault) parsedAliases.push('$0');
202
>
203
>
// shift cmd and aliases after filtering out '*'
204
>
if (isDefault) {
205
parsedCommand.cmd = parsedAliases[0];
206
aliases = parsedAliases.slice(1);
207
cmd = cmd.replace(DEFAULT_MARKER, parsedCommand.cmd);
208
}
210
>
// populate aliasMap
211
>
aliases.forEach(alias => {
212
this.aliasMap[alias] = parsedCommand.cmd;
214
>
215
>
if (description !== false) {
216
this.usage.command(cmd, description, isDefault, aliases, deprecated);
217
}
219
>
this.handlers[parsedCommand.cmd] = {
220
>
original: cmd,
221
>
description,
222
>
handler,
223
>
builder: (builder as CommandBuilder) || {},
224
>
middlewares,
225
>
deprecated,
226
>
demanded: parsedCommand.demanded,
227
>
optional: parsedCommand.optional,
228
>
};
229
>
230
>
if (isDefault) this.defaultCommand = this.handlers[parsedCommand.cmd];
231
>
}
232
}
233
getCommandHandlers(): Dictionary<CommandHandler> {