INNER CODE UNIT · JavaScript
parseCommand
sindresorhus/meow · source/index.js:49
const parseCommand = (input, options, parserOptions, showHelp) => {
if (!options.commands) {
return {command: undefined, input};
}
if (input.length === 0) {
return {command: undefined, input: []};
}
const command = String(input[0]);
if (!options.commands.includes(command)) {
if (!options.allowUnknownFlags && command.startsWith('-')) {
// The "command" looks like a flag. Determine whether it genuinely came from
// before '--' (an unknown parent flag) or after '--' (a post-separator positional
// being used as the command name). Re-parsing the pre-separator slice is the
// only reliable way — a simple indexOf would misfire when the same string
// appears as a flag value earlier in argv.