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

Function flagTakesArg

src/utils/shell/specPrefix.ts:51–68  ·  view source on GitHub ↗
(
  flag: string,
  nextArg: string | undefined,
  spec: CommandSpec | null,
)

Source from the content-addressed store, hash-verified

49
50// Check if a flag takes an argument based on spec, or use heuristic
51function flagTakesArg(
52 flag: string,
53 nextArg: string | undefined,
54 spec: CommandSpec | null,
55): boolean {
56 // Check if flag is in spec.options
57 if (spec?.options) {
58 const option = spec.options.find(opt =>
59 Array.isArray(opt.name) ? opt.name.includes(flag) : opt.name === flag,
60 )
61 if (option) return !!option.args
62 }
63 // Heuristic: if next arg isn't a flag and isn't a known subcommand, assume it's a flag value
64 if (spec?.subcommands?.length && nextArg && !nextArg.startsWith('-')) {
65 return !isKnownSubcommand(nextArg, spec)
66 }
67 return false
68}
69
70// Find the first subcommand by skipping flags and their values
71function findFirstSubcommand(

Callers 2

findFirstSubcommandFunction · 0.85
buildPrefixFunction · 0.85

Calls 1

isKnownSubcommandFunction · 0.70

Tested by

no test coverage detected