MCPcopy Index your code
hub / github.com/anomalyco/opencode / flatten

Function flatten

packages/core/src/cross-spawn-spawner.ts:53–77  ·  view source on GitHub ↗
(command: ChildProcess.Command)

Source from the content-addressed store, hash-verified

51}
52
53const flatten = (command: ChildProcess.Command) => {
54 const commands: Array<ChildProcess.StandardCommand> = []
55 const opts: Array<ChildProcess.PipeOptions> = []
56
57 const walk = (cmd: ChildProcess.Command): void => {
58 switch (cmd._tag) {
59 case "StandardCommand":
60 commands.push(cmd)
61 return
62 case "PipedCommand":
63 walk(cmd.left)
64 opts.push(cmd.options)
65 walk(cmd.right)
66 return
67 }
68 }
69
70 walk(command)
71 if (commands.length === 0) throw new Error("flatten produced empty commands array")
72 const [head, ...tail] = commands
73 return {
74 commands: [head, ...tail] as Arr.NonEmptyReadonlyArray<ChildProcess.StandardCommand>,
75 opts,
76 }
77}
78
79const toPlatformError = (
80 method: string,

Callers 2

toPlatformErrorFunction · 0.70

Calls 1

walkFunction · 0.70

Tested by

no test coverage detected