Repository navigation
perf(cli): Skip loading every command for --version, leading global flags, and top-level help - #1826
Open
sentry-junior[bot] wants to merge 2 commits into
Open
sentry-junior[bot] wants to merge 2 commits into
sentry-junior[bot] wants to merge 2 commits into
Conversation
routesForArgs fell back to the full application whenever the first token was a flag, so `sentry --version` and `sentry --verbose issue list` loaded every command. Read the leading tokens like the route scanner does: skip global flags (and their values), and for a bare `--version` load only the help route, since Stricli prints the version before it runs any command. Other leading flags, like `--help`, still get the full application. Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
`sentry`, `sentry help`, and `sentry --help` list every top-level command, so they loaded app.ts and with it every command module. Render that help from the full route tree at build time instead (`script/generate-root-help.ts` writes `src/generated/root-help.json` as part of `generate:docs`): the command summaries the branded help lists, and Stricli's `--help` text with and without colors. For the text top-level help, `selectApp()` loads only the `help` route and registers the precomputed copy with `setRootHelp()`. The Stricli patch now passes `ansiColor` to the `renderHelp` hook so plain `--help` can pick the matching copy. JSON help (`--json`, `--fields`, SENTRY_OUTPUT_FORMAT=json), `help <command>`, and `--help` before a route name still load the full application. A test checks the generated file against the full tree, and that both paths print the same text. Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
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.
Follow-up to #1814. That PR made a run load only the top-level route it names. But it still loaded every command when the first token was a flag, or when the run printed the top-level help, which lists every command. This PR covers those cases.
Commit 1:
--versionand leading global flags.selectApp()now reads the tokens before the route name the same way the route scanner does. It skips global flags and their values, sosentry --verbose issue listloads onlyissue. A baresentry --versionloads onlyhelp, since Stricli prints the version before it runs any command.Commit 2: top-level help.
sentry,sentry help, andsentry --helpnow print a copy rendered at build time.script/generate-root-help.tswritessrc/generated/root-help.jsonas part ofgenerate:docs. The file is gitignored and listed inensure-generated.mjs. It holds:--helptext, plain and with colorsFor these runs, the CLI loads only the
helproute and registers the copy throughsetRootHelp(). The Stricli patch now passesansiColorto therenderHelphook, so plain--helpcan pick the plain or colored copy. The graphics banner registration moved tosrc/graphics-banner.ts, so both paths register it.These still load the full application:
--json,--fields,SENTRY_OUTPUT_FORMAT=json)help <command>--helpbefore a route name, and any flag the scanner doesn't accept thereschemaandcliVerification
test/lib/app-for-args.test.ts:root-help.jsonagainst the full tree withbuildRootHelp(app, routes), so stale generated data fails the testprintCustomHelp(overview and full) and--help(plain and colored) print the same text with onlyhelploaded as with the full appselectApppicks routes for each argument casemainfor 46 argument cases with piped and TTY output: no args,help,-h/--help,help --help,--helpAll, JSON help,--versioncombinations, global flags,help issue,issue --help, and an unknown route. Output and exit codes matched for every case. They also matched underNO_COLOR,STRICLI_NO_COLOR,FORCE_AGENT_MODE,SENTRY_OUTPUT_FORMAT=json, narrow and wide terminals, and with an auth token set.tsc,pnpm run lint, andci:policy(includingcheck:patches) pass. The CLI unit suite has 13,091 passing tests. 6 fail in this sandbox; all of them are chmod/EACCES permission tests (completions, db readonly, code-scanner, file-changes, upgrade lock), unrelated to this change.Startup time (npm bundle, median of 15 runs, noisy sandbox)
sentrysentry helpsentry --helpsentry --versionsentry --verbose --versionsentry issue list --helpmainhere already includes the@sentry/apibump from #1820. The generated help text adds about 20 KB toindex.cjs.via @BYK.
--
View Session in Sentry