MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / findFirstSubcommand

Function findFirstSubcommand

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

Source from the content-addressed store, hash-verified

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

Callers 1

calculateDepthFunction · 0.85

Calls 2

flagTakesArgFunction · 0.85
isKnownSubcommandFunction · 0.70

Tested by

no test coverage detected