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

Function findCommandNode

src/utils/bash/parser.ts:156–191  ·  view source on GitHub ↗
(node: Node, parent: Node | null)

Source from the content-addressed store, hash-verified

154}
155
156function findCommandNode(node: Node, parent: Node | null): Node | null {
157 const { type, children } = node
158
159 if (COMMAND_TYPES.has(type)) return node
160
161 // Variable assignment followed by command
162 if (type === 'variable_assignment' && parent) {
163 return (
164 parent.children.find(
165 c => COMMAND_TYPES.has(c.type) && c.startIndex > node.startIndex,
166 ) ?? null
167 )
168 }
169
170 // Pipeline: recurse into first child (which may be a redirected_statement)
171 if (type === 'pipeline') {
172 for (const child of children) {
173 const result = findCommandNode(child, node)
174 if (result) return result
175 }
176 return null
177 }
178
179 // Redirected statement: find the command inside
180 if (type === 'redirected_statement') {
181 return children.find(c => COMMAND_TYPES.has(c.type)) ?? null
182 }
183
184 // Recursive search
185 for (const child of children) {
186 const result = findCommandNode(child, node)
187 if (result) return result
188 }
189
190 return null
191}
192
193function extractEnvVars(commandNode: Node | null): string[] {
194 if (!commandNode || commandNode.type !== 'command') return []

Callers 1

parseCommandFunction · 0.85

Calls 1

hasMethod · 0.45

Tested by

no test coverage detected