#compdef manora

autoload -U is-at-least

_manora() {
    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[@]}" : \
'-m[Open a TUI menu that allows searching through local man pages, downloading man pages from <https\://manned.org>, and displaying them as PDF files (default operation)]' \
'--menu[Open a TUI menu that allows searching through local man pages, downloading man pages from <https\://manned.org>, and displaying them as PDF files (default operation)]' \
'-s[Save <man page> into the <file> PDF file; if <file> isn'\''t specified, save it to a "man_<man page>.pdf" file in the current directory; if <file> already exists, ask for a confirmation to overwrite it]' \
'--save[Save <man page> into the <file> PDF file; if <file> isn'\''t specified, save it to a "man_<man page>.pdf" file in the current directory; if <file> already exists, ask for a confirmation to overwrite it]' \
'-d[Skip searching for the man page locally and directly download it from <https\://manned.org> instead; this option can be used when specifying a man page to open as an argument (\`manora --download <man page>\`); or in combination with the \`-s / --save\` option (\`manora --download --save <man page>\`)]' \
'--download[Skip searching for the man page locally and directly download it from <https\://manned.org> instead; this option can be used when specifying a man page to open as an argument (\`manora --download <man page>\`); or in combination with the \`-s / --save\` option (\`manora --download --save <man page>\`)]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
'-V[Print version]' \
'--version[Print version]' \
'::man_page -- Man page to display, download, or save:_default' \
'::file -- Optional destination PDF file to save the man page to with the `--save` option:_files' \
":: :_manora_commands" \
"*::: :->manora" \
&& ret=0
    case $state in
    (manora)
        words=($line[3] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:manora-command-$line[3]:"
        case $line[3] in
            (completion)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
':shell:(bash elvish fish powershell zsh)' \
&& ret=0
;;
(manual)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
":: :_manora__subcmd__help_commands" \
"*::: :->help" \
&& ret=0

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

(( $+functions[_manora_commands] )) ||
_manora_commands() {
    local commands; commands=(
'completion:Generate shell completion for the specified shell' \
'manual:Generate the man page' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'manora commands' commands "$@"
}
(( $+functions[_manora__subcmd__completion_commands] )) ||
_manora__subcmd__completion_commands() {
    local commands; commands=()
    _describe -t commands 'manora completion commands' commands "$@"
}
(( $+functions[_manora__subcmd__help_commands] )) ||
_manora__subcmd__help_commands() {
    local commands; commands=(
'completion:Generate shell completion for the specified shell' \
'manual:Generate the man page' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'manora help commands' commands "$@"
}
(( $+functions[_manora__subcmd__help__subcmd__completion_commands] )) ||
_manora__subcmd__help__subcmd__completion_commands() {
    local commands; commands=()
    _describe -t commands 'manora help completion commands' commands "$@"
}
(( $+functions[_manora__subcmd__help__subcmd__help_commands] )) ||
_manora__subcmd__help__subcmd__help_commands() {
    local commands; commands=()
    _describe -t commands 'manora help help commands' commands "$@"
}
(( $+functions[_manora__subcmd__help__subcmd__manual_commands] )) ||
_manora__subcmd__help__subcmd__manual_commands() {
    local commands; commands=()
    _describe -t commands 'manora help manual commands' commands "$@"
}
(( $+functions[_manora__subcmd__manual_commands] )) ||
_manora__subcmd__manual_commands() {
    local commands; commands=()
    _describe -t commands 'manora manual commands' commands "$@"
}

if [ "$funcstack[1]" = "_manora" ]; then
    _manora "$@"
else
    compdef _manora manora
fi
