Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion src/main/features/cli/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -79,7 +80,9 @@ export function parseArgs(argv: readonly string[], specs: Record<string, FlagSpe
continue;
}
if (raw === undefined) {
if (i >= 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 =
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/main/cli/args.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
Expand Down