Repository navigation
Emit native Stricli commands and route maps for cf - #774
irvinebroque wants to merge 8 commits into
Conversation
commit: |
|
| mean | stddev | min | max | |
|---|---|---|---|---|
| PR | 272.8 ms | 5.0 ms | 263.7 ms | 284.7 ms |
| base | 296.2 ms | 5.1 ms | 288.8 ms | 307.2 ms |
Δ (PR vs base): ↓ -23.4 ms (-7.9%)
Measured with hyperfine on ubuntu-latest (3 warmup runs, 20 timed runs). CI numbers carry ±a few ms of runner jitter; treat small deltas as noise.
| if (negated && inline !== undefined) { | ||
| return fail(`Cannot pass a value to --${spelling}`); | ||
| } | ||
| parsedTokens.push( |
There was a problem hiding this comment.
Repeated boolean flags such as --force -f and --quiet --quiet are valid yargs invocations, but this now forwards both canonical --force tokens to Stricli, which raises --force can only be specified once. Keep only the final value for a boolean flag before invoking Stricli so repeated flags retain their previous last-value-wins behavior.
| parsedTokens.push( | |
| const token = negated | |
| ? `${flag}=false` | |
| : value === undefined | |
| ? flag | |
| : `${flag}=${value}`; | |
| for (let index = parsedTokens.length - 1; index >= 0; index--) { | |
| if ( | |
| parsedTokens[index] === flag || | |
| parsedTokens[index]?.startsWith(`${flag}=`) | |
| ) { | |
| parsedTokens.splice(index, 1); | |
| } | |
| } | |
| parsedTokens.push(token); |
| /^-[a-zA-Z]{2,}$/.test(arg) | ||
| ) { | ||
| const shortNames = arg.slice(1).split(""); | ||
| if ( |
There was a problem hiding this comment.
This requires every member of a grouped short option to be boolean. containers build defines -p as boolean and -t as its required string tag, so the yargs-compatible cf containers build -pt image ./dir is now rejected as an unknown -pt instead of expanding to -p -t image. Permit a value-taking final member after a boolean prefix.
| if ( | |
| shortNames.slice(0, -1).every( | |
| (name) => | |
| def.flags.get(names.get(name) ?? "")?.type === "boolean" | |
| ) && | |
| def.flags.has(names.get(shortNames.at(-1) ?? "") ?? "") |
| if (!previous?.startsWith("-")) { | ||
| return true; | ||
| } | ||
| const key = names.get(previous.replace(/^--?/, "")); |
There was a problem hiding this comment.
An unknown option is normally parsed as a value-bearing option by yargs. Here its following value is instead treated as the first command token, so cf --bogus value zones list fails route resolution with Unknown commands: value, zones, list rather than resolving zones list and reporting the actual unknown --bogus flag. Skip the immediate token after an unknown option while looking for the command path.
| const key = names.get(previous.replace(/^--?/, "")); | |
| return ( | |
| key !== undefined && | |
| def.flags.get(key)?.type === "boolean" && | |
| !["true", "false"].includes(token) | |
| ); |
|
Review: 3 findings. Posted 3 inline suggestion comments. |
|
LGTM! |
|
Review: 1 findings.
|
|
No new concerns since the last review. |
| mkdir "install-$side" | ||
| (cd "$side" && pnpm --filter cf build) | ||
| (cd "$side/packages/cli" && pnpm pack --pack-destination "../../../install-$side") | ||
| (cd "install-$side" && npm install --ignore-scripts --no-audit --no-fund ./*.tgz) |
|
@irvinebroque Bonk workflow was cancelled. View workflow run · To retry, trigger Bonk again. |
|
When an optional array flag has no value, |
|
Review: 1 findings. 🤖 I've done a thorough review of your PR. Migrates command definitions, parsing, completion, generated routing, and auth commands to Stricli.
|
Why switch? Three things now come from the same command definition: what
cfaccepts, what Tab suggests, and what inputs the handler can use. Customers can now complete saved profile names without logging in, and reading help no longer loads the generated code that makes API calls. This is not a smaller install or a promise that every command starts faster.For maintainers: a flag rename can fail the build instead of breaking a command.
cf auth createused to declare--scopesonce for the parser and again in the handler’s TypeScript interface. Now the handler gets its type from the flag definition. Rename the flag but leave the handler readingargv.scopes, and TypeScript catches it. Generated commands already had some type inference under yargs; the gain here is removing the duplicate declaration inauth.For customers: choose a saved profile when deploying. If your team has a profile named
production, typecf deploy --profile proand press Tab. Before, Tab offered nothing; now it suggestsproduction. The--profileflag tells Stricli where to get valid names, so you don’t have to remember the spelling or stop to runcf auth list. Pressing Tab only reads local profile names; it doesn’t log in, call Cloudflare, or start a deploy.For correctness: we prevent some mistakes, not all of them. Parsing and Tab can still agree on a wrong choice, and a correctly typed handler can still send the wrong API request. The parity checks tell us whether the tested invocations behave like yargs—not whether yargs was right. The reason to switch is that future changes are safer, not that the whole CLI is simpler or guaranteed correct.
What customers see
cf zero-trust devices list --helpcf zero-trust devices list --dry-runcf complete poand press Tabpowershellwas a valid argument.powershellfrom the command’s positional choices. Routes, aliases, flags and enum values also come from the parser. Existing bash, zsh, fish and PowerShell scripts work without reinstalling.workprofile, typecf auth activate woorcf zones list --profile woand press Tabcf auth list.work. Also works forauth create(re-authentication) andauth delete. Only local filenames are listed; no token reads, login, or API calls. If the store is unavailable, Tab stays silent.The new Tab results are intentional. Against
mainat6de4261c2, all 7,206 in-process comparisons matched the yargs result: 4,191 help paths, 2,962 generated dry runs (including 198 matching failures), and 53 other cases. On Linux, macOS, and Windows, a separate check installed both npm tarballs and matched the actual exit status and exact stdout and stderr for five commands: help, a dry run, an invalid flag, repeated--force -fon a dry run, and refusing a delete without--forcewhen stdin is piped. The saved-profile example returnedworkthrough all four shell integrations on macOS. These checks don’t exercise live API calls or interactive prompts.How much difference does it make?
Measurements from the lazy-handler and parser-backed completion revision, before the auth conversion: median wall time from launching
bin/cfto exit on one Apple Silicon Mac (Node 24.22.0; two warmups, then 20 fresh processes per build per command, alternating builds; warm filesystem, telemetry off):zero-trust devices liHelp loads less code; its timing was close. Node loaded 45 built JS modules totaling 1.83 MB for help, down from 60 totaling 2.49 MB. The completion callback was about 21 ms quicker in this sample, despite loading more JS (1.90 vs 1.36 MB); it no longer reads and walks the whole JSON catalog. These results don’t measure a cold install or the time spent waiting for Cloudflare’s API.
How it works
flowchart LR subgraph Before Y[Generated yargs builder + handler] --> P[Parse or show help] M[Separate JSON catalog] --> T[Tab] end subgraph After D[Command definition] --> H[Help] D --> S[Stricli suggestions for all four shells] D --> R[Parse and run] --> L[Import selected handler] endFor
zones list, abridged:Hand-written commands: All nine
cf authcommands now use native definitions too. Previouslyauth createdeclaredscopesas a string array in a builder and separately declaredscopes?: string[]for its handler. Now the handler type comes directly from the flag:This catches a mistyped or renamed auth input before release. It doesn’t change the login flow or make authentication faster. Profile names are suggested only where accepted: for example, a saved
defaultis valid for--profilebut not forauth activate <name>.What we take on
cfnpm package grows from 3.08 MB to 3.37 MB (+288 KB, about 9%;npm pack --dry-run, excluding separately installed dependencies). The production build goes from 274 JS modules (12.40 MB) to 3,246 (13.70 MB). Splitting handlers lets help skip execution code; npm still ships every handler.cfdoes not run both parsers.cfstill owns its help and compatibility rules. Scripts care about repeated flags, error order and destructive confirmations. Movingauthremoved its old builders and separate argument interfaces, but did not remove the shared adapter: hand-written families outsideauthstill need it. Shared parser changes must work for both styles.cf’s existing scripts lets us use the new suggestions without dropping three shells. Stricli core has no runtime dependencies; this does not make all ofcfdependency-free.