_have libscout &&
_libscout()
{
    local cur prev

    COMPREPLY=()
    cur=${COMP_WORDS[COMP_CWORD]}
    prev=${COMP_WORDS[COMP_CWORD-1]}
    opmode=${COMP_WORDS[2]}

    case $prev in
	libscout|LibScout|*/bin/libscout|*/bin/LibScout)
	    # --opmode must be first
            COMPREPLY=( $(compgen -W "--opmode" -- $cur) )
	    return 0;;
        -o|--opmode)
            modes='
                lib_api_analysis
                match
                profile
                updatability
            '
            COMPREPLY=( $(compgen -W "${modes[*]}" -- $cur) )
            return 0;;
	--json-dir|--lib-api-compat-dir|--log-dir|--profiles-dir|--stats-dir)
	    _filedir -d
            return 0;;
	--android-sdk)
	    _filedir jar
            return 0;;
	--library-description)
	    _filedir xml
            return 0;;
	--libscout-conf)
	    _filedir
            return 0;;
        -m|-n|-u|-v|--lib-dependency-analysis|--lib-usage-analysis|--mute|--no-partial-matching|--verbose-profiles)
            return 0;;
    esac
    if [[ "$cur" == -* ]]; then
        opts=' -a -c -d -j -l -m -n -o -p -s -u -v -x '
        lopts='
            --android-sdk
            --json-dir
            --lib-api-compat-dir
            --lib-dependency-analysis
            --library-description
            --libscout-conf
            --lib-usage-analysis
            --log-dir
            --mute
            --no-partial-matching
            --opmode
            --profiles-dir
            --stats-dir
            --verbose-profiles
        '
        COMPREPLY=( $(compgen -W "${opts[*]} ${lopts[*]}" -- $cur) )
    elif [[ "$opmode" == "lib_api_analysis" ]]; then
        _filedir
    elif [[ "$opmode" == "match" || "$opmode" == "updatability" ]]; then
        _filedir -d
    elif [[ "$opmode" == "profile" ]]; then
        _filedir '@(aar|jar)'
    fi
}
complete -F _libscout libscout LibScout

