# Bash completion for appctl. Source this from your ~/.bashrc:
#   source /path/to/sprint_planer_web/bin/appctl-completion.bash
# `appctl` will offer to add that line on first run.

_appctl_complete() {
    local cur prev cword
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    cword="${COMP_CWORD}"
    prev="${COMP_WORDS[cword-1]}"

    local top="dev prod lint test check completion help"

    if (( cword == 1 )); then
        # shellcheck disable=SC2207
        COMPREPLY=( $(compgen -W "${top}" -- "${cur}") )
        return 0
    fi

    if (( cword == 2 )); then
        case "${COMP_WORDS[1]}" in
            dev)
                # shellcheck disable=SC2207
                COMPREPLY=( $(compgen -W "start stop build shell logs" -- "${cur}") )
                return 0
                ;;
            prod)
                # shellcheck disable=SC2207
                COMPREPLY=( $(compgen -W "start stop build" -- "${cur}") )
                return 0
                ;;
        esac
    fi

    return 0
}

complete -F _appctl_complete appctl
complete -F _appctl_complete ./appctl
