Skip to content

fix(cli): make sentry cli --version print the version#1128

Merged
BYK merged 2 commits into
mainfrom
byk/fix/cli-version-flag
Jun 23, 2026
Merged

fix(cli): make sentry cli --version print the version#1128
BYK merged 2 commits into
mainfrom
byk/fix/cli-version-flag

Conversation

@BYK

@BYK BYK commented Jun 23, 2026

Copy link
Copy Markdown
Member

Problem

Reported by sergical in #discuss-cli: sentry cli --version errors with
No command registered for \--version`, even though sentry --version` works.

Stricli only handles --version at the application proxy, so it never reaches
route maps. The behavior was inconsistent across the tree:

Command Before
sentry --version 0.0.0-dev
sentry cli --version No command registered for \--version`` ❌
sentry issue --version No flag registered for --version

Fix

preprocessArgv() (in argv-hoist.ts) now normalizes a top-level --version token —
appearing after any route group/subcommand, before any -- escape — to a plain
["--version"], so the app-level version handler prints it. After the fix, sentry cli --version, sentry issue --version, and sentry issue list --version all print
the version, consistent with sentry --version.

Notes:

  • -v is intentionally left alone — it's the reserved short alias for --verbose
    (GLOBAL_FLAGS). Only the long --version form is normalized. (BYK's guidance in the
    thread was specifically about sentry cli --version.)
  • Tokens after a -- escape are ignored, so sentry monitor run <slug> -- tool --version
    still forwards --version to the wrapped command.
  • --version=value is not matched (no command defines a --version value flag).
  • Extracted preprocessArgv (version-normalize + existing global-flag hoist) so runCli
    stays under the cognitive-complexity budget.

Out of scope: aliasing sentry upgrade → CLI upgrade. Per BYK in-thread, sentry upgrade is reserved for SDK upgrade flows and must not be remapped.

Tests

Unit tests added for isVersionRequest and preprocessArgv (route-scoped --version,
nested subcommand, -v non-match, post--- escape, --version=foo non-match). Verified
in dev: sentry cli --version0.0.0-dev; sentry cli -v unchanged. typecheck + lint clean.

Stricli only handles `--version` at the application proxy, so `sentry
--version` worked but `sentry cli --version` failed route resolution
("No command registered for `--version`"), and `sentry issue --version`
errored with "No flag registered". Reported in #discuss-cli.

preprocessArgv() now normalizes a top-level `--version` token (appearing
after any route group/subcommand, before any `--` escape) to a plain
`["--version"]` so the app-level handler prints it consistently. `-v` is
left untouched — it is the reserved short alias for `--verbose`. Tokens
after `--` are ignored so `sentry monitor run <slug> -- tool --version`
still forwards `--version` to the wrapped command.

Extracted preprocessArgv (version-normalize + global-flag hoist) to keep
runCli under the cognitive-complexity budget. Adds unit tests for
isVersionRequest and preprocessArgv.
@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1

QR code for preview link

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

Built to branch gh-pages at 2026-06-23 16:22 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Codecov Results 📊

✅ Patch coverage is 81.82%. Project has 5052 uncovered lines.
✅ Project coverage is 81.34%. Comparing base (base) to head (head).

Files with missing lines (1)
File Patch % Lines
src/cli.ts 0.00% ⚠️ 2 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    81.33%    81.34%    +0.01%
==========================================
  Files          392       392         —
  Lines        27061     27070        +9
  Branches     17558     17564        +6
==========================================
+ Hits         22009     22018        +9
- Misses        5052      5052         —
- Partials      1832      1832         —

Generated by Codecov Action

Adversarial-review NIT: document that the naive token scan in
isVersionRequest treats a bare `--version` as a version request even when
it would otherwise be a value flag's argument (e.g. `issue list -q
--version`); the `=` form passes the literal string. No behavior change.
@BYK BYK merged commit 30a0190 into main Jun 23, 2026
29 checks passed
@BYK BYK deleted the byk/fix/cli-version-flag branch June 23, 2026 16:31
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