( command: string, )
| 164 | * invocation, path-like name, bare subcommand-aware command). |
| 165 | */ |
| 166 | export 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. |
nothing calls this directly
no test coverage detected