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

Function getCommandPrefixStatic

src/utils/powershell/staticPrefix.ts:166–186  ·  view source on GitHub ↗
(
  command: string,
)

Source from the content-addressed store, hash-verified

164 * invocation, path-like name, bare subcommand-aware command).
165 */
166export async function getCommandPrefixStatic(
167 command: string,
168): Promise<{ commandPrefix: string | null } | null> {
169 const parsed = await parsePowerShellCommand(command)
170 if (!parsed.valid) {
171 return null
172 }
173
174 // Find the first actual command (CommandAst). getAllCommands iterates
175 // both statement.commands and statement.nestedCommands (for &&/||/if/for).
176 // Skip synthetic CommandExpressionAst entries (expression pipeline sources,
177 // non-PipelineAst statement placeholders).
178 const firstCommand = getAllCommands(parsed).find(
179 cmd => cmd.elementType === 'CommandAst',
180 )
181 if (!firstCommand) {
182 return { commandPrefix: null }
183 }
184
185 return { commandPrefix: await extractPrefixFromElement(firstCommand) }
186}
187
188/**
189 * Extract prefixes for all subcommands in a compound PowerShell command.

Callers

nothing calls this directly

Calls 2

extractPrefixFromElementFunction · 0.85
getAllCommandsFunction · 0.70

Tested by

no test coverage detected