Skip to content

Commit 6d7ba3f

Browse files
committed
prettier
1 parent f806955 commit 6d7ba3f

File tree

3 files changed

+124
-102
lines changed

3 files changed

+124
-102
lines changed

bin/cli.ts

Lines changed: 73 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -4,79 +4,93 @@ import cac from 'cac';
44
import { script, Completion } from '../src/index.js';
55
import tab from '../src/cac.js';
66

7-
import {
8-
setupCompletionForPackageManager
9-
} from './completion-handlers';
7+
import { setupCompletionForPackageManager } from './completion-handlers';
108

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

1412
const cli = cac('tab');
1513

16-
cli.command('<packageManager> complete', 'Process completion requests from shell')
17-
.allowUnknownOptions()
18-
.action(async (packageManager) => {
19-
if (!packageManagers.includes(packageManager)) {
20-
console.error(`Error: Unsupported package manager "${packageManager}"`);
21-
console.error(`Supported package managers: ${packageManagers.join(', ')}`);
22-
process.exit(1);
23-
}
14+
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+
}
2428

25-
const dashIndex = process.argv.indexOf('--');
26-
if (dashIndex !== -1) {
27-
const completion = new Completion();
28-
setupCompletionForPackageManager(packageManager, completion);
29-
const toComplete = process.argv.slice(dashIndex + 1);
30-
await completion.parse(toComplete);
31-
process.exit(0);
32-
} else {
33-
console.error(`Error: Expected '--' followed by command to complete`);
34-
console.error(`Example: npx @bombsh/tab ${packageManager} complete -- command-to-complete`);
35-
process.exit(1);
36-
}
37-
});
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+
});
3844

39-
cli.command('<packageManager> <shell>', 'Generate shell completion script for a package manager')
40-
.action(async (packageManager, shell) => {
41-
if (shell === 'complete') {
42-
const dashIndex = process.argv.indexOf('--');
43-
if (dashIndex !== -1) {
44-
const completion = new Completion();
45-
setupCompletionForPackageManager(packageManager, completion);
46-
const toComplete = process.argv.slice(dashIndex + 1);
47-
await completion.parse(toComplete);
48-
process.exit(0);
49-
} else {
50-
console.error(`Error: Expected '--' followed by command to complete`);
51-
console.error(`Example: npx @bombsh/tab ${packageManager} complete -- command-to-complete`);
52-
process.exit(1);
53-
}
54-
return;
55-
}
45+
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+
}
5668

57-
if (!packageManagers.includes(packageManager)) {
58-
console.error(`Error: Unsupported package manager "${packageManager}"`);
59-
console.error(`Supported package managers: ${packageManagers.join(', ')}`);
60-
process.exit(1);
61-
}
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+
}
6276

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

69-
generateCompletionScript(packageManager, shell);
70-
});
83+
generateCompletionScript(packageManager, shell);
84+
});
7185

7286
const completion = tab(cli);
7387

7488
cli.parse();
7589

7690
function generateCompletionScript(packageManager: string, shell: string) {
77-
const name = packageManager;
78-
const executable = process.env.npm_execpath ?
79-
`${packageManager} exec @bombsh/tab ${packageManager}` :
80-
`node ${process.argv[1]} ${packageManager}`;
81-
script(shell as any, name, executable);
82-
}
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);
96+
}

bin/completion-handlers.ts

Lines changed: 50 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,64 @@
11
import { Completion } from '../src/index.js';
22

3-
export function setupCompletionForPackageManager(packageManager: string, completion: Completion) {
4-
if (packageManager === 'pnpm') {
5-
setupPnpmCompletions(completion);
6-
} else if (packageManager === 'npm') {
7-
setupNpmCompletions(completion);
8-
} else if (packageManager === 'yarn') {
9-
setupYarnCompletions(completion);
10-
} else if (packageManager === 'bun') {
11-
setupBunCompletions(completion);
12-
}
3+
export function setupCompletionForPackageManager(
4+
packageManager: string,
5+
completion: Completion
6+
) {
7+
if (packageManager === 'pnpm') {
8+
setupPnpmCompletions(completion);
9+
} else if (packageManager === 'npm') {
10+
setupNpmCompletions(completion);
11+
} else if (packageManager === 'yarn') {
12+
setupYarnCompletions(completion);
13+
} else if (packageManager === 'bun') {
14+
setupBunCompletions(completion);
15+
}
1316
}
1417

1518
export function setupPnpmCompletions(completion: Completion) {
16-
completion.addCommand('add', 'Install a package', [], async () => []);
17-
completion.addCommand('remove', 'Remove a package', [], async () => []);
18-
completion.addCommand('install', 'Install all dependencies', [], async () => []);
19-
completion.addCommand('update', 'Update packages', [], async () => []);
20-
completion.addCommand('exec', 'Execute a command', [], async () => []);
21-
completion.addCommand('run', 'Run a script', [], async () => []);
22-
completion.addCommand('publish', 'Publish package', [], async () => []);
23-
completion.addCommand('test', 'Run tests', [], async () => []);
24-
completion.addCommand('build', 'Build project', [], async () => []);
19+
completion.addCommand('add', 'Install a package', [], async () => []);
20+
completion.addCommand('remove', 'Remove a package', [], async () => []);
21+
completion.addCommand(
22+
'install',
23+
'Install all dependencies',
24+
[],
25+
async () => []
26+
);
27+
completion.addCommand('update', 'Update packages', [], async () => []);
28+
completion.addCommand('exec', 'Execute a command', [], async () => []);
29+
completion.addCommand('run', 'Run a script', [], async () => []);
30+
completion.addCommand('publish', 'Publish package', [], async () => []);
31+
completion.addCommand('test', 'Run tests', [], async () => []);
32+
completion.addCommand('build', 'Build project', [], async () => []);
2533
}
2634

2735
export function setupNpmCompletions(completion: Completion) {
28-
completion.addCommand('install', 'Install a package', [], async () => []);
29-
completion.addCommand('uninstall', 'Uninstall a package', [], async () => []);
30-
completion.addCommand('run', 'Run a script', [], async () => []);
31-
completion.addCommand('test', 'Run tests', [], async () => []);
32-
completion.addCommand('publish', 'Publish package', [], async () => []);
33-
completion.addCommand('update', 'Update packages', [], async () => []);
34-
completion.addCommand('start', 'Start the application', [], async () => []);
35-
completion.addCommand('build', 'Build project', [], async () => []);
36+
completion.addCommand('install', 'Install a package', [], async () => []);
37+
completion.addCommand('uninstall', 'Uninstall a package', [], async () => []);
38+
completion.addCommand('run', 'Run a script', [], async () => []);
39+
completion.addCommand('test', 'Run tests', [], async () => []);
40+
completion.addCommand('publish', 'Publish package', [], async () => []);
41+
completion.addCommand('update', 'Update packages', [], async () => []);
42+
completion.addCommand('start', 'Start the application', [], async () => []);
43+
completion.addCommand('build', 'Build project', [], async () => []);
3644
}
3745

3846
export function setupYarnCompletions(completion: Completion) {
39-
completion.addCommand('add', 'Add a package', [], async () => []);
40-
completion.addCommand('remove', 'Remove a package', [], async () => []);
41-
completion.addCommand('run', 'Run a script', [], async () => []);
42-
completion.addCommand('test', 'Run tests', [], async () => []);
43-
completion.addCommand('publish', 'Publish package', [], async () => []);
44-
completion.addCommand('install', 'Install dependencies', [], async () => []);
45-
completion.addCommand('build', 'Build project', [], async () => []);
47+
completion.addCommand('add', 'Add a package', [], async () => []);
48+
completion.addCommand('remove', 'Remove a package', [], async () => []);
49+
completion.addCommand('run', 'Run a script', [], async () => []);
50+
completion.addCommand('test', 'Run tests', [], async () => []);
51+
completion.addCommand('publish', 'Publish package', [], async () => []);
52+
completion.addCommand('install', 'Install dependencies', [], async () => []);
53+
completion.addCommand('build', 'Build project', [], async () => []);
4654
}
4755

4856
export function setupBunCompletions(completion: Completion) {
49-
completion.addCommand('add', 'Add a package', [], async () => []);
50-
completion.addCommand('remove', 'Remove a package', [], async () => []);
51-
completion.addCommand('run', 'Run a script', [], async () => []);
52-
completion.addCommand('test', 'Run tests', [], async () => []);
53-
completion.addCommand('install', 'Install dependencies', [], async () => []);
54-
completion.addCommand('update', 'Update packages', [], async () => []);
55-
completion.addCommand('build', 'Build project', [], async () => []);
56-
}
57+
completion.addCommand('add', 'Add a package', [], async () => []);
58+
completion.addCommand('remove', 'Remove a package', [], async () => []);
59+
completion.addCommand('run', 'Run a script', [], async () => []);
60+
completion.addCommand('test', 'Run tests', [], async () => []);
61+
completion.addCommand('install', 'Install dependencies', [], async () => []);
62+
completion.addCommand('update', 'Update packages', [], async () => []);
63+
completion.addCommand('build', 'Build project', [], async () => []);
64+
}

tsdown.config.ts

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

0 commit comments

Comments
 (0)