source /usr/lib/l3vm/l3vm_lib.sh

MANAGE_OPTIONS="--update --ssh-keys --change-password --error-report --templates --supported-templates --allow-running --allow-force-off --stop-on-error --debug --help"

_l3vmadm() {
    if [ "${#COMP_WORDS[@]}" -le 2 ] || [ "$COMP_CWORD" = 1 ]; then
        COMPREPLY=( $(compgen -W "manage cleanup" -- "${COMP_WORDS[COMP_CWORD]}") )
        return
    fi
    case "${COMP_WORDS[1]}" in
        manage)
            if [ "${COMP_CWORD}" -eq 2 ]; then
                COMPREPLY=( $(compgen -W "${MANAGE_OPTIONS}" -- "${COMP_WORDS[COMP_CWORD]}") )
            else
	            list_clones &> /dev/null
                COMPREPLY=( $(compgen -W "${MANAGE_OPTIONS} ${CLONES[*]}" -- "${COMP_WORDS[COMP_CWORD]}") )
            fi
        ;;
        cleanup)
            COMPREPLY=( $(compgen -W "--no-confirm --dryrun --regexp --allow-running --no-grace-period --debug --help" -- "${COMP_WORDS[COMP_CWORD]}") )

    esac

}

complete -F _l3vmadm l3vmadm
