clap-ts 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +57 -2
- package/dist/completions.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -515,6 +515,62 @@ runMain(rootCommand, {
|
|
|
515
515
|
});
|
|
516
516
|
```
|
|
517
517
|
|
|
518
|
+
### Shell Completions
|
|
519
|
+
|
|
520
|
+
Add Tab completion for bash, zsh, fish, and powershell with one line:
|
|
521
|
+
|
|
522
|
+
```ts
|
|
523
|
+
import { defineCommand, runMain, withCompletions } from 'clap-ts';
|
|
524
|
+
|
|
525
|
+
const root = defineCommand({
|
|
526
|
+
meta: { name: 'my-cli', version: '1.0.0' },
|
|
527
|
+
args: { /* ... */ },
|
|
528
|
+
subCommands: { /* ... */ },
|
|
529
|
+
});
|
|
530
|
+
|
|
531
|
+
// Auto-adds a `completions` subcommand
|
|
532
|
+
runMain(withCompletions(root));
|
|
533
|
+
```
|
|
534
|
+
|
|
535
|
+
Users then enable completions in their shell:
|
|
536
|
+
|
|
537
|
+
```bash
|
|
538
|
+
# bash - add to ~/.bashrc
|
|
539
|
+
eval "$(my-cli completions bash)"
|
|
540
|
+
|
|
541
|
+
# zsh - add to ~/.zshrc
|
|
542
|
+
eval "$(my-cli completions zsh)"
|
|
543
|
+
|
|
544
|
+
# fish - save to completions dir
|
|
545
|
+
my-cli completions fish > ~/.config/fish/completions/my-cli.fish
|
|
546
|
+
|
|
547
|
+
# powershell - add to $PROFILE
|
|
548
|
+
my-cli completions powershell >> $PROFILE
|
|
549
|
+
```
|
|
550
|
+
|
|
551
|
+
Generated scripts support flags, subcommands, aliases, enum values, and value hints (file/dir completion):
|
|
552
|
+
|
|
553
|
+
```ts
|
|
554
|
+
const cmd = defineCommand({
|
|
555
|
+
meta: { name: 'tool' },
|
|
556
|
+
args: {
|
|
557
|
+
config: { type: 'string', valueHint: 'filePath' }, // Tab completes files
|
|
558
|
+
outDir: { type: 'string', valueHint: 'dirPath' }, // Tab completes directories
|
|
559
|
+
host: { type: 'string', valueHint: 'hostname' }, // Tab completes hostnames
|
|
560
|
+
env: { type: 'string', valueParser: ['dev', 'prod'] }, // Tab shows dev, prod
|
|
561
|
+
},
|
|
562
|
+
});
|
|
563
|
+
```
|
|
564
|
+
|
|
565
|
+
You can also generate scripts manually without the subcommand:
|
|
566
|
+
|
|
567
|
+
```ts
|
|
568
|
+
import { generateCompletions } from 'clap-ts';
|
|
569
|
+
|
|
570
|
+
const bashScript = generateCompletions(root, 'bash');
|
|
571
|
+
const zshScript = generateCompletions(root, 'zsh', 'custom-binary-name');
|
|
572
|
+
```
|
|
573
|
+
|
|
518
574
|
### runMain
|
|
519
575
|
|
|
520
576
|
Entry point for CLI applications. Handles argv parsing, subcommand resolution, validation, help/version, and error display.
|
|
@@ -733,12 +789,11 @@ bun run bench/parse.bench.ts
|
|
|
733
789
|
| hidePossibleValues | Yes | Yes |
|
|
734
790
|
| Hidden args/commands | Yes | Yes |
|
|
735
791
|
| Type-safe parsed args | derive macro | generics |
|
|
736
|
-
| Shell completions | Yes |
|
|
792
|
+
| Shell completions (bash/zsh/fish/powershell) | Yes | Yes |
|
|
737
793
|
| Man page generation | Yes | Not yet |
|
|
738
794
|
|
|
739
795
|
## Roadmap
|
|
740
796
|
|
|
741
|
-
- Shell completion generation (bash/zsh/fish)
|
|
742
797
|
- Man page generation
|
|
743
798
|
- Markdown help output
|
|
744
799
|
|
package/dist/completions.d.ts
CHANGED
|
@@ -37,4 +37,4 @@ export declare function generateCompletions(command: CommandDef, shell: Shell, b
|
|
|
37
37
|
* eval "$(my-cli completions bash)"
|
|
38
38
|
* ```
|
|
39
39
|
*/
|
|
40
|
-
export declare function withCompletions
|
|
40
|
+
export declare function withCompletions(rootCommand: CommandDef<any>): CommandDef<any>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clap-ts",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "A type-safe CLI argument parser for TypeScript, inspired by Rust's clap crate. Full clap-style parsing, validation, help generation, and subcommand support with zero dependencies.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|