From 42daf53202470c3d9373b5d4762de22d1377f77a Mon Sep 17 00:00:00 2001 From: moreih29 Date: Fri, 20 Nov 2026 02:06:47 +0900 Subject: [PATCH] fix(cli): refuse a flag where an option's value should be PowerShell 5.1 drops an empty argument, so `nexus workspace edit X --name '' --json` reached the CLI as `--name --json` and named the workspace "--json". The shared parser now treats a following `--...` token as a missing value, with the same "needs a value (an empty one: --name=, ...)" error it gives at the end of the line. A value that starts with `--` is still given as `--name=--value`. Co-Authored-By: Claude Opus 5.5 --- src/main/features/cli/args.ts | 5 ++++- tests/unit/main/cli/args.test.ts | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) 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)); });