# Note that in case we change the name of this file, make sure to change it also in postinstall.js
_ow_autocomplete()
{
    local cur prev

    # COMP_WORDS is an array of words in the current command line.
    # COMP_CWORD is the "current word number" - the index of the word we are completing in COMP_WORDS.

    cur=${COMP_WORDS[COMP_CWORD]}
    prev=${COMP_WORDS[COMP_CWORD-1]}

    case ${COMP_CWORD} in
        1)
            COMPREPLY=($(compgen -W "client config dev opk" -- ${cur}))
            ;;
        2)
            # here we display the subcomands for when the command was already typed
            case ${prev} in
                opk)
                    COMPREPLY=($(compgen -W "pack release sign upload" -- ${cur}))
                    ;;
                dev)
                    COMPREPLY=($(compgen -W "config sign-opk" -- ${cur}))
                    ;;
                client)
                    COMPREPLY=($(compgen -W "calculate-opk-uid calc-uid" -- ${cur}))
                    ;;
            esac
            ;;
        *)
            COMPREPLY=()
            ;;
    esac
}

complete -F _ow_autocomplete ow