Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix quotes for brimcap cli args #1598

Merged
merged 2 commits into from
May 1, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 9 additions & 16 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,14 +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)
}
}