Open
Conversation
Permissive argv scanner that extracts known global flags and passes unknown flags + positionals through to rest. Reuses all existing Parser internals (createOptionNames, normalizeOptionName, coerce, etc).
Adds globals as a third generic on Handler, Context, and middleware() factory following the existing InferVars/InferEnv pattern. Wires globals into execute.Options and mwCtx construction.
Extends globalOptionsLines, formatRoot, and formatCommand to accept an optional globals schema. Custom globals render as a separate block above the built-in global options using the existing optionEntries helper.
Extends complete() to accept an optional globals descriptor. Global flags are suggested alongside command-specific options with dedup. Value resolution falls through from command options to globals.
Adds globals as 4th generic on Cli type, all create() overloads, and create.Options. Stores globals config in WeakMap. Validates against builtin flag collisions at create() and command option collisions at command(). Extracts globals via Parser.parseGlobals after builtin extraction in serveImpl. Passes globals to middleware context, Help output, Completions, --llms manifests, and --schema output.
13 integration tests (middleware flow, aliases, defaults, routing, help, --llms, --schema, conflicts, negation, position flexibility), 2 type-level tests (generic flow, alias constraint), and 8 parser unit tests for parseGlobals.
- Stop unknown flags from greedily eating the next token as a value
- Add -- separator handling in parseGlobals
- Wrap parseGlobals in try/catch for clean error envelopes
- Validate globalAlias values against reserved short flags (-h)
- Check command alias collisions with global aliases
- Include --no-{config} negation in builtin collision list
- Add globals to fetch gateway middleware context
- Delete redundant "stripped from argv" and "work with subcommands" tests - Update validation error test to match new try/catch behavior - Use toKebab import instead of inline regex in Completions.ts
Define GlobalsDescriptor once in Cli.ts, replace 6 inline repetitions across Cli.ts, Help.ts, and Completions.ts.
commit: |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #98 +/- ##
=======================================
Coverage ? 92.68%
=======================================
Files ? 23
Lines ? 2899
Branches ? 1153
=======================================
Hits ? 2687
Misses ? 176
Partials ? 36 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- Add undefined to GlobalsDescriptor.alias for exactOptionalPropertyTypes - Restructure globalAlias type test to avoid tsc -b @ts-expect-error quirk
- 5 completions tests (global flags, aliases, dedup, enum values, booleans) - 7 parser tests (-- separator, stacked shorts, count, array, unknown --no-*, unknown --flag=value, missing value error) - 3 cli tests (parseGlobals error envelope, -h alias conflict, command alias conflict) - 2 help tests (deprecated globals rendering, globals with defaults in formatRoot)
- 6 parser tests (stacked short count/non-boolean/value-taking, short missing value, known --no- negation, known --flag=value with array) - 1 cli test (agent-mode error formatting for globals validation)
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
globalsandglobalAliasoptions toCli.create()for defining CLI-wide flags (e.g.--rpc-url,--chain,--profile)Parser.parseGlobals()c.globalswith full type inference--help,--llms,--schema, and shell completionscreate()time (vs builtins and reserved aliases) andcommand()time (vs command options and aliases)API
Test plan
parseGlobalstsc -bclean