# jsign completion

have jsign &&
_jsign()
{
    COMPREPLY=()
    local cur prev
    _get_comp_words_by_ref cur prev

    local opts="-s --keystore --storepass --storetype -a --alias --keypass --keyfile -c --certfile -t --tsaurl -r --tsretries -w --tsretrywait -n --name -u --url -h --replace -e --encoding --help"

    if [[ "$cur" == -* ]]; then
        COMPREPLY=( $(compgen -W "${opts}" -- "$cur") )
        return 0
    fi

    local pattern="!*.@(exe|dll|cpl|ocx|sys|scr|drv|ps1|psm1|psd1|msi|msp|cab|cat)"

    case $prev in
        -s|--keystore|--keyfile|-c|--certfile)
            _filedir
            return 0
            ;;
        --storetype)
            COMPREPLY=( $( compgen -W 'JKS JCEKS PKCS12 PKCS11 AWS AZUREKEYVAULT DIGICERTONE ESIGNER GOOGLECLOUD HASHICORPVAULT YUBIKEY NITROKEY OPENPGP OPENSC' -- "$cur" ) )
            return 0
            ;;
        --storepass|-a|--alias|--keypass|-t|--tsaurl|-r|--tsretries|-w|--tsretrywait|-n|--name|-u|--url|-e|--encoding)
            # argument required but no completions available
            return 0
            ;;
        -h|--help)
            # no argument
            return 0
            ;;
    esac

    COMPREPLY=( $( compgen -f -X "$pattern" -- "$cur" ) $( compgen -d -- "$cur" ) )

} &&
complete -F _jsign -o filenames jsign
