MCPcopy Create free account
hub / github.com/Noumena-Network/code / extractCommandArguments

Function extractCommandArguments

src/utils/bash/parser.ts:207–240  ·  view source on GitHub ↗
(commandNode: Node)

Source from the content-addressed store, hash-verified

205}
206
207export function extractCommandArguments(commandNode: Node): string[] {
208 // Declaration commands
209 if (commandNode.type === 'declaration_command') {
210 const firstChild = commandNode.children[0]
211 return firstChild && DECLARATION_COMMANDS.has(firstChild.text)
212 ? [firstChild.text]
213 : []
214 }
215
216 const args: string[] = []
217 let foundCommandName = false
218
219 for (const child of commandNode.children) {
220 if (child.type === 'variable_assignment') continue
221
222 // Command name
223 if (
224 child.type === 'command_name' ||
225 (!foundCommandName && child.type === 'word')
226 ) {
227 foundCommandName = true
228 args.push(child.text)
229 continue
230 }
231
232 // Arguments
233 if (ARGUMENT_TYPES.has(child.type)) {
234 args.push(stripQuotes(child.text))
235 } else if (SUBSTITUTION_TYPES.has(child.type)) {
236 break
237 }
238 }
239 return args
240}
241
242function stripQuotes(text: string): string {
243 return text.length >= 2 &&

Callers 2

parser.test.tsFile · 0.85
getCommandPrefixStaticFunction · 0.85

Calls 2

stripQuotesFunction · 0.85
hasMethod · 0.45

Tested by

no test coverage detected