mirror of
https://github.com/clap-rs/clap
synced 2024-12-15 07:12:32 +00:00
77 lines
2.1 KiB
Text
77 lines
2.1 KiB
Text
|
_my-app() {
|
||
|
local i cur prev opts cmds
|
||
|
COMPREPLY=()
|
||
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||
|
cmd=""
|
||
|
opts=""
|
||
|
|
||
|
for i in ${COMP_WORDS[@]}
|
||
|
do
|
||
|
case "${i}" in
|
||
|
"$1")
|
||
|
cmd="my__app"
|
||
|
;;
|
||
|
help)
|
||
|
cmd+="__help"
|
||
|
;;
|
||
|
test)
|
||
|
cmd+="__test"
|
||
|
;;
|
||
|
*)
|
||
|
;;
|
||
|
esac
|
||
|
done
|
||
|
|
||
|
case "${cmd}" in
|
||
|
my__app)
|
||
|
opts="-h -V -C -c --help --version --conf --config <file> first second test help"
|
||
|
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
|
||
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||
|
return 0
|
||
|
fi
|
||
|
case "${prev}" in
|
||
|
*)
|
||
|
COMPREPLY=()
|
||
|
;;
|
||
|
esac
|
||
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||
|
return 0
|
||
|
;;
|
||
|
my__app__help)
|
||
|
opts="<SUBCOMMAND>..."
|
||
|
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
|
||
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||
|
return 0
|
||
|
fi
|
||
|
case "${prev}" in
|
||
|
*)
|
||
|
COMPREPLY=()
|
||
|
;;
|
||
|
esac
|
||
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||
|
return 0
|
||
|
;;
|
||
|
my__app__test)
|
||
|
opts="-h -V --case --help --version"
|
||
|
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
|
||
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||
|
return 0
|
||
|
fi
|
||
|
case "${prev}" in
|
||
|
--case)
|
||
|
COMPREPLY=($(compgen -f "${cur}"))
|
||
|
return 0
|
||
|
;;
|
||
|
*)
|
||
|
COMPREPLY=()
|
||
|
;;
|
||
|
esac
|
||
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||
|
return 0
|
||
|
;;
|
||
|
esac
|
||
|
}
|
||
|
|
||
|
complete -F _my-app -o bashdefault -o default my-app
|