Skip to content

armgit / Pake

Public Imported from GitHub
0

Turn any website into a lightweight desktop app with one command, on macOS, Windows and Linux.

fix: name quoting in the excess-arguments hint

Tw93f5496992409e
diff --git a/bin/cli.ts b/bin/cli.ts
index 685d62cf..09050a1e 100644
--- a/bin/cli.ts
+++ b/bin/cli.ts
@@ -241,6 +241,15 @@ program.parseAsync().catch((error: unknown) => {
// Parse errors (unknown option, invalid argument, missing value) are
// invalid input. Commander already printed the message to stderr; in
// json mode also emit the machine-readable result on stdout.
+ //
+ // Excess operands are almost always an unquoted value: `--name Google
+ // Translate` leaves `Translate` as a second operand, and commander's
+ // "too many arguments" names neither --name nor quoting, so the shape
+ // reads as "names with spaces are unsupported" (#1378).
+ const excessArguments = error.code === 'commander.excessArguments';
+ const hint = excessArguments
+ ? 'A value containing spaces must be quoted, for example --name "Google Translate".'
+ : 'Run pake --help for the accepted options.';
if (process.argv.includes('--json')) {
printJsonResult({
ok: false,
@@ -252,9 +261,13 @@ program.parseAsync().catch((error: unknown) => {
error: {
code: 'INVALID_INPUT',
message: error.message.trim(),
- hint: 'Run pake --help for the accepted options.',
+ hint,
},
});
+ } else if (excessArguments) {
+ // Commander has already written its message and the full help, so this
+ // lands last, which is where the eye goes after a wall of help text.
+ console.error(chalk.red(`\u2715 ${hint}`));
}
process.exitCode = ERROR_EXIT_CODES.INVALID_INPUT;
return;
diff --git a/dist/cli.js b/dist/cli.js
index 5b329495..8b24bf85 100644
--- a/dist/cli.js
+++ b/dist/cli.js
@@ -4073,6 +4073,15 @@ program.parseAsync().catch((error) => {
// Parse errors (unknown option, invalid argument, missing value) are
// invalid input. Commander already printed the message to stderr; in
// json mode also emit the machine-readable result on stdout.
+ //
+ // Excess operands are almost always an unquoted value: `--name Google
+ // Translate` leaves `Translate` as a second operand, and commander's
+ // "too many arguments" names neither --name nor quoting, so the shape
+ // reads as "names with spaces are unsupported" (#1378).
+ const excessArguments = error.code === 'commander.excessArguments';
+ const hint = excessArguments
+ ? 'A value containing spaces must be quoted, for example --name "Google Translate".'
+ : 'Run pake --help for the accepted options.';
if (process.argv.includes('--json')) {
printJsonResult({
ok: false,
@@ -4084,10 +4093,15 @@ program.parseAsync().catch((error) => {
error: {
code: 'INVALID_INPUT',
message: error.message.trim(),
- hint: 'Run pake --help for the accepted options.',
+ hint,
},
});
}
+ else if (excessArguments) {
+ // Commander has already written its message and the full help, so this
+ // lands last, which is where the eye goes after a wall of help text.
+ console.error(chalk.red(`\u2715 ${hint}`));
+ }
process.exitCode = ERROR_EXIT_CODES.INVALID_INPUT;
return;
}
diff --git a/tests/index.js b/tests/index.js
index 06070227..0207db4c 100644
--- a/tests/index.js
+++ b/tests/index.js
@@ -282,6 +282,28 @@ class PakeTestRunner {
}),
);
+ // An unquoted value leaves extra operands; the hint must name quoting
+ // rather than commander's generic "too many arguments" (#1378).
+ await this.runTest("Unquoted Value Hint", () => {
+ const result = spawnSync(
+ process.execPath,
+ [
+ config.CLI_PATH,
+ "https://example.com",
+ "--name",
+ "Google",
+ "Translate",
+ "--json",
+ ],
+ { encoding: "utf8", timeout: TIMEOUTS.QUICK },
+ );
+ if (result.error || result.status !== 2) return false;
+ const error = JSON.parse(result.stdout).error;
+ return (
+ error?.code === "INVALID_INPUT" && /must be quoted/.test(error.hint)
+ );
+ });
+
// Number validation test
await this.runTest("Number Validation", () => {
try {