fix(make-pdf): boolean flags no longer swallow the next positional argument

Fixes #2514. The parser treated any non-flag token after a flag as its value,
so `$P generate --toc essay.md` ate essay.md as --toc's value and failed with
"missing input" — the skill's own documented usage only worked when two
boolean flags happened to be adjacent. BOOLEAN_FLAGS enumerates the no-value
flags; value flags (--watermark, --to, --title, ...) are unchanged. main()
now runs behind import.meta.main so tests import the parser directly.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Garry Tan
2026-08-16 09:19:12 -07:00
co-authored by Claude Fable 5
parent 9df6015130
commit a118fd0c89
2 changed files with 66 additions and 3 deletions
+19 -3
View File
@@ -20,7 +20,20 @@ interface ParsedArgs {
flags: Record<string, string | boolean>;
}
function parseArgs(argv: string[]): ParsedArgs {
/**
* Flags that never take a value (#2514). The parser used to treat ANY
* following non-flag token as the flag's value, so the skill's own
* documented usage — `$P generate --cover --toc essay.md essay.pdf` — worked
* only by luck of flag adjacency, while `$P generate --toc essay.md` ate
* `essay.md` as --toc's value and failed with "missing input".
*/
export const BOOLEAN_FLAGS = new Set([
"cover", "toc", "no-chapter-breaks", "no-confidential",
"page-numbers", "no-page-numbers", "tagged", "no-tagged",
"outline", "no-outline", "quiet", "verbose", "allow-network",
]);
export function parseArgs(argv: string[]): ParsedArgs {
const args = argv.slice(2);
if (args.length === 0) {
printUsage();
@@ -37,7 +50,7 @@ function parseArgs(argv: string[]): ParsedArgs {
if (a.startsWith("--")) {
const key = a.slice(2);
const next = args[i + 1];
if (next !== undefined && !next.startsWith("--")) {
if (!BOOLEAN_FLAGS.has(key) && next !== undefined && !next.startsWith("--")) {
flags[key] = next;
i++;
} else {
@@ -272,4 +285,7 @@ async function main(): Promise<void> {
}
}
main();
// Guarded so tests can import parseArgs/BOOLEAN_FLAGS without running the CLI.
if (import.meta.main) {
main();
}