Skip to content

fix: route ask/docs/diff options past root-command flag collisions#52

Merged
Arthur742Ramos merged 1 commit into
mainfrom
arthur742ramos/cli-option-routing
Jun 11, 2026
Merged

fix: route ask/docs/diff options past root-command flag collisions#52
Arthur742Ramos merged 1 commit into
mainfrom
arthur742ramos/cli-option-routing

Conversation

@Arthur742Ramos

Copy link
Copy Markdown
Owner

Summary

Fixes a repo-wide CLI correctness bug: several subcommand options were silently ignored because their flag names collide with the root command.

Root cause

The root bootcamp command defines -b/--branch, --model, --format, --full-clone, --keep-temp, etc. Because the root has its own options + action alongside subcommands, Commander captures those flags at the root before the subcommand parses them. The affected options:

  • ask: --branch, --model
  • docs: --branch
  • diff: --format, --full-clone, --keep-temp

(bootcamp health had the same issue, fixed in #50; diff --output was already worked around.)

Fix

  • Extracted pure, tested helpers getFlagValue(args, flags) and hasFlag(args, flags) into src/utils.ts.
  • cli.ts reads the colliding options from raw argv via these helpers (the approach diff already used for --output).
  • Removed the masking default on diff --format so the argv fallback can take effect (runPullRequestDiff already defaults to markdown).

Testing

  • test/utils.test.ts — 9 new unit tests for getFlagValue / hasFlag (value + = forms, aliases, absence, repeats) — utils.ts now at 100% coverage
  • test/cli-option-routing.test.ts — in-process test that mocks the command runners, sets process.argv, and asserts ask/docs/diff receive the correct values
  • test/e2e/diff-command.e2e.test.ts — new real-CLI e2e (offline, fake GitHub API + bare repo) asserting --format html produces DIFF.html and --keep-temp retains the clone
  • Local validation: lint ✓, typecheck ✓, build ✓, full unit suite 1062 passing, coverage above thresholds, diff e2e ✓

The root command defines -b/--branch, --model, --format, --full-clone, --keep-temp, etc. Because the root has options + an action alongside subcommands, Commander captures those flags at the root before the subcommand parses them, so several subcommand options were silently ignored:

- ask: --branch, --model
- docs: --branch
- diff: --format, --full-clone, --keep-temp

Extract pure, tested getFlagValue/hasFlag helpers in src/utils.ts and read the affected options from raw argv (the approach diff already used for --output). Removed the masking default on diff --format so the fallback can take effect (runPullRequestDiff already defaults to markdown).

Tests: getFlagValue/hasFlag unit tests; an in-process cli routing test that mocks the command runners and asserts values reach them; a real-CLI diff e2e asserting --format html and --keep-temp take effect.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Arthur742Ramos Arthur742Ramos merged commit 4ed4806 into main Jun 11, 2026
13 checks passed
@Arthur742Ramos Arthur742Ramos deleted the arthur742ramos/cli-option-routing branch June 11, 2026 17:45
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.

2 participants