Skip to content

Commit 4550eca

Browse files
authored
chore: readme-gif (#57)
* update * change gif * update readme * update readme * update
1 parent 1080e7c commit 4550eca

File tree

2 files changed

+42
-20
lines changed

2 files changed

+42
-20
lines changed

README.md

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
> A video showcasing how pnpm autocompletions work on a test CLI command
2-
> like `my-cli`
1+
![tab CLI autocompletions demo](assets/preview.gif)
32

43
# tab
54

6-
Shell autocompletions are largely missing in the JavaScript CLI ecosystem. Tab provides a simple API for adding autocompletions to any JavaScript CLI tool.
5+
Shell autocompletions are largely missing in the JavaScript CLI ecosystem. tab provides a simple API for adding autocompletions to any JavaScript CLI tool.
76

87
Additionally, tab supports autocompletions for `pnpm`, `npm`, `yarn`, and `bun`.
98

109
As CLI tooling authors, if we can spare our users a second or two by not checking documentation or writing the `-h` flag, we're doing them a huge favor. The unconscious mind loves hitting the [TAB] key and always expects feedback. When nothing happens, it breaks the user's flow - a frustration apparent across the whole JavaScript CLI tooling ecosystem.
1110

12-
Tab solves this complexity by providing autocompletions that work consistently across `zsh`, `bash`, `fish`, and `powershell`.
11+
tab solves this complexity by providing autocompletions that work consistently across `zsh`, `bash`, `fish`, and `powershell`.
1312

1413
## Installation
1514

@@ -92,7 +91,7 @@ yarn add --emoji=<TAB>
9291

9392
## Framework Adapters
9493

95-
Tab provides adapters for popular JavaScript CLI frameworks.
94+
tab provides adapters for popular JavaScript CLI frameworks.
9695

9796
### CAC Integration
9897

@@ -109,13 +108,17 @@ cli
109108
.option('--host <host>', 'Specify host');
110109

111110
// Initialize tab completions
112-
const completion = tab(cli);
111+
const completion = await tab(cli);
113112

114113
// Add custom completions for option values
115-
completion.commands.get('dev')?.options.get('--port')!.handler = async () => [
116-
{ value: '3000', description: 'Development port' },
117-
{ value: '8080', description: 'Production port' },
118-
];
114+
const devCommand = completion.commands.get('dev');
115+
const portOption = devCommand?.options.get('port');
116+
if (portOption) {
117+
portOption.handler = (complete) => {
118+
complete('3000', 'Development port');
119+
complete('8080', 'Production port');
120+
};
121+
}
119122

120123
cli.parse();
121124
```
@@ -143,10 +146,14 @@ const main = defineCommand({
143146
const completion = await tab(main);
144147

145148
// Add custom completions
146-
completion.commands.get('dev')?.options.get('--port')!.handler = async () => [
147-
{ value: '3000', description: 'Development port' },
148-
{ value: '8080', description: 'Production port' },
149-
];
149+
const devCommand = completion.commands.get('dev');
150+
const portOption = devCommand?.options.get('port');
151+
if (portOption) {
152+
portOption.handler = (complete) => {
153+
complete('3000', 'Development port');
154+
complete('8080', 'Production port');
155+
};
156+
}
150157

151158
const cli = createMain(main);
152159
cli();
@@ -175,15 +182,19 @@ program
175182
const completion = tab(program);
176183

177184
// Add custom completions
178-
completion.commands.get('serve')?.options.get('--port')!.handler = async () => [
179-
{ value: '3000', description: 'Default port' },
180-
{ value: '8080', description: 'Alternative port' },
181-
];
185+
const serveCommand = completion.commands.get('serve');
186+
const portOption = serveCommand?.options.get('port');
187+
if (portOption) {
188+
portOption.handler = (complete) => {
189+
complete('3000', 'Default port');
190+
complete('8080', 'Alternative port');
191+
};
192+
}
182193

183194
program.parse();
184195
```
185196

186-
Tab uses a standardized completion protocol that any CLI can implement:
197+
tab uses a standardized completion protocol that any CLI can implement:
187198

188199
```bash
189200
# Generate shell completion script
@@ -207,4 +218,15 @@ See [bombshell docs](https://bomb.sh/docs/tab/).
207218

208219
## Contributing
209220

210-
We welcome contributions! Tab's architecture makes it easy to add support for new package managers or CLI frameworks.
221+
We welcome contributions! tab's architecture makes it easy to add support for new package managers or CLI frameworks.
222+
223+
## Acknowledgments
224+
225+
tab was inspired by the great [Cobra](https://github.com/spf13/cobra/) project, which set the standard for CLI tooling in the Go ecosystem.
226+
227+
## Adoption Support
228+
229+
We want to make it as easy as possible for the JS ecosystem to enjoy great autocompletions.
230+
We at [thundraa](https://thundraa.com) would be happy to help any open source CLI utility adopt tab.
231+
If you maintain a CLI and would like autocompletions set up for your users, just [drop the details in our _Adopting tab_ discussion](https://github.com/bombshell-dev/tab/discussions/61).
232+
We’ll gladly help and even open a PR to get you started.

assets/preview.gif

15 MB
Loading

0 commit comments

Comments
 (0)