-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalias.ts
61 lines (50 loc) · 1.51 KB
/
alias.ts
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
import { flags } from '@oclif/command'
import { CompletionBase } from '../../../base'
import { generateCompletionAliasScriptForBash } from '../../../utils/bash'
import { generateCompletionAliasScriptForFish } from '../../../utils/fish'
export default class CompletionGenerateAlias extends CompletionBase {
static description = [
`Generates completion script for alias`,
``,
`This needs the completion script for the main command to be present.`,
``,
`Check the "completion:generate" command.`,
].join('\n')
static args = [
{
name: 'ALIAS',
required: true,
description: 'name of the alias',
},
]
static flags = {
...CompletionBase.flags,
shell: flags.string({
...CompletionBase.flags.shell,
options: CompletionBase.flags.shell.options?.filter(
(shell) => shell !== 'zsh'
),
required: true,
}),
}
async run() {
const { args, flags } = this.parse(CompletionGenerateAlias)
const shell = flags.shell
const { bin } = this.config
const alias = args.ALIAS
if (bin === alias) {
return this.error(`ALIAS can not be ${bin}`, { exit: 1 })
}
let scriptContent = ''
if (shell === 'bash') {
scriptContent = generateCompletionAliasScriptForBash({ bin, alias })
}
if (shell === 'fish') {
scriptContent = generateCompletionAliasScriptForFish({ bin, alias })
}
if (shell === 'zsh') {
this.error(`not needed for ${shell}`, { exit: 1 })
}
this.log(scriptContent)
}
}