( command: Command<Name, Input, ContextInput, E, R>, commandPath: ReadonlyArray<string> )
| 33 | * Includes the root command as the first element. |
| 34 | */ |
| 35 | export const getCommandsForCommandPath = <Name extends string, Input, E, R, ContextInput>( |
| 36 | command: Command<Name, Input, ContextInput, E, R>, |
| 37 | commandPath: ReadonlyArray<string> |
| 38 | ): ReadonlyArray<Command.Any> => { |
| 39 | const commands: Array<Command.Any> = [command] |
| 40 | let currentCommand: Command.Any = command |
| 41 | |
| 42 | for (let i = 1; i < commandPath.length; i++) { |
| 43 | const subcommandName = commandPath[i] |
| 44 | let subcommand: Command.Any | undefined = undefined |
| 45 | |
| 46 | for (const group of currentCommand.subcommands) { |
| 47 | subcommand = group.commands.find((sub) => sub.name === subcommandName) |
| 48 | if (subcommand) { |
| 49 | break |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | if (!subcommand) { |
| 54 | break |
| 55 | } |
| 56 | |
| 57 | commands.push(subcommand) |
| 58 | currentCommand = subcommand |
| 59 | } |
| 60 | |
| 61 | return commands |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Returns active global flags for a command path. |
no test coverage detected