(
commands: Command[],
groupName: string,
commandName: string,
initOptions: InitConfig,
)
| 28 | |
| 29 | export function getCommand(commands: Command[], groupName: string, commandName: string): Command { |
| 30 | if (groupName === 'fs') { |
| 31 | groupName = 'filesystem'; |
| 32 | } |
| 33 | |
| 34 | let matches = commands.filter((command) => command.group.startsWith(groupName) && command.name === commandName); |
| 35 | if (matches.length === 1) { |
| 36 | return matches[0]; |
| 37 | } |
| 38 | |
| 39 | matches = commands.filter((command) => command.group.startsWith(groupName) && command.name.startsWith(commandName)); |
| 40 | if (matches.length === 1) { |
| 41 | return matches[0]; |
| 42 | } |
| 43 | |
| 44 | if (matches.length === 0) { |
| 45 | matches = commands.filter((command) => command.group.startsWith(groupName)); |
| 46 | } |
| 47 | |
| 48 | printUsage(matches.length > 0 ? matches : commands); |
| 49 | throw new CommandNotFoundError(`Command not found: ${groupName || ''} ${commandName || ''}`); |
| 50 | } |
| 51 | |
| 52 | export function getCommandArguments( |
| 53 | command: Command, |
| 54 | argv: string[], |
| 55 | ): { options: { [name: string]: unknown }; args: string[] } { |
| 56 | try { |
| 57 | const { values: options, positionals } = parseArgs({ |
| 58 | args: argv, |
| 59 | options: command.options || {}, |
| 60 | strict: true, |
| 61 | allowPositionals: true, |
| 62 | }); |
no test coverage detected