Skip to content

Commit 06b8e31

Browse files
committed
update
1 parent 6d7ba3f commit 06b8e31

File tree

2 files changed

+68
-70
lines changed

2 files changed

+68
-70
lines changed

bin/cli.ts

Lines changed: 68 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -12,85 +12,84 @@ const shells = ['zsh', 'bash', 'fish', 'powershell'];
1212
const cli = cac('tab');
1313

1414
cli
15-
.command(
16-
'<packageManager> complete',
17-
'Process completion requests from shell'
18-
)
19-
.allowUnknownOptions()
20-
.action(async (packageManager) => {
21-
if (!packageManagers.includes(packageManager)) {
22-
console.error(`Error: Unsupported package manager "${packageManager}"`);
23-
console.error(
24-
`Supported package managers: ${packageManagers.join(', ')}`
25-
);
26-
process.exit(1);
27-
}
15+
.command(
16+
'<packageManager> complete',
17+
'Process completion requests from shell'
18+
)
19+
.action(async (packageManager) => {
20+
if (!packageManagers.includes(packageManager)) {
21+
console.error(`Error: Unsupported package manager "${packageManager}"`);
22+
console.error(
23+
`Supported package managers: ${packageManagers.join(', ')}`
24+
);
25+
process.exit(1);
26+
}
2827

29-
const dashIndex = process.argv.indexOf('--');
30-
if (dashIndex !== -1) {
31-
const completion = new Completion();
32-
setupCompletionForPackageManager(packageManager, completion);
33-
const toComplete = process.argv.slice(dashIndex + 1);
34-
await completion.parse(toComplete);
35-
process.exit(0);
36-
} else {
37-
console.error(`Error: Expected '--' followed by command to complete`);
38-
console.error(
39-
`Example: npx @bombsh/tab ${packageManager} complete -- command-to-complete`
40-
);
41-
process.exit(1);
42-
}
43-
});
28+
const dashIndex = process.argv.indexOf('--');
29+
if (dashIndex !== -1) {
30+
const completion = new Completion();
31+
setupCompletionForPackageManager(packageManager, completion);
32+
const toComplete = process.argv.slice(dashIndex + 1);
33+
await completion.parse(toComplete);
34+
process.exit(0);
35+
} else {
36+
console.error(`Error: Expected '--' followed by command to complete`);
37+
console.error(
38+
`Example: ${packageManager} exec @bombsh/tab ${packageManager} complete -- command-to-complete`
39+
);
40+
process.exit(1);
41+
}
42+
});
4443

4544
cli
46-
.command(
47-
'<packageManager> <shell>',
48-
'Generate shell completion script for a package manager'
49-
)
50-
.action(async (packageManager, shell) => {
51-
if (shell === 'complete') {
52-
const dashIndex = process.argv.indexOf('--');
53-
if (dashIndex !== -1) {
54-
const completion = new Completion();
55-
setupCompletionForPackageManager(packageManager, completion);
56-
const toComplete = process.argv.slice(dashIndex + 1);
57-
await completion.parse(toComplete);
58-
process.exit(0);
59-
} else {
60-
console.error(`Error: Expected '--' followed by command to complete`);
61-
console.error(
62-
`Example: npx @bombsh/tab ${packageManager} complete -- command-to-complete`
63-
);
64-
process.exit(1);
65-
}
66-
return;
67-
}
45+
.command(
46+
'<packageManager> <shell>',
47+
'Generate shell completion script for a package manager'
48+
)
49+
.action(async (packageManager, shell) => {
50+
if (shell === 'complete') {
51+
const dashIndex = process.argv.indexOf('--');
52+
if (dashIndex !== -1) {
53+
const completion = new Completion();
54+
setupCompletionForPackageManager(packageManager, completion);
55+
const toComplete = process.argv.slice(dashIndex + 1);
56+
await completion.parse(toComplete);
57+
process.exit(0);
58+
} else {
59+
console.error(`Error: Expected '--' followed by command to complete`);
60+
console.error(
61+
`Example: ${packageManager} exec @bombsh/tab ${packageManager} complete -- command-to-complete`
62+
);
63+
process.exit(1);
64+
}
65+
return;
66+
}
6867

69-
if (!packageManagers.includes(packageManager)) {
70-
console.error(`Error: Unsupported package manager "${packageManager}"`);
71-
console.error(
72-
`Supported package managers: ${packageManagers.join(', ')}`
73-
);
74-
process.exit(1);
75-
}
68+
if (!packageManagers.includes(packageManager)) {
69+
console.error(`Error: Unsupported package manager "${packageManager}"`);
70+
console.error(
71+
`Supported package managers: ${packageManagers.join(', ')}`
72+
);
73+
process.exit(1);
74+
}
7675

77-
if (!shells.includes(shell)) {
78-
console.error(`Error: Unsupported shell "${shell}"`);
79-
console.error(`Supported shells: ${shells.join(', ')}`);
80-
process.exit(1);
81-
}
76+
if (!shells.includes(shell)) {
77+
console.error(`Error: Unsupported shell "${shell}"`);
78+
console.error(`Supported shells: ${shells.join(', ')}`);
79+
process.exit(1);
80+
}
8281

83-
generateCompletionScript(packageManager, shell);
84-
});
82+
generateCompletionScript(packageManager, shell);
83+
});
8584

8685
const completion = tab(cli);
8786

8887
cli.parse();
8988

9089
function generateCompletionScript(packageManager: string, shell: string) {
91-
const name = packageManager;
92-
const executable = process.env.npm_execpath
93-
? `${packageManager} exec @bombsh/tab ${packageManager}`
94-
: `node ${process.argv[1]} ${packageManager}`;
95-
script(shell as any, name, executable);
90+
const name = packageManager;
91+
const executable = process.env.npm_execpath
92+
? `${packageManager} exec @bombsh/tab ${packageManager}`
93+
: `node ${process.argv[1]} ${packageManager}`;
94+
script(shell as any, name, executable);
9695
}

tsdown.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ export default defineConfig({
77
'src/cac.ts',
88
'src/commander.ts',
99
'bin/cli.ts',
10-
'bin/completion-handlers.ts',
1110
],
1211
format: ['esm'],
1312
dts: true,

0 commit comments

Comments
 (0)