-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathcmd-install-completion.mts
More file actions
84 lines (69 loc) · 2.37 KB
/
Copy pathcmd-install-completion.mts
File metadata and controls
84 lines (69 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { handleInstallCompletion } from './handle-install-completion.mts'
import { outputDryRunWrite } from '../../util/dry-run/output.mts'
import { defineFlags } from '../../meow.mts'
import { commonFlags } from '../../flags.mts'
import { meowOrExit } from '../../util/cli/with-subcommands.mjs'
import { getFlagListOutput } from '../../util/output/formatting.mts'
import type { CliCommandContext } from '../../util/cli/with-subcommands.mjs'
import type { MeowFlags } from '../../flags.mts'
const config = {
commandName: 'completion',
description: 'Install bash completion for Socket CLI',
flags: defineFlags({
...commonFlags,
}),
help: (command: string, helpConfig: { flags: MeowFlags }) => `
Usage
$ ${command} [options] [NAME=socket]
Installs bash completion for the Socket CLI. This will:
1. Source the completion script in your current shell
2. Add the source command to your ~/.bashrc if it's not already there
This command will only setup tab completion, nothing else.
Afterwards you should be able to type \`socket \` and then press tab to
have bash auto-complete/suggest the sub/command or flags.
Currently only supports bash.
The optional name argument allows you to enable tab completion on a command
name other than "socket". Mostly for debugging but also useful if you use a
different alias for socket on your system.
Options
${getFlagListOutput(helpConfig.flags)}
Examples
$ ${command}
$ ${command} sd
$ ${command} ./sd
`,
hidden: false,
}
export const cmdInstallCompletion = {
description: config.description,
hidden: config.hidden,
run,
}
export async function run(
argv: string[] | readonly string[],
importMeta: ImportMeta,
{ parentName }: CliCommandContext,
): Promise<void> {
const cli = meowOrExit({
argv,
config,
parentName,
importMeta,
})
const dryRun = cli.flags['dryRun']
const targetName = cli.input[0] || 'socket'
if (dryRun) {
// Runtime read so tests that mutate process.env['HOME'] pick up changes.
const bashRcPath = `${process.env['HOME']}/.bashrc`
outputDryRunWrite(
bashRcPath,
`install bash completion for "${targetName}"`,
[
'Add completion script source command to ~/.bashrc',
'Enable tab completion in current shell',
],
)
return
}
await handleInstallCompletion(targetName)
}