MCPcopy Index your code
hub / github.com/codeaashu/claude-code / findFirstSubcommand

Function findFirstSubcommand

src/utils/shell/specPrefix.ts:71–86  ·  view source on GitHub ↗
(
  args: string[],
  spec: CommandSpec | null,
)

Source from the content-addressed store, hash-verified

69
70// Find the first subcommand by skipping flags and their values
71function findFirstSubcommand(
72 args: string[],
73 spec: CommandSpec | null,
74): string | undefined {
75 for (let i = 0; i < args.length; i++) {
76 const arg = args[i]
77 if (!arg) continue
78 if (arg.startsWith('-')) {
79 if (flagTakesArg(arg, args[i + 1], spec)) i++
80 continue
81 }
82 if (!spec?.subcommands?.length) return arg
83 if (isKnownSubcommand(arg, spec)) return arg
84 }
85 return undefined
86}
87
88export async function buildPrefix(
89 command: string,

Callers 1

calculateDepthFunction · 0.85

Calls 2

flagTakesArgFunction · 0.85
isKnownSubcommandFunction · 0.70

Tested by

no test coverage detected