Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/pretty-zebras-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@bomb.sh/tab': patch
---

parse args manually for tab's cli instead of using cac
55 changes: 23 additions & 32 deletions bin/cli.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
#!/usr/bin/env node

import cac from 'cac';
import { script } from '../src/t.js';
import tab from '../src/cac.js';

import { setupCompletionForPackageManager } from './completion-handlers';
import { PackageManagerCompletion } from './package-manager-completion.js';

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

async function main() {
const cli = cac('tab');

// TODO: aren't these conditions are already handled by cac?
const args = process.argv.slice(2);

// <packageManager> complete -- <args>
if (args.length >= 2 && args[1] === 'complete') {
const packageManager = args[0];

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

const dashIndex = process.argv.indexOf('--');
if (dashIndex !== -1) {
// Use the new PackageManagerCompletion wrapper
const completion = new PackageManagerCompletion(packageManager);
await setupCompletionForPackageManager(packageManager, completion);
const toComplete = process.argv.slice(dashIndex + 1);
await completion.parse(toComplete);
process.exit(0);
} else {
console.error(`Error: Expected '--' followed by command to complete`);
console.error(
`Example: ${packageManager} exec @bomb.sh/tab ${packageManager} complete -- command-to-complete`
);
process.exit(1);
}
}

cli
.command(
'<packageManager> <shell>',
'Generate shell completion script for a package manager'
)
.action(async (packageManager, shell) => {
if (!packageManagers.includes(packageManager)) {
console.error(`Error: Unsupported package manager "${packageManager}"`);
console.error(
`Supported package managers: ${packageManagers.join(', ')}`
);
process.exit(1);
}
// <packageManager> <shell>
if (args.length === 2) {
const [packageManager, shell] = args;

if (!shells.includes(shell)) {
console.error(`Error: Unsupported shell "${shell}"`);
console.error(`Supported shells: ${shells.join(', ')}`);
process.exit(1);
}
if (!packageManagers.includes(packageManager)) {
console.error(`Error: Unsupported package manager "${packageManager}"`);
console.error(
`Supported package managers: ${packageManagers.join(', ')}`
);
process.exit(1);
}

generateCompletionScript(packageManager, shell);
});
if (!shells.includes(shell)) {
console.error(`Error: Unsupported shell "${shell}"`);
console.error(`Supported shells: ${shells.join(', ')}`);
process.exit(1);
}

tab(cli);
generateCompletionScript(packageManager, shell);
process.exit(0);
}

cli.parse();
console.error('Usage: tab <packageManager> <shell>');
console.error(` tab <packageManager> complete -- <args>`);
process.exit(1);
}

function generateCompletionScript(packageManager: string, shell: string) {
Expand Down
Loading
Loading