# waf completion                                       -*- shell-script -*-

_waf()
{
    #local sourcesdir="/etc/apt/sources.list.d"
    local cur prev words cword
    _init_completion || return

    local GENERIC_WAF_OPTIONS='
        --version
        -c --colors
        -j --jobs
        -k --keep
        -v --verbose
        -z --zones
        -h --help
        --wtools-version
    '

    # see if the user selected a command already
    local COMMANDS=(
        "audit"
        "build"
        "check"
        "clangdb"
        "clean" "distclean"
        "configure"
        "dist" "distcheck"
        "eclipse"
        "install"
        "lint"
        "list"
        "shell"
        "step"
        "test"
        "uninstall")

    local command i
    for (( i=0; i < ${#words[@]}-1; i++ )); do
        if [[ ${COMMANDS[@]} =~ ${words[i]} ]]; then
            command=${words[i]}
            break
        fi
    done

    # supported options per command
    if [[ "$cur" == -* ]]; then
        case $command in
            configure)
                COMPREPLY=( $( compgen -W '
                    --out
                    --top
                    --prefix
                    --bindir
                    --libdir
                    --with-prefix-map
                    --prefix-map-path
                    --srcinstdir
                    --check-c-compiler
                    --check-cxx-compiler
                    --clang-tidy-config
                    --pylint-config
                    --checkstyle-config
                    --mode
                    --sanitize
                    --jtpath
                    --jtrunner
                    --boost-includes
                    --boost-libs
                    --boost-mt
                    --boost-abi
                    --boost-linkage_autodetect
                    --boost-toolset
                    --nopyc
                    --nopycache
                    --pythondir
                    --pythonarchdir
                    --gcovr-no-generated
                    --gcovr-html-high
                    --gcovr-html-medium
                    --with-sphinx-formats
                    '"$GENERIC_WAF_OPTIONS" -- "$cur" ) )
                return 0
                ;;
            build)
                COMPREPLY=( $( compgen -W '
                    --progress
                    --targets
                    --with-docs
                    --monitor
                    '"$GENERIC_WAF_OPTIONS" -- "$cur" ) )
                return 0
                ;;
            step)
                COMPREPLY=( $( compgen -W '
                    --files
                    '"$GENERIC_WAF_OPTIONS" -- "$cur" ) )
                return 0
                ;;
            lint)
                COMPREPLY=( $( compgen -W '
                    --lintall
                    '"$GENERIC_WAF_OPTIONS" -- "$cur" ) )
                return 0
                ;;
            test)
                COMPREPLY=( $( compgen -W '
                    --notests
                    --alltests
                    --test-fail-fatal
                    --testcmd
                    --dump-test-script
                    --clear-failed
                    --valgrind
                    --monitor
                    --gcovr-no-generated
                    --gcovr-html-high
                    --gcovr-html-medium
                    '"$GENERIC_WAF_OPTIONS" -- "$cur" ) )
                return 0
                ;;
            install)
                COMPREPLY=( $( compgen -W '
                    --destdir
                    --force
                    --distcheck-args
                    --progress
                    --targets
                    --with-docs
                    --monitor
                    '"$GENERIC_WAF_OPTIONS" -- "$cur" ) )
                return 0
                ;;
            uninstall)
                COMPREPLY=( $( compgen -W '
                    --destdir
                    --force
                    --distcheck-args
                    '"$GENERIC_WAF_OPTIONS" -- "$cur" ) )
                return 0
                ;;
            *)
                COMPREPLY=( $( compgen -W "$GENERIC_WAF_OPTIONS" -- "$cur" ) )
                return 0
                ;;
        esac
    fi

    # show what commands we have
    COMPREPLY=( $( compgen -W '${COMMANDS[@]}' -- "$cur" ) )

    return 0
} &&
complete -F _waf waf

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