Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds runtime “global options” support so a single schema can define flags available across all subcommands, including parsing them before/after subcommands, merging them into command args, and exposing them in help/usage output.
Changes:
- Add global-args typing and runtime plumbing (
GlobalArgs,GlobalArgsContext,createDefineCommand, andglobalArgsoptions forrunMain/runCommand). - Update the arg parser to scan for subcommands while skipping known global flags (including
--no-*) and to split global vs command raw args for leaf commands. - Add help output support for
[global options]in usage and a dedicated “Global Options” section; add schema extraction caching (extractFieldsCached).
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/types.ts | Introduces global-args types and adds globalArgs to runtime options types. |
| src/parser/arg-parser.ts | Implements global args scanning/splitting and uses cached schema extraction. |
| src/parser/arg-parser.test.ts | Adds tests covering global args parsing, --no-*, scanner stop conditions, and leaf splitting. |
| src/output/help-generator.ts | Adds global options rendering in usage and help sections. |
| src/output/help-generator.test.ts | Adds tests for [global options] usage and “Global Options” help section. |
| src/index.ts | Exports createDefineCommand, extractFieldsCached, and global-args types. |
| src/core/schema-extractor.ts | Adds WeakMap-based caching via extractFieldsCached; getExtractedFields uses it. |
| src/core/schema-extractor.test.ts | Tests cache behavior for extractFieldsCached. |
| src/core/runner.ts | Threads global args context through parsing/help and merges validated global args into command args. |
| src/core/run-main.test.ts | Adds integration tests for global arg merging, precedence, validation errors, and env fallback. |
| src/core/command.ts | Extends command typing to include global args and adds createDefineCommand. |
| src/core/command.test.ts | Adds type-level tests for global args via factory, explicit type parameter, and declaration merging. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 16 out of 16 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- resolve unknownKeysMode from both command/global extracted schemas - remove unnecessary as any casts in run-main tests - update createDefineCommand API reference signature text
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 22 out of 22 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const withoutDashes = token.slice(2); | ||
|
|
||
| if (withoutDashes.startsWith("no-")) { | ||
| continue; |
There was a problem hiding this comment.
In findPotentialSubcommandOnHelp(), any --no-* token is currently treated as a flag and skipped unconditionally. This can mis-detect the next token as a subcommand when the user passes --no-<non-boolean> (or an unknown --no-*) with a value (e.g. --no-config app.toml --help), reintroducing the “option value treated as subcommand” issue on help paths. Treat --no-* as boolean negation only when <name> is a known boolean long flag; otherwise handle it like a normal long option (including consuming the next value when appropriate).
| continue; | |
| const negatedName = withoutDashes.slice(3); | |
| const negatedInfo = longFlags.get(negatedName); | |
| if (negatedInfo && negatedInfo.boolean) { | |
| // Known boolean long flag negation (e.g. --no-verbose); no value to consume. | |
| continue; | |
| } |
Summary
globalArgssupport torunMain/runCommand--no-*boolean negationcreateDefineCommandand global-args type plumbing (GlobalArgs,GlobalArgsContext,MergedArgs)[global options]in usage andGlobal Options:in help outputoverrideBuiltinAliasfor-h/-Hin subcommand detection and help outputcreateDefineCommandinternals while preserving typingas anyin run-main global options testscreateDefineCommandreturn typeShared options: [Global Options](...)links from subcommand docsCloses #154
Code Metrics Report
Details
Code coverage of files in pull request scope (85.4% → 86.8%)
Reported by octocov