#!/bin/bash
# completion for some vstorage-mount's commands

_vstorage_mount()
{
	local cur prev
	COMPREPLY=()

	ps_general_options="-l -L -d -C -R -B -S -b -u -g -m -t -a -f"

	cur="${COMP_WORDS[COMP_CWORD]}"
	prev="${COMP_WORDS[COMP_CWORD-1]}"
	
	case $COMP_CWORD in
	1)
		COMPREPLY=( $( compgen -W "-c "  -- "$cur" ) )
		;;
	2)
		case "$prev" in
		-c)
			clusters=`ls /etc/vstorage/clusters`
			COMPREPLY=( $( compgen -W "$clusters" -- "$cur" ) )
			;;
		esac
		;;
	3)
		case "${COMP_WORDS[COMP_CWORD-2]}" in
		-c)
			COMPREPLY=(  $( compgen -d -- "$cur" ) )
			;;
		esac
		;;
	4)
		case "${COMP_WORDS[COMP_CWORD-3]}" in
		-c)
			COMPREPLY=( $( compgen -W "$ps_general_options -v -i -s" -- "$cur") )
			;;
		esac
		;;
	*)
		case "${COMP_WORDS[COMP_CWORD-1]}" in
		-v)
			COMPREPLY=( $( compgen -W "$ps_general_options -i -s" -- "$cur" ) )
			;;
		-i)
			COMPREPLY=( $( compgen -W "$ps_general_options -v -s" -- "$cur" ) )
			;;
		-s)
			COMPREPLY=( $( compgen -W "$ps_general_options -v -i" -- "$cur" ) )
			;;
		-u)
			COMPREPLY=( $( compgen -u -- "$cur" | sed ':a;N;$!ba;s/\n/ /g') )
			;;
		-g)
			COMPREPLY=( $( compgen -g -- "$cur" | sed ':a;N;$!ba;s/\n/ /g') )
			;;
		*)
			COMPREPLY=(  $( compgen -f -d -- "$cur" ) )
			;;
		esac
	esac

	return 0
}

complete -F _vstorage_mount -o nospace vstorage-mount pstorage-mount
