#compdef mdcat

autoload -U is-at-least

_mdcat() {
    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[@]}" \
":: :_mdcat_commands" \
"*::: :->mdcat" \
&& ret=0
    case $state in
    (mdcat)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:mdcat-command-$line[1]:"
        case $line[1] in
            (mdcat)
_arguments "${_arguments_options[@]}" \
'--columns=[Maximum number of columns to use for output]:COLUMNS: ' \
'-c[Disable all colours and other styles]' \
'--no-colour[Disable all colours and other styles]' \
'-l[Do not load remote resources like images]' \
'--local[Do not load remote resources like images]' \
'--fail[Exit immediately if any error occurs processing an input file]' \
'--detect-only[Only detect the terminal type and exit]' \
'(-c --no-colour)--ansi-only[Limit to standard ANSI formatting]' \
'-p[Paginate the output of mdcat with a pager like less]' \
'--paginate[Paginate the output of mdcat with a pager like less]' \
'-P[Do not paginate output (default). Overrides an earlier --paginate]' \
'--no-pager[Do not paginate output (default). Overrides an earlier --paginate]' \
'-h[Print help information]' \
'--help[Print help information]' \
'-V[Print version information]' \
'--version[Print version information]' \
'*::filenames -- Files to read.  If - read from standard input instead:_files' \
&& ret=0
;;
(mdless)
_arguments "${_arguments_options[@]}" \
'--columns=[Maximum number of columns to use for output]:COLUMNS: ' \
'-c[Disable all colours and other styles]' \
'--no-colour[Disable all colours and other styles]' \
'-l[Do not load remote resources like images]' \
'--local[Do not load remote resources like images]' \
'--fail[Exit immediately if any error occurs processing an input file]' \
'--detect-only[Only detect the terminal type and exit]' \
'(-c --no-colour)--ansi-only[Limit to standard ANSI formatting]' \
'-P[Do not paginate output]' \
'--no-pager[Do not paginate output]' \
'-p[Paginate the output of mdcat with a pager like less (default). Overrides an earlier --no-pager]' \
'--paginate[Paginate the output of mdcat with a pager like less (default). Overrides an earlier --no-pager]' \
'-h[Print help information]' \
'--help[Print help information]' \
'-V[Print version information]' \
'--version[Print version information]' \
'*::filenames -- Files to read.  If - read from standard input instead:_files' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" \
":: :_mdcat__help_commands" \
"*::: :->help" \
&& ret=0

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

(( $+functions[_mdcat_commands] )) ||
_mdcat_commands() {
    local commands; commands=(
'mdcat:cat for markdown: Show markdown documents in terminals' \
'mdless:cat for markdown: Show markdown documents in terminals' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'mdcat commands' commands "$@"
}
(( $+functions[_mdcat__help_commands] )) ||
_mdcat__help_commands() {
    local commands; commands=(
'mdcat:cat for markdown: Show markdown documents in terminals' \
'mdless:cat for markdown: Show markdown documents in terminals' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'mdcat help commands' commands "$@"
}
(( $+functions[_mdcat__help__help_commands] )) ||
_mdcat__help__help_commands() {
    local commands; commands=()
    _describe -t commands 'mdcat help help commands' commands "$@"
}
(( $+functions[_mdcat__help__mdcat_commands] )) ||
_mdcat__help__mdcat_commands() {
    local commands; commands=()
    _describe -t commands 'mdcat help mdcat commands' commands "$@"
}
(( $+functions[_mdcat__mdcat_commands] )) ||
_mdcat__mdcat_commands() {
    local commands; commands=()
    _describe -t commands 'mdcat mdcat commands' commands "$@"
}
(( $+functions[_mdcat__help__mdless_commands] )) ||
_mdcat__help__mdless_commands() {
    local commands; commands=()
    _describe -t commands 'mdcat help mdless commands' commands "$@"
}
(( $+functions[_mdcat__mdless_commands] )) ||
_mdcat__mdless_commands() {
    local commands; commands=()
    _describe -t commands 'mdcat mdless commands' commands "$@"
}

_mdcat "$@"
