#
# Ceph - scalable distributed file system
#
-# Copyright (C) 2011 Wido den Hollander <wido@widodh.nl>
-#
# This is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License version 2.1, as published by the Free Software
-# Foundation. See file COPYING.
+# Foundation.
#
_ceph()
{
- local cur prev
-
- COMPREPLY=()
- cur="${COMP_WORDS[COMP_CWORD]}"
- prev="${COMP_WORDS[COMP_CWORD-1]}"
- prevprev="${COMP_WORDS[COMP_CWORD-2]}"
+ local options_noarg="-h --help -s --status -w --watch --watch-debug --watch-info --watch-sec --watch-warn --watch-error --version -v --verbose --concise"
+ local options_arg="-c --conf -i --in-file -o --out-file --id --user -n --name --cluster --admin-daemon --admin-socket -f --format --connect-timeout"
+ local cnt=${#COMP_WORDS[@]}
+ local cur=${COMP_WORDS[COMP_CWORD]}
+ local prev=${COMP_WORDS[COMP_CWORD-1]}
- if [[ ${cur} == -* ]] ; then
- COMPREPLY=( $(compgen -W "--conf -c --name --id -m --version -s --status -w --watch -o --out-file -i --in-file" -- ${cur}) )
- return 0
- fi
+ if [[ " -c --conf -i --in-file -o --out-file " =~ " ${prev} " ]]
+ then
+ #default autocomplete for options (file autocomplete)
+ compopt -o default
+ COMPREPLY=()
+ return 0
+ fi
+ if [[ "${cur:0:1}" == "-" ]] ;
+ then
+ COMPREPLY=( $(compgen -W "${options_noarg} ${options_arg}" -- $cur) )
+ return 0
+ fi
+ declare -A hint_args
+ for (( i=1 ; i<cnt ; i++ ))
+ do
+ #skip this word if it is option
+ if [[ " ${options_noarg} " =~ " ${COMP_WORDS[i]} " ]]
+ then
+ continue
+ fi
+ #skip this word and next if it is option with arg
+ if [[ " ${options_arg} " =~ " ${COMP_WORDS[i]} " ]]
+ then
+ ((i++));
+ continue
+ fi
+ hint_args[$((i-1))]="${COMP_WORDS[i]}"
+ done
- case "${prev}" in
- -o | --out-file | -i | --in-file | --conf | -c)
- COMPREPLY=( $(compgen -f ${cur}) )
- return 0
- ;;
- -m)
- COMPREPLY=( $(compgen -A hostname ${cur}) )
- return 0
- ;;
- auth)
- COMPREPLY=( $(compgen -W "list add del print_key print-key export get get-key import get-or-create get-or-create-key" -- ${cur}) )
- return 0
- ;;
- pg)
- COMPREPLY=( $(compgen -W "stat dump dump_json dump_stuck force_create_pg getmap map send_pg_creates scrub deep-scrub repair" -- ${cur}) )
- return 0
- ;;
- osd)
- COMPREPLY=( $(compgen -W "stat pool dump getmaxosd tree getmap getcrushmap lspools reweight-by-utilization trash tier" -- ${cur}) )
- return 0
- ;;
- mon)
- COMPREPLY=( $(compgen -W "stat getmap add remove dump" -- ${cur}) )
- return 0
- ;;
- mds)
- COMPREPLY=( $(compgen -W "stat stat getmap dump compat" -- ${cur}) )
- return 0
- ;;
- pool)
- COMPREPLY=( $(compgen -W "create delete rename stats set set-quota get rmsnap mksnap" -- ${cur}) )
- return 0
- ;;
- health)
- COMPREPLY=( $(compgen -W "detail" -- ${cur}) )
- return 0
- ;;
- tier)
- COMPREPLY=( $(compgen -W "remove cache-mode" -- ${cur}) )
- return 0
- ;;
- ceph)
- COMPREPLY=( $(compgen -W "osd mon mds pg auth health df" -- ${cur}) )
- return 0
- ;;
- esac
+ local IFS=$'\n'
+ COMPREPLY=( $(${COMP_WORDS[0]} --completion "${hint_args[@]}" 2>/dev/null) )
}
complete -F _ceph ceph