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
|`aliases`|`string[]`| Short (`['v']` for `-v`) or long aliases (`['verb']` for `--verb`) |
353
+
|`default`| varies | Default value (makes the option non-nullable) |
354
+
|`description`|`string`| Help text description |
355
+
|`group`|`string`| Groups options under a custom section header |
356
+
|`hidden`|`boolean`| Hide from `--help` output |
357
+
|`required`|`boolean`| Mark as required (makes the option non-nullable) |
358
+
359
+
### Aliases
360
+
361
+
Options can have both short (single-character) and long (multi-character) aliases:
362
+
363
+
```typescript
364
+
opt.options({
365
+
verbose: opt.boolean({ aliases: ['v', 'verb'] }),
366
+
output: opt.string({ aliases: ['o', 'out'] }),
367
+
});
368
+
```
369
+
370
+
All of these are equivalent:
371
+
372
+
```shell
373
+
$ my-cli -v # verbose: true
374
+
$ my-cli --verb # verbose: true
375
+
$ my-cli --verbose # verbose: true
376
+
$ my-cli -o file.txt # output: "file.txt"
377
+
$ my-cli --out file.txt # output: "file.txt"
378
+
$ my-cli --output file.txt # output: "file.txt"
379
+
```
380
+
381
+
For non-array options, using both an alias and the canonical name throws an error:
382
+
383
+
```shell
384
+
$ my-cli --verb --verbose
385
+
Error: Conflicting options: --verb and --verbose cannot both be specified
386
+
```
387
+
388
+
For array options, values from all aliases are merged. Single-character aliases and the canonical name are processed first (in command-line order), then multi-character aliases are appended:
0 commit comments