#
# This is the bash auto completion script for the rhc command
# 
_rhc()
{
    local cur opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"

    if [ $COMP_CWORD -eq 1 ]; then
        opts="domain app sshkey port-forward server setup help"
        COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
    elif [ $COMP_CWORD -eq 2 ]; then
        case "${COMP_WORDS[1]}" in
            domain)
                opts="create show alter destroy"
                ;;
            app)
                opts="create show start stop force-stop restart reload status destroy tidy add-alias remove-alias snapshot tail cartridge"
                ;;
            sshkey)
                opts="add update remove list"
                ;;
            port-forward)
                opts="--debug --help --rhlogin --password --namespace --config --timeout --app"
                ;;
            *)
                opts=""
                ;;
        esac

    elif [ $COMP_CWORD -eq 3 ]; then
        case "${COMP_WORDS[1]}" in
            domain)
                case "${COMP_WORDS[2]}" in
                    create | alter | destroy)
                        opts="--debug --help --rhlogin --password --namespace --config --timeout"
                        ;;
                    show)
                        opts="--debug --help --rhlogin --password --config --timeout"
                        ;;
                    *)
                        ;;
                esac
                ;;
            app)
                case "${COMP_WORDS[2]}" in
                    create)
                        opts="--debug --help --rhlogin --password --no-dns --nogit --app --repo --type --enable-jenkins --config --timeout"
                        ;;
                    show | start | stop | force-stop | restart | reload | status | destroy | tidy | add-alias | remove-alias | destroy )
                        opts="--debug --help --rhlogin --password --app --alias --bypass --config --timeout"
                        ;;
                    tail)
                        opts="--debug --help --rhlogin --password --app --opts --filepath --config --timeout"
                        ;;
                    snapshot)
                        opts="save restore"
                        ;;
                    cartridge)
                        opts="add remove stop start restart status reload list"
                        ;;
                    *)
                        ;;
                esac
                ;;
            sshkey)
                case "${COMP_WORDS[2]}" in
                    add | update)
                        opts="--debug --help --rhlogin --password --identifier --ssh --config --timeout"
                        ;;
                    remove)
                        opts="--debug --help --rhlogin --password --identifier --config --timeout"
                        ;;
                    list)
                        opts="--debug --help --rhlogin --password --config --timeout"
                        ;;
                    *)
                        ;;
                esac
                ;;
        esac

    elif [ $COMP_CWORD -eq 4 ]; then
        case "${COMP_WORDS[1]}" in
            app)
                case "${COMP_WORDS[2]}" in
                    snapshot)
                        case "${COMP_WORDS[3]}" in
                            save | restore)
                                opts="--debug --help --rhlogin --password --app --filepath --config --timeout"
                                ;;
                            *)
                                ;;
                        esac
                        ;;
                    cartridge)
                        case "${COMP_WORDS[3]}" in
                            add | remove | stop | start | restart | status | reload | list)
                                opts="--debug --help --rhlogin --password --app --cartridge --config --timeout"
                                ;;
                            *)
                                ;;
                        esac
                        ;;
                esac
                ;;
        esac

    fi

   if [ ${#opts[@]} -gt 0 ]; then COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ); fi
   return 0
}
complete -o default -F _rhc rhc
