You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat!: remove direct CliBuilder pattern for nested commands
Remove the inferior `.command(name, CliBuilder)` overload that lacked type
inference for parent globals. The factory pattern `.command(name, factory)`
is now the only way to create nested command groups.
BREAKING CHANGE: The `.command(name, cliBuilder, options?)` overload has been
removed. Users must migrate to the factory pattern:
Before:
const sub = bargs('sub').command('foo', ...);
bargs('main').command('nested', sub, 'desc');
After:
bargs('main').command('nested', (nested) =>
nested.command('foo', ...), 'desc');
The factory pattern provides full type inference for parent globals in nested
command handlers, which the direct CliBuilder pattern could not.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
The factory function receives a `CliBuilder` that already has parent globals typed, so all nested command handlers get full type inference for merged `global + command` options.
224
-
225
-
You can also pass a pre-built `CliBuilder` directly (see [.command(name, cliBuilder)](#commandname-clibuilder-description)), but handlers won't have parent globals typed at compile time. See `examples/nested-commands.ts` for a full example.
223
+
The factory function receives a `CliBuilder` that already has parent globals typed, so all nested command handlers get full type inference for merged `global + command` options. See `examples/nested-commands.ts` for a full example.
226
224
227
225
## API
228
226
@@ -262,24 +260,9 @@ Register a command. The handler receives merged global + command types.
262
260
)
263
261
```
264
262
265
-
### .command(name, cliBuilder, description?)
266
-
267
-
Register a nested command group. The `cliBuilder` is another `CliBuilder` whose commands become subcommands. Parent globals are passed down to nested handlers at runtime, but **handlers won't have parent globals typed** at compile time.
.command('nested', subCommands, 'Nested commands') // nested group
274
-
.parseAsync();
275
-
276
-
// $ main nested foo
277
-
// $ main nested bar
278
-
```
279
-
280
263
### .command(name, factory, description?)
281
264
282
-
Register a nested command group using a factory function. **This is the recommended form** because the factory receives a builder that already has parent globals typed, giving full type inference in nested handlers.
265
+
Register a nested command group using a factory function. The factory receives a builder that already has parent globals typed, giving full type inference in nested handlers.
0 commit comments