diff --git a/src/bash_completion/rbd b/src/bash_completion/rbd index 5e9a7335766ef..bef1670e9a28b 100644 --- a/src/bash_completion/rbd +++ b/src/bash_completion/rbd @@ -8,41 +8,76 @@ # License version 2.1, as published by the Free Software # Foundation. See file COPYING. # +_rbd_commands="" # lazy init +_rbd_global_options="" # lazy init _rbd() { - local cur prev + if [ "x${_rbd_commands}" == "x" ]; then + local rbc="$(rbd bash-completion 2>/dev/null)" + _rbd_commands="$(echo ${rbc} | sed -e 's/|-[^|]*//g' -e 's/||*/|/g')" + _rbd_global_options="$(echo ${rbc} | sed -e 's/|[^-][^\|]*//g' -e 's/||*/|/g')" + fi COMPREPLY=() - cur="${COMP_WORDS[COMP_CWORD]}" - prev="${COMP_WORDS[COMP_CWORD-1]}" - - if [[ ${cur} == -* ]] ; then - COMPREPLY=( $(compgen -W "-c --conf -m -d -f -p --pool --snap -i -o --image --dest --dest-pool --path --size --id --keyfile" -- ${cur}) ) - return 0 - fi - - case "${prev}" in - --conf | -c | --path | --keyfile | --keyring) - COMPREPLY=( $(compgen -f ${cur}) ) - return 0 - ;; - -m) - COMPREPLY=( $(compgen -A hostname ${cur}) ) - return 0 - ;; - snap) - COMPREPLY=( $(compgen -W "ls create rollback rm purge protect unprotect" -- ${cur}) ) - return 0 - ;; - lock) - COMPREPLY=( $(compgen -W "list add remove" -- ${cur}) ) - return 0 - ;; - rbd) - COMPREPLY=( $(compgen -W "ls list info create clone flatten resize rm export import diff export-diff import-diff cp copy mv rename snap watch lock bench-write map unmap showmapped" -- ${cur}) ) - return 0 - ;; - esac + + local arg_count=${#COMP_WORDS[@]} + local args=() + local help_request="false" + for (( i=1; i