# Bash completion script for Carthage.

_carthage() {
    local commands command cur prev
    commands="archive bootstrap build checkout copy-frameworks fetch help outdated update validate version"
    command="${COMP_WORDS[1]}"
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"

    if [ $COMP_CWORD == 1 ]
    then
        COMPREPLY=($(compgen -W "${commands}" -- ${cur}))
        return 0
    fi

    if [ $COMP_CWORD == 2 -a "${command}" == help ]
    then
        COMPREPLY=($(compgen -W "${commands}" -- ${cur}))
        return 0
    fi

    if [[ "${cur}" == -* ]]
    then
        case "${command}" in
            archive)
                COMPREPLY=($(compgen -W '--output --project-directory --color' -- ${cur}))
                return 0
                ;;
            bootstrap|update)
                COMPREPLY=($(compgen -W '--no-checkout --no-build --verbose --configuration \
                    --platform --toolchain --derived-data --use-ssh --use-submodules \
                    --no-use-binaries --color --project-directory --cache-builds' -- ${cur}))
                return 0
                ;;
            build)
                COMPREPLY=($(compgen -W '--configuration --platform --toolchain --derived-data \
                    --no-skip-current --color --verbose --project-directory --cache-builds' -- ${cur}))
                return 0
                ;;
            checkout)
                COMPREPLY=($(compgen -W '--use-ssh --use-submodules --no-use-binaries \
                    --color --project-directory' -- ${cur}))
                return 0
                ;;
            fetch)
                COMPREPLY=($(compgen -W '--color' -- ${cur}))
                return 0
                ;;
            outdated)
                COMPREPLY=($(compgen -W '--use-ssh --verbose --color \
                    --project-directory' -- ${cur}))
                return 0
                ;;
        esac
    fi

    case "${prev}" in
        --output)
            _filedir
            return 0
            ;;
        --project-directory)
            _filedir -d
            return 0
            ;;
        --color)
            COMPREPLY=($(compgen -W 'auto always never' -- ${cur}))
            return 0
            ;;
        --configuration)
            COMPREPLY=($(compgen -W 'Release Debug' -- ${cur}))
            return 0
            ;;
        --platform)
            COMPREPLY=($(compgen -W 'all macOS iOS watchOS tvOS' -- ${cur}))
            return 0
            ;;
        --toolchain)
            COMPREPLY=($(compgen -W 'com.apple.dt.toolchain.Swift_2_3 \
                com.apple.dt.toolchain.XcodeDefault' -- ${cur}))
            return 0
            ;;
        --derived-data)
            _filedir -d
            return 0
            ;;
    esac
}
complete -F _carthage carthage
