Skip to content

Commit 86b24d4

Browse files
authored
fix: parse args manually instead of using cac (#80)
1 parent cf7a727 commit 86b24d4

File tree

3 files changed

+99
-110
lines changed

3 files changed

+99
-110
lines changed

.changeset/pretty-zebras-arrive.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@bomb.sh/tab': patch
3+
---
4+
5+
parse args manually for tab's cli instead of using cac

bin/cli.ts

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
#!/usr/bin/env node
22

3-
import cac from 'cac';
43
import { script } from '../src/t.js';
5-
import tab from '../src/cac.js';
6-
74
import { setupCompletionForPackageManager } from './completion-handlers';
85
import { PackageManagerCompletion } from './package-manager-completion.js';
96

107
const packageManagers = ['npm', 'pnpm', 'yarn', 'bun'];
118
const shells = ['zsh', 'bash', 'fish', 'powershell'];
129

1310
async function main() {
14-
const cli = cac('tab');
15-
16-
// TODO: aren't these conditions are already handled by cac?
1711
const args = process.argv.slice(2);
12+
13+
// <packageManager> complete -- <args>
1814
if (args.length >= 2 && args[1] === 'complete') {
1915
const packageManager = args[0];
2016

@@ -28,47 +24,42 @@ async function main() {
2824

2925
const dashIndex = process.argv.indexOf('--');
3026
if (dashIndex !== -1) {
31-
// Use the new PackageManagerCompletion wrapper
3227
const completion = new PackageManagerCompletion(packageManager);
3328
await setupCompletionForPackageManager(packageManager, completion);
3429
const toComplete = process.argv.slice(dashIndex + 1);
3530
await completion.parse(toComplete);
3631
process.exit(0);
3732
} else {
3833
console.error(`Error: Expected '--' followed by command to complete`);
39-
console.error(
40-
`Example: ${packageManager} exec @bomb.sh/tab ${packageManager} complete -- command-to-complete`
41-
);
4234
process.exit(1);
4335
}
4436
}
4537

46-
cli
47-
.command(
48-
'<packageManager> <shell>',
49-
'Generate shell completion script for a package manager'
50-
)
51-
.action(async (packageManager, shell) => {
52-
if (!packageManagers.includes(packageManager)) {
53-
console.error(`Error: Unsupported package manager "${packageManager}"`);
54-
console.error(
55-
`Supported package managers: ${packageManagers.join(', ')}`
56-
);
57-
process.exit(1);
58-
}
38+
// <packageManager> <shell>
39+
if (args.length === 2) {
40+
const [packageManager, shell] = args;
5941

60-
if (!shells.includes(shell)) {
61-
console.error(`Error: Unsupported shell "${shell}"`);
62-
console.error(`Supported shells: ${shells.join(', ')}`);
63-
process.exit(1);
64-
}
42+
if (!packageManagers.includes(packageManager)) {
43+
console.error(`Error: Unsupported package manager "${packageManager}"`);
44+
console.error(
45+
`Supported package managers: ${packageManagers.join(', ')}`
46+
);
47+
process.exit(1);
48+
}
6549

66-
generateCompletionScript(packageManager, shell);
67-
});
50+
if (!shells.includes(shell)) {
51+
console.error(`Error: Unsupported shell "${shell}"`);
52+
console.error(`Supported shells: ${shells.join(', ')}`);
53+
process.exit(1);
54+
}
6855

69-
tab(cli);
56+
generateCompletionScript(packageManager, shell);
57+
process.exit(0);
58+
}
7059

71-
cli.parse();
60+
console.error('Usage: tab <packageManager> <shell>');
61+
console.error(` tab <packageManager> complete -- <args>`);
62+
process.exit(1);
7263
}
7364

7465
function generateCompletionScript(packageManager: string, shell: string) {

0 commit comments

Comments
 (0)