mirror of
https://github.com/clap-rs/clap
synced 2024-11-14 00:27:13 +00:00
144 lines
4.1 KiB
Bash
144 lines
4.1 KiB
Bash
_my-app() {
|
|
local i cur prev opts cmd
|
|
COMPREPLY=()
|
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
|
cmd=""
|
|
opts=""
|
|
|
|
for i in ${COMP_WORDS[@]}
|
|
do
|
|
case "${cmd},${i}" in
|
|
",$1")
|
|
cmd="my__app"
|
|
;;
|
|
my__app,bar)
|
|
cmd="my__app__bar"
|
|
;;
|
|
my__app,foo)
|
|
cmd="my__app__foo"
|
|
;;
|
|
my__app,help)
|
|
cmd="my__app__help"
|
|
;;
|
|
my__app__help,bar)
|
|
cmd="my__app__help__bar"
|
|
;;
|
|
my__app__help,foo)
|
|
cmd="my__app__help__foo"
|
|
;;
|
|
my__app__help,help)
|
|
cmd="my__app__help__help"
|
|
;;
|
|
*)
|
|
;;
|
|
esac
|
|
done
|
|
|
|
case "${cmd}" in
|
|
my__app)
|
|
opts="-h --help [free] foo bar 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__bar)
|
|
opts="-h --help"
|
|
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__foo)
|
|
opts="-h --help"
|
|
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__help)
|
|
opts="foo bar help"
|
|
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__help__bar)
|
|
opts=""
|
|
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
|
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
|
return 0
|
|
fi
|
|
case "${prev}" in
|
|
*)
|
|
COMPREPLY=()
|
|
;;
|
|
esac
|
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
|
return 0
|
|
;;
|
|
my__app__help__foo)
|
|
opts=""
|
|
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
|
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
|
return 0
|
|
fi
|
|
case "${prev}" in
|
|
*)
|
|
COMPREPLY=()
|
|
;;
|
|
esac
|
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
|
return 0
|
|
;;
|
|
my__app__help__help)
|
|
opts=""
|
|
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
|
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
|
return 0
|
|
fi
|
|
case "${prev}" in
|
|
*)
|
|
COMPREPLY=()
|
|
;;
|
|
esac
|
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
|
return 0
|
|
;;
|
|
esac
|
|
}
|
|
|
|
if [[ "${BASH_VERSINFO[0]}" -eq 4 && "${BASH_VERSINFO[1]}" -ge 4 || "${BASH_VERSINFO[0]}" -gt 4 ]]; then
|
|
complete -F _my-app -o nosort -o bashdefault -o default my-app
|
|
else
|
|
complete -F _my-app -o bashdefault -o default my-app
|
|
fi
|