Skip to content

Commit d958763

Browse files
committed
feat: alias bargs.create to bargs (or vice-versa)
`bargs()` instead of `bargs.create()` is preferred; `bargs.create()` is soft-deprecated
1 parent 1e2b30e commit d958763

File tree

10 files changed

+146
-174
lines changed

10 files changed

+146
-174
lines changed

README.md

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ A CLI with an optional command and a couple options:
2727
```typescript
2828
import { bargs, opt, pos } from '@boneskull/bargs';
2929

30-
await bargs
31-
.create('greet', { version: '1.0.0' })
30+
await bargs('greet', { version: '1.0.0' })
3231
.globals(
3332
opt.options({
3433
name: opt.string({ default: 'world' }),
@@ -112,11 +111,10 @@ const parser = pos.positionals(pos.variadic('string', { name: 'text' }))(
112111
}),
113112
);
114113

115-
const { values, positionals } = await bargs
116-
.create('echo', {
117-
description: 'Echo text to stdout',
118-
version: '1.0.0',
119-
})
114+
const { values, positionals } = await bargs('echo', {
115+
description: 'Echo text to stdout',
116+
version: '1.0.0',
117+
})
120118
.globals(parser)
121119
.parseAsync();
122120

@@ -132,11 +130,10 @@ For a CLI with multiple subcommands:
132130
```typescript
133131
import { bargs, merge, opt, pos } from '@boneskull/bargs';
134132

135-
await bargs
136-
.create('tasks', {
137-
description: 'A task manager',
138-
version: '1.0.0',
139-
})
133+
await bargs('tasks', {
134+
description: 'A task manager',
135+
version: '1.0.0',
136+
})
140137
.globals(
141138
opt.options({
142139
verbose: opt.boolean({ aliases: ['v'], default: false }),
@@ -189,8 +186,7 @@ Commands can be nested to arbitrary depth by passing a `CliBuilder` as the secon
189186
import { bargs, opt, pos } from '@boneskull/bargs';
190187

191188
// Define subcommands as a separate builder
192-
const remoteCommands = bargs
193-
.create('remote')
189+
const remoteCommands = bargs('remote')
194190
.command(
195191
'add',
196192
pos.positionals(
@@ -208,8 +204,7 @@ const remoteCommands = bargs
208204
.defaultCommand('add');
209205

210206
// Nest under parent CLI
211-
await bargs
212-
.create('git')
207+
await bargs('git')
213208
.globals(opt.options({ verbose: opt.boolean({ aliases: ['v'] }) }))
214209
.command('remote', remoteCommands, 'Manage remotes') // ← CliBuilder
215210
.command('commit', commitParser, commitHandler) // ← Regular command
@@ -227,7 +222,7 @@ Parent globals automatically flow to nested command handlers. You can nest as de
227222

228223
## API
229224

230-
### bargs.create(name, options?)
225+
### bargs(name, options?)
231226

232227
Create a CLI builder.
233228

@@ -243,7 +238,7 @@ Create a CLI builder.
243238
Set global options and transforms that apply to all commands.
244239

245240
```typescript
246-
bargs.create('my-cli').globals(opt.options({ verbose: opt.boolean() }));
241+
bargs('my-cli').globals(opt.options({ verbose: opt.boolean() }));
247242
// ...
248243
```
249244

@@ -268,9 +263,9 @@ Register a command. The handler receives merged global + command types.
268263
Register a nested command group. The `cliBuilder` is another `CliBuilder` whose commands become subcommands. Parent globals are passed down to nested handlers.
269264

270265
```typescript
271-
const subCommands = bargs.create('sub').command('foo', ...).command('bar', ...);
266+
const subCommands = bargs('sub').command('foo', ...).command('bar', ...);
272267

273-
bargs.create('main')
268+
bargs('main')
274269
.command('nested', subCommands, 'Nested commands') // nested group
275270
.parseAsync();
276271

@@ -304,11 +299,11 @@ Parse arguments and execute handlers.
304299

305300
```typescript
306301
// Async (supports async transforms/handlers)
307-
const result = await bargs.create('my-cli').globals(...).parseAsync();
302+
const result = await bargs('my-cli').globals(...).parseAsync();
308303
console.log(result.values, result.positionals, result.command);
309304

310305
// Sync (no async transforms/handlers)
311-
const result = bargs.create('my-cli').globals(...).parse();
306+
const result = bargs('my-cli').globals(...).parse();
312307
```
313308

314309
## Option Helpers
@@ -469,8 +464,7 @@ const globals = map(
469464
}),
470465
);
471466

472-
await bargs
473-
.create('my-cli')
467+
await bargs('my-cli')
474468
.globals(globals)
475469
.command(
476470
'info',
@@ -513,8 +507,7 @@ If you prefer camelCase property names instead of kebab-case, use the `camelCase
513507
```typescript
514508
import { bargs, map, opt, camelCaseValues } from '@boneskull/bargs';
515509

516-
const { values } = await bargs
517-
.create('my-cli')
510+
const { values } = await bargs('my-cli')
518511
.globals(
519512
map(
520513
opt.options({
@@ -542,12 +535,12 @@ By default, **bargs** displays your package's homepage and repository URLs (from
542535

543536
```typescript
544537
// Custom epilog
545-
bargs.create('my-cli', {
538+
bargs('my-cli', {
546539
epilog: 'For more info, visit https://example.com',
547540
});
548541

549542
// Disable epilog entirely
550-
bargs.create('my-cli', { epilog: false });
543+
bargs('my-cli', { epilog: false });
551544
```
552545

553546
## Theming
@@ -556,18 +549,18 @@ Customize help output colors with built-in themes or your own:
556549

557550
```typescript
558551
// Use a built-in theme: 'default', 'mono', 'ocean', 'warm'
559-
bargs.create('my-cli', { theme: 'ocean' });
552+
bargs('my-cli', { theme: 'ocean' });
560553

561554
// Disable colors entirely
562-
bargs.create('my-cli', { theme: 'mono' });
555+
bargs('my-cli', { theme: 'mono' });
563556
```
564557

565558
The `ansi` export provides common ANSI escape codes for styled terminal output:
566559

567560
```typescript
568561
import { ansi } from '@boneskull/bargs';
569562

570-
bargs.create('my-cli', {
563+
bargs('my-cli', {
571564
theme: {
572565
command: ansi.bold,
573566
flag: ansi.brightCyan,
@@ -613,7 +606,7 @@ import {
613606
} from '@boneskull/bargs';
614607

615608
try {
616-
await bargs.create('my-cli').parseAsync();
609+
await bargs('my-cli').parseAsync();
617610
} catch (error) {
618611
if (error instanceof ValidationError) {
619612
// Config validation failed (e.g., invalid schema)

examples/greeter.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,10 @@ const greetPositionals = pos.positionals(
4545

4646
// Build and run the CLI
4747
// Using the (Parser, handler) form for full type inference of merged globals
48-
await bargs
49-
.create('greeter', {
50-
description: 'A friendly greeter CLI',
51-
version: '1.0.0',
52-
})
48+
await bargs('greeter', {
49+
description: 'A friendly greeter CLI',
50+
version: '1.0.0',
51+
})
5352
.globals(globalOptions)
5453
// The (Parser, handler, description) form gives us merged global + command types!
5554
.command(

examples/nested-commands.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ const config: Map<string, string> = new Map([
3535
// ═══════════════════════════════════════════════════════════════════════════════
3636

3737
// "remote" command group with subcommands: add, remove, list
38-
const remoteCommands = bargs
39-
.create('remote')
38+
const remoteCommands = bargs('remote')
4039
.command(
4140
'add',
4241
pos.positionals(
@@ -96,8 +95,7 @@ const remoteCommands = bargs
9695
.defaultCommand('list');
9796

9897
// "config" command group with subcommands: get, set
99-
const configCommands = bargs
100-
.create('config')
98+
const configCommands = bargs('config')
10199
.command(
102100
'get',
103101
pos.positionals(pos.string({ name: 'key', required: true })),
@@ -137,11 +135,10 @@ const globals = opt.options({
137135
verbose: opt.boolean({ aliases: ['v'], default: false }),
138136
});
139137

140-
await bargs
141-
.create('git-like', {
142-
description: 'A git-like CLI demonstrating nested commands',
143-
version: '1.0.0',
144-
})
138+
await bargs('git-like', {
139+
description: 'A git-like CLI demonstrating nested commands',
140+
version: '1.0.0',
141+
})
145142
.globals(globals)
146143
// Register nested command groups
147144
.command('remote', remoteCommands, 'Manage remotes')

examples/tasks.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,10 @@ const doneParser = pos.positionals(pos.string({ name: 'id', required: true }));
7171
// Using (Parser, handler, description) form for full type inference!
7272
// ═══════════════════════════════════════════════════════════════════════════════
7373

74-
await bargs
75-
.create('tasks', {
76-
description: 'A simple task manager',
77-
version: '1.0.0',
78-
})
74+
await bargs('tasks', {
75+
description: 'A simple task manager',
76+
version: '1.0.0',
77+
})
7978
.globals(globalOptions)
8079
// The handler receives merged global + command types
8180
.command(

examples/transforms.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,10 @@ const infoParser = opt.options({});
9797
// Using (Parser, handler, description) form for full type inference!
9898
// ═══════════════════════════════════════════════════════════════════════════════
9999

100-
await bargs
101-
.create('transforms-demo', {
102-
description: 'Demonstrates transforms with commands',
103-
version: '1.0.0',
104-
})
100+
await bargs('transforms-demo', {
101+
description: 'Demonstrates transforms with commands',
102+
version: '1.0.0',
103+
})
105104
.globals(globals)
106105
// The handler receives merged global + command types
107106
.command(

src/bargs.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/**
22
* Core bargs API using parser combinator pattern.
33
*
4-
* Provides `bargs.create()` for building CLIs with a fluent API, plus
5-
* combinator functions like `pipe()`, `map()`, and `handle()`.
4+
* Provides `bargs()` for building CLIs with a fluent API, plus combinator
5+
* functions like `pipe()`, `map()`, and `handle()`.
66
*
77
* @packageDocumentation
88
*/
@@ -362,8 +362,7 @@ const kebabToCamel = (s: string): string =>
362362
* ```typescript
363363
* import { bargs, opt, map, camelCaseValues } from '@boneskull/bargs';
364364
*
365-
* const { values } = await bargs
366-
* .create('my-cli')
365+
* const { values } = await bargs('my-cli')
367366
* .globals(
368367
* map(opt.options({ 'output-dir': opt.string() }), camelCaseValues),
369368
* )
@@ -396,8 +395,7 @@ export const camelCaseValues = <V, P extends readonly unknown[]>(
396395
* @example
397396
*
398397
* ```typescript
399-
* const cli = await bargs
400-
* .create('my-app', { version: '1.0.0' })
398+
* const cli = await bargs('my-app', { version: '1.0.0' })
401399
* .globals(
402400
* map(opt.options({ verbose: opt.boolean() }), ({ values }) => ({
403401
* values: { ...values, ts: Date.now() },
@@ -414,7 +412,7 @@ export const camelCaseValues = <V, P extends readonly unknown[]>(
414412
*
415413
* @function
416414
*/
417-
const create = (
415+
export const bargs = (
418416
name: string,
419417
options: CreateOptions = {},
420418
): CliBuilder<Record<string, never>, readonly []> => {
@@ -1110,8 +1108,7 @@ const runWithCommands = (
11101108
};
11111109

11121110
/**
1113-
* Main bargs namespace.
1111+
* @ignore
1112+
* @deprecated
11141113
*/
1115-
export const bargs = {
1116-
create,
1117-
};
1114+
bargs.create = bargs;

src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
* ```typescript
99
* import { bargs, opt, pos } from '@boneskull/bargs';
1010
*
11-
* await bargs
12-
* .create('my-app', { version: '1.0.0' })
11+
* await bargs('my-app', { version: '1.0.0' })
1312
* .globals(opt.options({ verbose: opt.boolean({ aliases: ['v'] }) }))
1413
* .command(
1514
* 'greet',

src/theme.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import { stripVTControlCharacters } from 'node:util';
1313

1414
/**
1515
* Strip all ANSI escape codes from a string.
16+
*
17+
* @function
1618
*/
1719
export const stripAnsi = stripVTControlCharacters;
1820

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ export interface CountOption extends OptionBase {
204204
}
205205

206206
/**
207-
* Options for bargs.create().
207+
* Options for bargs().
208208
*/
209209
export interface CreateOptions {
210210
/** Description shown in help */

0 commit comments

Comments
 (0)