Skip to content

Commit

Permalink
try spawnSync
Browse files Browse the repository at this point in the history
Signed-off-by: Mason Fish <mason@looky.cloud>
  • Loading branch information
Mason Fish committed Apr 30, 2021
1 parent 1cb01d3 commit 0fca927
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
Binary file removed itest/testdata/sample.pcap
Binary file not shown.
28 changes: 9 additions & 19 deletions plugins/brimcap/brimcap-cli.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {execSync, spawn, ChildProcess} from "child_process"
import {spawnSync, spawn, ChildProcess} from "child_process"
import flatMap from "lodash/flatMap"

interface packetOptions {
Expand Down Expand Up @@ -42,17 +42,16 @@ const OPTION_NAME_MAP = {
srcPort: "src.port"
}

const toCliOpts = (opts: loadOptions | searchOptions): string[] =>
flatMap(
Object.entries(opts).map(([k, v]) => [`-${OPTION_NAME_MAP[k] || k}`, v])
)

export default class BrimcapCLI {
constructor(private binPath: string) {}

public load(pcapPath: string, opts: loadOptions): ChildProcess {
const subCommandWithArgs = [
"load",
...flatMap(
Object.entries(opts).map(([k, v]) => [`-${OPTION_NAME_MAP[k] || k}`, v])
),
pcapPath
]
const subCommandWithArgs = ["load", ...toCliOpts(opts), pcapPath]

return spawn(this.binPath, subCommandWithArgs)
}
Expand All @@ -62,17 +61,8 @@ export default class BrimcapCLI {
}

private exec(subCommand: string, opts: searchOptions) {
const commandWithArgs = [
`"${this.binPath}"`,
subCommand,
...flatMap(
Object.entries(opts).map(([k, v]) => [
`-${OPTION_NAME_MAP[k] || k}`,
`"${v}"`
])
)
].join(" ")
const subCommandWithArgs = [subCommand, ...toCliOpts(opts)]

return execSync(commandWithArgs)
return spawnSync(this.binPath, subCommandWithArgs)
}
}

0 comments on commit 0fca927

Please sign in to comment.