MCPcopy Create free account
hub / github.com/Effect-TS/effect / getCommandsForCommandPath

Function getCommandsForCommandPath

packages/effect/src/cli/internal/help.ts:35–62  ·  view source on GitHub ↗
(
  command: Command<Name, Input, ContextInput, E, R>,
  commandPath: ReadonlyArray<string>
)

Source from the content-addressed store, hash-verified

33 * Includes the root command as the first element.
34 */
35export 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.

Callers 2

getHelpForCommandPathFunction · 0.85

Calls 2

findMethod · 0.65
pushMethod · 0.65

Tested by

no test coverage detected