feat(cli): hoist global flags from any argv position and add -v alias#709
Draft
feat(cli): hoist global flags from any argv position and add -v alias#709
Conversation
Contributor
Semver Impact of This PR🟡 Minor (new features) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨Docs
Other
Bug Fixes 🐛Dashboard
Other
Internal Changes 🔧
🤖 This preview updates automatically when you update the PR. |
Contributor
|
Contributor
Codecov Results 📊✅ 134 passed | Total: 134 | Pass Rate: 100% | Execution Time: 0ms 📊 Comparison with Base Branch
✨ No test changes detected All tests are passing successfully. ✅ Patch coverage is 100.00%. Project has 1573 uncovered lines. 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.
fca1b1b to
a3181cf
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
--verbose,-v,--json,--log-level,--fields) from any position to the end of argv before Stricli processes it-vas a short alias for--verboseon all leaf commandssentry --verbose issue list,sentry cli -v upgrade, etc.Problem
Stricli only parses flags at the leaf command level. Global flags injected by
buildCommandfail when placed before subcommands:sentry cli upgrade --verbose✅ workedsentry cli --verbose upgrade❌ Stricli can't route past the flagsentry --verbose cli upgrade❌ samesentry cli upgrade -v❌ no short alias existedApproach
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=valueand--no-flagforms, and preserves relative order of all tokens.src/lib/command.ts— Injectsv: "verbose"alias following the existingbuildDeleteCommandpattern. Skipped when command owns--verboseorvis already taken.src/cli.ts— CallshoistGlobalFlags()insiderunCli(). OriginalcliArgspreserved for help-as-positional recovery (cliArgs.at(-1) === "help"); hoisted args passed to executor.Tests
command.test.tspasses (81 tests total)