#compdef nanopub

autoload -U is-at-least

_nanopub() {
    typeset -A opt_args
    typeset -a _arguments_options
    local ret=1

    if is-at-least 5.2; then
        _arguments_options=(-s -S -C)
    else
        _arguments_options=(-s -C)
    fi

    local context curcontext="$curcontext" state line
    _arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
":: :_nanopub_commands" \
"*::: :->nanopub" \
&& ret=0
    case $state in
    (nanopub)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:nanopub-command-$line[1]:"
        case $line[1] in
            (sign)
_arguments "${_arguments_options[@]}" : \
'-k+[The path to a private key used to sign. Found in ~/.nanopub by default]:PRIVATE_KEY:_default' \
'--key=[The path to a private key used to sign. Found in ~/.nanopub by default]:PRIVATE_KEY:_default' \
'-p+[The path to a profile.yml file. Default\: ~/.nanopub/profile.yml]:PROFILE:_default' \
'--profile=[The path to a profile.yml file. Default\: ~/.nanopub/profile.yml]:PROFILE:_default' \
'-h[Print help]' \
'--help[Print help]' \
':NANOPUB_FILE -- The file to sign:_default' \
&& ret=0
;;
(publish)
_arguments "${_arguments_options[@]}" : \
'-k+[The path to a private key used to sign.]:PRIVATE_KEY:_default' \
'--key=[The path to a private key used to sign.]:PRIVATE_KEY:_default' \
'-p+[The path to a profile.yml file. Default\: ~/.nanopub/profile.yml]:PROFILE:_default' \
'--profile=[The path to a profile.yml file. Default\: ~/.nanopub/profile.yml]:PROFILE:_default' \
'-t[To publish to the test server instead of the Nanopublication network.]' \
'--test[To publish to the test server instead of the Nanopublication network.]' \
'-h[Print help]' \
'--help[Print help]' \
':NANOPUB_FILE -- The file to publish:_default' \
&& ret=0
;;
(check)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
':NANOPUB_FILE -- The file to check:_default' \
&& ret=0
;;
(completions)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
'::SHELL -- The shell to generate scripts for:(bash elvish fish powershell zsh)' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
":: :_nanopub__help_commands" \
"*::: :->help" \
&& ret=0

    case $state in
    (help)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:nanopub-help-command-$line[1]:"
        case $line[1] in
            (sign)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(publish)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(check)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(completions)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
        esac
    ;;
esac
;;
        esac
    ;;
esac
}

(( $+functions[_nanopub_commands] )) ||
_nanopub_commands() {
    local commands; commands=(
'sign:Sign a Nanopub' \
'publish:Sign, publish, or check a Nanopublication (https\://nanopub.net)' \
'check:Check if a Nanopub is valid' \
'completions:Generates completion scripts for your shell' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'nanopub commands' commands "$@"
}
(( $+functions[_nanopub__check_commands] )) ||
_nanopub__check_commands() {
    local commands; commands=()
    _describe -t commands 'nanopub check commands' commands "$@"
}
(( $+functions[_nanopub__completions_commands] )) ||
_nanopub__completions_commands() {
    local commands; commands=()
    _describe -t commands 'nanopub completions commands' commands "$@"
}
(( $+functions[_nanopub__help_commands] )) ||
_nanopub__help_commands() {
    local commands; commands=(
'sign:Sign a Nanopub' \
'publish:Sign, publish, or check a Nanopublication (https\://nanopub.net)' \
'check:Check if a Nanopub is valid' \
'completions:Generates completion scripts for your shell' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'nanopub help commands' commands "$@"
}
(( $+functions[_nanopub__help__check_commands] )) ||
_nanopub__help__check_commands() {
    local commands; commands=()
    _describe -t commands 'nanopub help check commands' commands "$@"
}
(( $+functions[_nanopub__help__completions_commands] )) ||
_nanopub__help__completions_commands() {
    local commands; commands=()
    _describe -t commands 'nanopub help completions commands' commands "$@"
}
(( $+functions[_nanopub__help__help_commands] )) ||
_nanopub__help__help_commands() {
    local commands; commands=()
    _describe -t commands 'nanopub help help commands' commands "$@"
}
(( $+functions[_nanopub__help__publish_commands] )) ||
_nanopub__help__publish_commands() {
    local commands; commands=()
    _describe -t commands 'nanopub help publish commands' commands "$@"
}
(( $+functions[_nanopub__help__sign_commands] )) ||
_nanopub__help__sign_commands() {
    local commands; commands=()
    _describe -t commands 'nanopub help sign commands' commands "$@"
}
(( $+functions[_nanopub__publish_commands] )) ||
_nanopub__publish_commands() {
    local commands; commands=()
    _describe -t commands 'nanopub publish commands' commands "$@"
}
(( $+functions[_nanopub__sign_commands] )) ||
_nanopub__sign_commands() {
    local commands; commands=()
    _describe -t commands 'nanopub sign commands' commands "$@"
}

if [ "$funcstack[1]" = "_nanopub" ]; then
    _nanopub "$@"
else
    compdef _nanopub nanopub
fi
