-
Notifications
You must be signed in to change notification settings - Fork 31
/
completion.go
71 lines (66 loc) · 1.77 KB
/
completion.go
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
package completion
import (
"fmt"
"os"
"github.com/urfave/cli/v2"
)
// taken from https://github.com/urfave/cli/blob/master/autocomplete/zsh_autocomplete
var zsh_script = `#compdef temporal
_cli_zsh_autocomplete() {
local -a opts
local cur
cur=${words[-1]}
if [[ "$cur" == "-"* ]]; then
opts=("${(@f)$(_CLI_ZSH_AUTOCOMPLETE_HACK=1 ${words[@]:0:#words[@]-1} ${cur} --generate-bash-completion)}")
else
opts=("${(@f)$(_CLI_ZSH_AUTOCOMPLETE_HACK=1 ${words[@]:0:#words[@]-1} --generate-bash-completion)}")
fi
if [[ "${opts[1]}" != "" ]]; then
_describe 'values' opts
else
_files
fi
return
}
compdef _cli_zsh_autocomplete temporal
`
// taken from https://github.com/urfave/cli/blob/master/autocomplete/bash_autocomplete
var bash_script = `#! /bin/bash
_cli_bash_autocomplete() {
if [[ "${COMP_WORDS[0]}" != "source" ]]; then
local cur opts base
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
if [[ "$cur" == "-"* ]]; then
opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} ${cur} --generate-bash-completion )
else
opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --generate-bash-completion )
fi
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
fi
}
complete -o bashdefault -o default -F _cli_bash_autocomplete temporal
`
func NewCompletionCommands() []*cli.Command {
return []*cli.Command{
{
Name: "bash",
Usage: "bash completion output",
UsageText: "source <(temporal completion bash)",
Action: func(c *cli.Context) error {
fmt.Fprintln(os.Stdout, bash_script)
return nil
},
},
{
Name: "zsh",
Usage: "zsh completion output",
UsageText: "source <(temporal completion zsh)",
Action: func(c *cli.Context) error {
fmt.Fprintln(os.Stdout, zsh_script)
return nil
},
},
}
}