Skip to content

Commit

Permalink
fix: stop using manually edited completion
Browse files Browse the repository at this point in the history
  • Loading branch information
matejvasek committed Oct 5, 2020
1 parent c2b4a30 commit bf9b048
Showing 1 changed file with 2 additions and 153 deletions.
155 changes: 2 additions & 153 deletions cmd/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,159 +39,8 @@ source <(faas completion bash)
return err
}
if args[0] == "zsh" {
// manually edited script based on `root.GenZshCompletion(os.Stdout)`
// unfortunately it doesn't support completion so well as for bash
// some manual edits had to be done
os.Stdout.WriteString(`
compdef _faas faas
function _faas {
local -a commands
_arguments -C \
'--config[config file path]:file:_files' \
'(-v --verbose)'{-v,--verbose}'[print verbose logs]' \
"1: :->cmnds" \
"*::arg:->args"
case $state in
cmnds)
commands=(
"completion:Generates bash/zsh completion scripts"
"create:Create a Function"
"delete:Delete deployed Function"
"describe:Describe Function"
"help:Help about any command"
"list:Lists deployed Functions"
"run:Run Function locally"
"update:Update or create a deployed Function"
"version:Print version"
)
_describe "command" commands
;;
esac
case "$words[1]" in
completion)
_faas_completion
;;
create)
_faas_create
;;
delete)
_faas_delete
;;
describe)
_faas_describe
;;
help)
_faas_help
;;
list)
_faas_list
;;
run)
_faas_run
;;
update)
_faas_update
;;
version)
_faas_version
;;
esac
}
function _list_funs() {
compadd $(faas list 2> /dev/null)
}
function _list_langs() {
compadd node go quarkus
}
function _list_fmts() {
compadd yaml xml json
}
function _list_regs() {
local config="${HOME}/.docker/config.json"
if command -v yq >/dev/null && test -f "$config"; then
compadd $(jq -r ".auths | keys[] " "$config")
fi
}
function _faas_completion {
_arguments \
'(-h --help)'{-h,--help}'[help for completion]' \
'--config[config file path]:file:_files' \
'(-v --verbose)'{-v,--verbose}'[print verbose logs]' \
'1: :("bash" "zsh")'
}
function _faas_create {
_arguments \
'1:string:_list_langs' \
'(-i --internal)'{-i,--internal}'[Create a cluster-local service without a publicly accessible route. $FAAS_INTERNAL]' \
'(-l --local)'{-l,--local}'[create the service function locally only.]' \
'(-n --name)'{-n,--name}'[optionally specify an explicit name for the serive, overriding path-derivation. $FAAS_NAME]:' \
'(-s --namespace)'{-s,--namespace}'[namespace at image registry (usually username or org name). $FAAS_NAMESPACE]:' \
'(-r --registry)'{-r,--registry}'[image registry (ex: quay.io). $FAAS_REGISTRY]:string:_list_regs' \
'--config[config file path]:file:_files' \
'(-v --verbose)'{-v,--verbose}'[print verbose logs]'
}
function _faas_delete {
_arguments \
'(-n --name)'{-n,--name}'[optionally specify an explicit name to remove, overriding path-derivation. $FAAS_NAME]:string:_list_funs' \
'--config[config file path]:file:_files' \
'(-v --verbose)'{-v,--verbose}'[print verbose logs]'
}
function _faas_describe {
_arguments \
'1:string:_list_funs' \
'(-n --name)'{-n,--name}'[optionally specify an explicit name for the serive, overriding path-derivation. $FAAS_NAME]:string:_list_funs' \
'(-o --output)'{-o,--output}'[optionally specify output format (yaml,xml,json).]:string:_list_fmts' \
'--config[config file path]:file:_files' \
'(-v --verbose)'{-v,--verbose}'[print verbose logs]'
}
function _faas_help {
_arguments \
'--config[config file path]:file:_files' \
'(-v --verbose)'{-v,--verbose}'[print verbose logs]'
}
function _faas_list {
_arguments \
'--config[config file path]:file:_files' \
'(-v --verbose)'{-v,--verbose}'[print verbose logs]'
}
function _faas_run {
_arguments \
'--config[config file path]:file:_files' \
'(-v --verbose)'{-v,--verbose}'[print verbose logs]'
}
function _faas_update {
_arguments \
'--config[config file path]:file:_files' \
'(-s --namespace)'{-s,--namespace}'[namespace at image registry (usually username or org name). $FAAS_NAMESPACE]:' \
'(-r --registry)'{-r,--registry}'[image registry (ex: quay.io). $FAAS_REGISTRY]:string:_list_regs' \
'(-v --verbose)'{-v,--verbose}'[print verbose logs]'
}
function _faas_version {
_arguments \
'--config[config file path]:file:_files' \
'(-v --verbose)'{-v,--verbose}'[print verbose logs]'
}
`)
return nil
err = root.GenZshCompletion(os.Stdout)
return err
}
return errors.New("unknown shell, only bash and zsh are supported")
},
Expand Down

0 comments on commit bf9b048

Please sign in to comment.