Skip to content

Commit

Permalink
feat: support multi-value CLI options
Browse files Browse the repository at this point in the history
  • Loading branch information
OrRosenblatt authored and antongolub committed Oct 26, 2024
1 parent 5826a74 commit 2664c66
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
12 changes: 12 additions & 0 deletions src/main/ts/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ import { Command, Option } from 'commander'

import { run } from './runner'

const parseMultipleValueArg = (
value: string,
previous: string | string[] | undefined,
) => {
if (!previous) {
return value
}

const previousArray = Array.isArray(previous) ? previous : [previous]
return previousArray.concat([value])
}

const env = process.env
const flags = new Command()
.addOption(
Expand Down
12 changes: 9 additions & 3 deletions src/main/ts/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,16 @@ export const formatFlags = (flags: TFlags, ...picklist: string[]): string[] =>
const flag = formatFlag(key)

if (checkValue(key, value, omitlist, picklist)) {
memo.push(flag)
if (!Array.isArray(value)) {
memo.push(flag)

if (value !== true) {
memo.push(value)
if (value !== true) {
memo.push(String(value))
}
} else {
value.forEach((val) => {
memo.push(flag, String(val))
})
}
}

Expand Down

0 comments on commit 2664c66

Please sign in to comment.