# fwup(1) completion

_fwup()
{
    local cur prev

    COMPREPLY=()
    _get_comp_words_by_ref cur prev

    case $prev in
        -d)
            _filedir
            return 0
            ;;
        -f)
            _filedir '@(conf)'
            return 0
            ;;
        -i|-o)
            _filedir '@(fw)'
            return 0
            ;;
        -p)
            _filedir '@(pub)'
            return 0
            ;;
        -s)
            _filedir '@(priv)'
            return 0
            ;;
        -t|--task)
            # This should call --list on the .fw file, but I'm not
            # sure how to implement that. The following tasks are
            # the most popular by convention.
            COMPREPLY=( $( compgen -W 'complete upgrade' -- "$cur" ) )
            return 0
            ;;
    esac

    if [[ "$cur" == -* ]] ; then
        COMPREPLY=( $( compgen -W '-a --apply -c --create \
                -d -D --detect -E --eject --no-eject -f -F -g --gen-keys -i \
                -l --list -m --metadata -n -o -p -q --quiet -s -S --sign \
                -t --task -u --unmount -U --no-unmount -v --verbose \
                -V --verify --version -y -z' \
                -- "$cur" ) )
    else
            _filedir '@(fw)'
            return 0
    fi

} &&
complete -F _fwup fwup
