# bash completion for vagrant                              -*- shell-script -*-

_vagrant()
{
    local cur prev words cword
    _init_completion || return

    local command options

    commands="box destroy halt init package plugin provision reload resume \
        ssh ssh-config status suspend up"

    if [[ $cword -eq 1 ]] ; then
        COMPREPLY=( $( compgen -W "$commands -h --help -v --version" -- "$cur" ) )
    else
        command=${words[1]}
        case $command in
            box)
                _count_args
                case $args in
                    2)
                        options='add list remove repackage'
                        ;;
                    3)
                        subcommand=${words[2]}
                        case $subcommand in
                            add)
                                options='-f --force --insecure --provider'
                                ;;
                        esac
                        ;;
                esac
                ;;
            destroy|halt)
                options='-f --force'
                ;;
            init|resume|status|suspend)
                options=''
                ;;
            package)
                options='--base --include --output --vagrantfile'
                ;;
            plugin)
                _count_args
                case $args in
                    2)
                        options='install license list uninstall'
                        ;;
                    3)
                        subcommand=${words[2]}
                        case $subcommand in
                            install)
                                options='--entry-point --plugin-prerelease --plugin-source --plugin-version'
                                ;;
                        esac
                        ;;
                esac
                ;;
            provision)
                options='--provision-with'
                ;;
            reload)
                options='--no-provision --provision --provision-with'
                ;;
            ssh)
                options='-c --command -p --plain'
                ;;
            ssh-config)
                options='--host'
                ;;
            up)
                options='--no-provision --provision --provision-with --no-parallel --parallel --provider'
                ;;
        esac
        COMPREPLY=( $( compgen -W "$options -h --help" -- "$cur" ) )
    fi

   return 0
} &&
complete -F _vagrant vagrant

# ex: ts=4 sw=4 et filetype=sh
