#compdef fmerge

autoload -U is-at-least

_fmerge() {
    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[@]}" : \
'-e[enables experimental features]' \
'--experimental[enables experimental features]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
":: :_fmerge_commands" \
"*::: :->fmerge" \
&& ret=0
    case $state in
    (fmerge)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:fmerge-command-$line[1]:"
        case $line[1] in
            (man)
_arguments "${_arguments_options[@]}" : \
'-o+[]: :_default' \
'--out=[]: :_default' \
'-f+[]: :(manpages markdown)' \
'--format=[]: :(manpages markdown)' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
&& ret=0
;;
(autocomplete)
_arguments "${_arguments_options[@]}" : \
'-o+[]: :_default' \
'--out=[]: :_default' \
'-s+[]: :(bash zsh fish elvish powershell)' \
'--shell=[]: :(bash zsh fish elvish powershell)' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
&& ret=0
;;
(merge)
_arguments "${_arguments_options[@]}" : \
'-f+[]: :_default' \
'--file=[]: :_default' \
'-r+[]: :_default' \
'--regex=[]: :_default' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
":: :_fmerge__help_commands" \
"*::: :->help" \
&& ret=0

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

(( $+functions[_fmerge_commands] )) ||
_fmerge_commands() {
    local commands; commands=(
'man:Renders the manual.' \
'autocomplete:Renders shell completion scripts.' \
'merge:Merge.' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'fmerge commands' commands "$@"
}
(( $+functions[_fmerge__autocomplete_commands] )) ||
_fmerge__autocomplete_commands() {
    local commands; commands=()
    _describe -t commands 'fmerge autocomplete commands' commands "$@"
}
(( $+functions[_fmerge__help_commands] )) ||
_fmerge__help_commands() {
    local commands; commands=(
'man:Renders the manual.' \
'autocomplete:Renders shell completion scripts.' \
'merge:Merge.' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'fmerge help commands' commands "$@"
}
(( $+functions[_fmerge__help__autocomplete_commands] )) ||
_fmerge__help__autocomplete_commands() {
    local commands; commands=()
    _describe -t commands 'fmerge help autocomplete commands' commands "$@"
}
(( $+functions[_fmerge__help__help_commands] )) ||
_fmerge__help__help_commands() {
    local commands; commands=()
    _describe -t commands 'fmerge help help commands' commands "$@"
}
(( $+functions[_fmerge__help__man_commands] )) ||
_fmerge__help__man_commands() {
    local commands; commands=()
    _describe -t commands 'fmerge help man commands' commands "$@"
}
(( $+functions[_fmerge__help__merge_commands] )) ||
_fmerge__help__merge_commands() {
    local commands; commands=()
    _describe -t commands 'fmerge help merge commands' commands "$@"
}
(( $+functions[_fmerge__man_commands] )) ||
_fmerge__man_commands() {
    local commands; commands=()
    _describe -t commands 'fmerge man commands' commands "$@"
}
(( $+functions[_fmerge__merge_commands] )) ||
_fmerge__merge_commands() {
    local commands; commands=()
    _describe -t commands 'fmerge merge commands' commands "$@"
}

if [ "$funcstack[1]" = "_fmerge" ]; then
    _fmerge "$@"
else
    compdef _fmerge fmerge
fi
