-
Notifications
You must be signed in to change notification settings - Fork 32
/
index.ts
55 lines (41 loc) · 1.88 KB
/
index.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
import {flags} from '@oclif/command'
import * as chalk from 'chalk'
import {cli} from 'cli-ux'
import {AutocompleteBase} from '../../base'
import Create from './create'
export default class Index extends AutocompleteBase {
static description = 'display autocomplete installation instructions'
static args = [{name: 'shell', description: 'shell type', required: false}]
static flags = {
'refresh-cache': flags.boolean({description: 'Refresh cache (ignores displaying instructions)', char: 'r'}),
}
static examples = [
'$ <%= config.bin %> autocomplete',
'$ <%= config.bin %> autocomplete bash',
'$ <%= config.bin %> autocomplete zsh',
'$ <%= config.bin %> autocomplete --refresh-cache',
]
async run() {
const {args, flags} = this.parse(Index)
const shell = args.shell || this.determineShell(this.config.shell)
this.errorIfNotSupportedShell(shell)
cli.action.start(`${chalk.bold('Building the autocomplete cache')}`)
await Create.run([], this.config)
cli.action.stop()
if (!flags['refresh-cache']) {
const bin = this.config.bin
const tabStr = shell === 'bash' ? '<TAB><TAB>' : '<TAB>'
const note = shell === 'zsh' ? `After sourcing, you can run \`${chalk.cyan('$ compaudit -D')}\` to ensure no permissions conflicts are present` : 'If your terminal starts as a login shell you may need to print the init script into ~/.bash_profile or ~/.profile.'
this.log(`
${chalk.bold(`Setup Instructions for ${bin.toUpperCase()} CLI Autocomplete ---`)}
1) Add the autocomplete env var to your ${shell} profile and source it
${chalk.cyan(`$ printf "eval $(${bin} autocomplete:script ${shell})" >> ~/.${shell}rc; source ~/.${shell}rc`)}
NOTE: ${note}
2) Test it out, e.g.:
${chalk.cyan(`$ ${bin} ${tabStr}`)} # Command completion
${chalk.cyan(`$ ${bin} command --${tabStr}`)} # Flag completion
Enjoy!
`)
}
}
}