Commit bb3ccda6
bb3ccda64c2dMerged
zhilyaev <[email protected]> ยท 5 years ago ยท 3 files ยท +1 added ยท ~2 modified
Description
add completion
Details
- Commit
- bb3ccda64c2d
- Parent
- 1193b2472931
cmd/helmwave/completion.goaddedView file
1+
package main2+
3+
import (4+
"errors"5+
"fmt"6+
"github.com/urfave/cli/v2"7+
)8+
9+
const (10+
bash = `11+
#! /bin/bash12+
13+
: ${PROG:=helmwave}14+
15+
_cli_bash_autocomplete() {16+
if [[ "${COMP_WORDS[0]}" != "source" ]]; then17+
local cur opts base18+
COMPREPLY=()19+
cur="${COMP_WORDS[COMP_CWORD]}"20+
if [[ "$cur" == "-"* ]]; then21+
opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} ${cur} --generate-bash-completion )22+
else23+
opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --generate-bash-completion )24+
fi25+
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )26+
return 027+
fi28+
}29+
30+
complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete $PROG31+
unset PROG32+
`33+
34+
zsh = `35+
#compdef helmwave36+
37+
_cli_zsh_autocomplete() {38+
39+
local -a opts40+
local cur41+
cur=${words[-1]}42+
if [[ "$cur" == "-"* ]]; then43+
opts=("${(@f)$(_CLI_ZSH_AUTOCOMPLETE_HACK=1 ${words[@]:0:#words[@]-1} ${cur} --generate-bash-completion)}")44+
else45+
opts=("${(@f)$(_CLI_ZSH_AUTOCOMPLETE_HACK=1 ${words[@]:0:#words[@]-1} --generate-bash-completion)}")46+
fi47+
48+
if [[ "${opts[1]}" != "" ]]; then49+
_describe 'values' opts50+
else51+
_files52+
fi53+
54+
return55+
}56+
57+
compdef _cli_zsh_autocomplete helmwave58+
`59+
)60+
61+
var (62+
ErrWrongShell = errors.New("wrong shell")63+
ErrNotChose = errors.New("you did not specify a shell")64+
)65+
66+
func completion() *cli.Command {67+
return &cli.Command{68+
Name: "completion",69+
Usage: "Generate completion script",70+
Description: `71+
echo "source <(helmwave completion bash)" >> ~/.bashrc72+
echo "source <(helmwave completion zsh)" >> ~/.zshrc"73+
`,74+
Action: func(c *cli.Context) error {75+
if 0 == c.Args().Len() {76+
return ErrNotChose77+
}78+
79+
switch c.Args().First() {80+
case "bash":81+
fmt.Print(bash)82+
return nil83+
case "zsh":84+
fmt.Print(zsh)85+
return nil86+
default:87+
return ErrWrongShell88+
}89+
},90+
}91+
}cmd/helmwave/main.gomodifiedView file
Loading diffโฆ
pkg/version/version.gomodifiedView file
Loading diffโฆ