Skip to content

refactor(cli): strict parseArgs, unified --json contract, mailbox/body/date fixes, and updated docs - #21

Merged
willtmc merged 1 commit into
mainfrom
refactor/cli-ergonomics-strict-args-json-docs
Nov 25, 2026
Merged

willtmc merged 1 commit into
mainfrom
refactor/cli-ergonomics-strict-args-json-docs

Conversation

@willtmc

@willtmc willtmc commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Summary

  • Strict parseArgs & safe global flag handling (src/cli.ts):
    • Removed global args.includes("-h") / args.includes("--help") and global consumeJsonFlag scanning so flags inside option values (e.g., --subject "foo --json", --body=-h, or --body "-h") never hijack help or JSON mode.
    • Added --version / -v (reading version from package.json, with --json support).
    • Routed usage errors (usage(1)) to stderr while keeping explicit --help / -h on stdout.
    • Converted accounts, thread, drafts list|get|delete|send, and url to strict parseArgs, rejecting unknown options like --bogus cleanly.
    • Extracted shared parseComposeArgs for drafts create and send: rejects passing both --body and --body-file, and names the exact missing required option (--to, --subject, --body or --body-file).
    • Validated search --max as a positive integer via shared parsePositiveIntOption.
  • Unified --json contract & honest exit codes (src/cli.ts, src/json-format.ts):
    • Added --json output across all remaining commands (accounts list|add|remove|credentials, labels <threadIds>, drafts get --download, drafts create, drafts delete, drafts send, send) while preserving existing JSON shapes on search, thread, labels list, drafts list, drafts get, drafts audit, and url.
    • labels <threadIds> now exits 1 when neither --add nor --remove is provided or when any thread modification fails (stderr in text mode; structured results/errors in --json mode).
    • accounts remove <email> now exits 1 when the account is not found.
    • Removed redundant .filter((id) => id !== "--json") in handleUrl.
  • Output, date, body, size & mailbox fixes (src/cli.ts, src/json-format.ts):
    • search uses the latest message in each thread for sender/date, unions labelIds across all messages in the thread, guards malformed Date headers against RangeError, and sanitizes \r/\n/\t in TSV columns.
    • thread prints Gmail-Message-ID: separately from RFC 822 Message-ID: and includes Cc: when present; deduplicated getHeader closures into one shared helper.
    • decodeBody skips named attachments and non-text/* parts so inline binary attachments are never dumped as message text.
    • formatSize clamps unit indexing so >= 1 TB never formats as undefined.
    • parseMailboxList respects quoted display-name commas (e.g. "McLemore, Will" <will@mclemoreauction.com>, jane@example.com).
  • Docs & tests (README.md, CHANGELOG.md, test/cli-ergonomics.test.js):

Verification

  • npm ci --no-audit --no-fund — passed
  • npm run lint (biome check src/) — passed (7 files, 0 errors)
  • npm run typecheck (tsc --noEmit) — passed
  • npm run build — passed
  • npm test — 50/50 tests passing

@willtmc
willtmc merged commit 79eebb0 into main Nov 25, 2026
1 check passed
@willtmc
willtmc deleted the refactor/cli-ergonomics-strict-args-json-docs branch November 25, 2026 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant