Skip to content

feat(cli): hoist global flags from any argv position and add -v alias#709

Draft
BYK wants to merge 1 commit intomainfrom
feat/global-flag-hoisting
Draft

feat(cli): hoist global flags from any argv position and add -v alias#709
BYK wants to merge 1 commit intomainfrom
feat/global-flag-hoisting

Conversation

@BYK
Copy link
Copy Markdown
Member

@BYK BYK commented Apr 9, 2026

Summary

  • Add argv preprocessor that moves global flags (--verbose, -v, --json, --log-level, --fields) from any position to the end of argv before Stricli processes it
  • Inject -v as a short alias for --verbose on all leaf commands
  • Allows sentry --verbose issue list, sentry cli -v upgrade, etc.

Problem

Stricli only parses flags at the leaf command level. Global flags injected by buildCommand fail when placed before subcommands:

  • sentry cli upgrade --verbose ✅ worked
  • sentry cli --verbose upgrade ❌ Stricli can't route past the flag
  • sentry --verbose cli upgrade ❌ same
  • sentry cli upgrade -v ❌ no short alias existed

Approach

src/lib/argv-hoist.ts — Pure function (zero imports, zero side effects) that scans argv left-to-right and relocates known global flags to the tail. Respects -- separator, handles --flag=value and --no-flag forms, and preserves relative order of all tokens.

src/lib/command.ts — Injects v: "verbose" alias following the existing buildDeleteCommand pattern. Skipped when command owns --verbose or v is already taken.

src/cli.ts — Calls hoistGlobalFlags() inside runCli(). Original cliArgs preserved for help-as-positional recovery (cliArgs.at(-1) === "help"); hoisted args passed to executor.

Tests

  • 22 unit tests + 5 property-based tests (token conservation, order preservation, idempotency)
  • Existing command.test.ts passes (81 tests total)

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 2026

Semver Impact of This PR

🟡 Minor (new features)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

Docs

  • Deploy main branch preview alongside PR previews by BYK in #707
  • Enable sourcemap upload, releases, and environment tracking by BYK in #705

Other

  • (cli) Hoist global flags from any argv position and add -v alias by BYK in #709
  • (commands) Add buildRouteMap wrapper with standard subcommand aliases by BYK in #690
  • (config) Support .sentryclirc config file for per-directory defaults by BYK in #693
  • (init) Add fuzzy edit replacers and edits-based apply-patchset by betegon in #698
  • (install) Add SENTRY_INIT env var to run wizard after install by betegon in #685
  • (release) Surface adoption and health metrics in list and view (Add release command group with adoption/health subcommand #463) by BYK in #680
  • (telemetry) Add agent detection tag for AI coding tools by betegon in #687

Bug Fixes 🐛

Dashboard

  • Add --layout flag to widget add for predictable placement by BYK in #700
  • Render tracemetrics widgets in dashboard view by BYK in #695

Other

  • (build) Enable sourcemap resolution for compiled binaries by BYK in #701
  • (cache) --fresh flag now updates cache with fresh response by BYK in #708
  • (init) Narrow command validation to actual shell injection vectors by betegon in #697
  • (init,feedback) Default to tracing only in feature select and attach user email to feedback by MathurAditya724 in #688
  • (setup) Handle read-only .claude directory in sandboxed environments by BYK in #702

Internal Changes 🔧

  • (docs) Gitignore generated command docs, extract fragments by BYK in #696
  • (eval) Replace OpenAI with Anthropic SDK in init-eval judge by betegon in #683
  • (init) Use markdown pipeline for spinner messages by betegon in #686
  • Regenerate skill files and command docs by github-actions[bot] in 584ec0e0

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 2026

PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://cli.sentry.dev/_preview/pr-709/

Built to branch gh-pages at 2026-04-09 20:27 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 2026

Codecov Results 📊

134 passed | Total: 134 | Pass Rate: 100% | Execution Time: 0ms

📊 Comparison with Base Branch

Metric Change
Total Tests
Passed Tests
Failed Tests
Skipped Tests

✨ No test changes detected

All tests are passing successfully.

✅ Patch coverage is 100.00%. Project has 1573 uncovered lines.
✅ Project coverage is 95.32%. Comparing base (base) to head (head).

Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    95.30%    95.32%    +0.02%
==========================================
  Files          230       232        +2
  Lines        33501     33616      +115
  Branches         0         0         —
==========================================
+ Hits         31928     32043      +115
- Misses        1573      1573         —
- Partials         0         0         —

Generated by Codecov Action

Global flags (--verbose, --json, --log-level, --fields) only worked when
placed after the leaf command because Stricli parses flags at the leaf level
only. This adds an argv preprocessor that relocates these flags from any
position to the end of argv before Stricli processes it, allowing patterns
like `sentry --verbose issue list` and `sentry cli -v upgrade`.

Also injects -v as a short alias for --verbose on all leaf commands,
following the existing buildDeleteCommand alias injection pattern.
@BYK BYK force-pushed the feat/global-flag-hoisting branch from fca1b1b to a3181cf Compare April 9, 2026 20:27
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