diff --git a/src/main/features/cli/args.ts b/src/main/features/cli/args.ts index c9721b974..3719920df 100644 --- a/src/main/features/cli/args.ts +++ b/src/main/features/cli/args.ts @@ -3,6 +3,7 @@ * * `--name value`, `--name=value` and bare `--name` (true) are flags; `-h` is * `--help`; `--` ends the flags. Everything else is positional, in order. + * A value that starts with `--` is given as `--name=--value`. * Which flags take a value is the command's to say, so a bare flag followed * by a word is told apart by the spec. */ @@ -79,7 +80,9 @@ export function parseArgs(argv: readonly string[], specs: Record= argv.length) { + // A flag where the value should be is a value gone missing, not the + // value: PowerShell 5.1 drops `--name ''`, leaving `--name --json`. + if (i >= argv.length || (argv[i] as string).startsWith("--")) { // `--since #3`: the shell took "#3" for a comment. `--command ""`: // PowerShell 5.1 passes no empty argument. const hint = diff --git a/tests/unit/main/cli/args.test.ts b/tests/unit/main/cli/args.test.ts index 120cd6ad6..6b72673f6 100644 --- a/tests/unit/main/cli/args.test.ts +++ b/tests/unit/main/cli/args.test.ts @@ -36,6 +36,11 @@ test.each([ ["--workspace"], "--workspace needs a value (an empty one: --workspace=, which every shell passes)", ], + // ...so `--workspace '' --json` reaches us as `--workspace --json`. + [ + ["--workspace", "--json"], + "--workspace needs a value (an empty one: --workspace=, which every shell passes)", + ], ])("%j is refused", (argv, message) => { expect(() => parseArgs(argv, SPECS)).toThrow(new CliUsageError(message)); });