#compdef git-ignore

autoload -U is-at-least

_git-ignore() {
    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 information]' \
'--help[Print help information]' \
'-V[Print version information]' \
'--version[Print version information]' \
'-l[List <templates> or all available templates]' \
'--list[List <templates> or all available templates]' \
'-u[Update templates by fetching them from gitignore.io]' \
'--update[Update templates by fetching them from gitignore.io]' \
'-s[Ignore all user defined aliases and templates]' \
'--simple[Ignore all user defined aliases and templates]' \
'-a[Autodetect templates based on the existing files]' \
'--auto[Autodetect templates based on the existing files]' \
'*::templates -- Names of templates to show/search for:' \
":: :_git-ignore_commands" \
"*::: :->git ignore" \
&& ret=0
    case $state in
    (git ignore)
        words=($line[2] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:git-ignore-command-$line[2]:"
        case $line[2] in
            (alias)
_arguments "${_arguments_options[@]}" \
'-h[Print help information]' \
'--help[Print help information]' \
":: :_git-ignore__alias_commands" \
"*::: :->alias" \
&& ret=0

    case $state in
    (alias)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:git-ignore-alias-command-$line[1]:"
        case $line[1] in
            (list)
_arguments "${_arguments_options[@]}" \
'--version[Print version information]' \
'-h[Print help information]' \
'--help[Print help information]' \
&& ret=0
;;
(add)
_arguments "${_arguments_options[@]}" \
'--version[Print version information]' \
'-h[Print help information]' \
'--help[Print help information]' \
':name:' \
'*::aliases:' \
&& ret=0
;;
(remove)
_arguments "${_arguments_options[@]}" \
'--version[Print version information]' \
'-h[Print help information]' \
'--help[Print help information]' \
':name:' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" \
'--version[Print version information]' \
'-h[Print help information]' \
'--help[Print help information]' \
&& ret=0
;;
        esac
    ;;
esac
;;
(template)
_arguments "${_arguments_options[@]}" \
'-h[Print help information]' \
'--help[Print help information]' \
":: :_git-ignore__template_commands" \
"*::: :->template" \
&& ret=0

    case $state in
    (template)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:git-ignore-template-command-$line[1]:"
        case $line[1] in
            (list)
_arguments "${_arguments_options[@]}" \
'--version[Print version information]' \
'-h[Print help information]' \
'--help[Print help information]' \
&& ret=0
;;
(add)
_arguments "${_arguments_options[@]}" \
'--version[Print version information]' \
'-h[Print help information]' \
'--help[Print help information]' \
':name:' \
':file-name:' \
&& ret=0
;;
(remove)
_arguments "${_arguments_options[@]}" \
'--version[Print version information]' \
'-h[Print help information]' \
'--help[Print help information]' \
':name:' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" \
'--version[Print version information]' \
'-h[Print help information]' \
'--help[Print help information]' \
&& ret=0
;;
        esac
    ;;
esac
;;
(init)
_arguments "${_arguments_options[@]}" \
'--force[Forcefully create config, possibly overwrite existing]' \
'-h[Print help information]' \
'--help[Print help information]' \
&& ret=0
;;
(completion)
_arguments "${_arguments_options[@]}" \
'-h[Print help information]' \
'--help[Print help information]' \
':shell -- Shell to generate completion for:(bash elvish fish powershell zsh)' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" \
'-h[Print help information]' \
'--help[Print help information]' \
&& ret=0
;;
        esac
    ;;
esac
}

(( $+functions[_git-ignore_commands] )) ||
_git-ignore_commands() {
    local commands; commands=(
'alias:Manage local aliases' \
'template:Manage local templates' \
'init:Initialize user configuration' \
'completion:Generate shell completion' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'git-ignore commands' commands "$@"
}
(( $+functions[_git-ignore__alias__add_commands] )) ||
_git-ignore__alias__add_commands() {
    local commands; commands=()
    _describe -t commands 'git-ignore alias add commands' commands "$@"
}
(( $+functions[_git-ignore__template__add_commands] )) ||
_git-ignore__template__add_commands() {
    local commands; commands=()
    _describe -t commands 'git-ignore template add commands' commands "$@"
}
(( $+functions[_git-ignore__alias_commands] )) ||
_git-ignore__alias_commands() {
    local commands; commands=(
'list:List available aliases' \
'ls:List available aliases' \
'add:Add a new alias' \
'remove:Remove an alias' \
'rm:Remove an alias' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'git-ignore alias commands' commands "$@"
}
(( $+functions[_git-ignore__completion_commands] )) ||
_git-ignore__completion_commands() {
    local commands; commands=()
    _describe -t commands 'git-ignore completion commands' commands "$@"
}
(( $+functions[_git-ignore__alias__help_commands] )) ||
_git-ignore__alias__help_commands() {
    local commands; commands=()
    _describe -t commands 'git-ignore alias help commands' commands "$@"
}
(( $+functions[_git-ignore__help_commands] )) ||
_git-ignore__help_commands() {
    local commands; commands=()
    _describe -t commands 'git-ignore help commands' commands "$@"
}
(( $+functions[_git-ignore__template__help_commands] )) ||
_git-ignore__template__help_commands() {
    local commands; commands=()
    _describe -t commands 'git-ignore template help commands' commands "$@"
}
(( $+functions[_git-ignore__init_commands] )) ||
_git-ignore__init_commands() {
    local commands; commands=()
    _describe -t commands 'git-ignore init commands' commands "$@"
}
(( $+functions[_git-ignore__alias__list_commands] )) ||
_git-ignore__alias__list_commands() {
    local commands; commands=()
    _describe -t commands 'git-ignore alias list commands' commands "$@"
}
(( $+functions[_git-ignore__template__list_commands] )) ||
_git-ignore__template__list_commands() {
    local commands; commands=()
    _describe -t commands 'git-ignore template list commands' commands "$@"
}
(( $+functions[_git-ignore__alias__remove_commands] )) ||
_git-ignore__alias__remove_commands() {
    local commands; commands=()
    _describe -t commands 'git-ignore alias remove commands' commands "$@"
}
(( $+functions[_git-ignore__template__remove_commands] )) ||
_git-ignore__template__remove_commands() {
    local commands; commands=()
    _describe -t commands 'git-ignore template remove commands' commands "$@"
}
(( $+functions[_git-ignore__template_commands] )) ||
_git-ignore__template_commands() {
    local commands; commands=(
'list:List available templates' \
'ls:List available templates' \
'add:Add a new template' \
'remove:Remove a template' \
'rm:Remove a template' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'git-ignore template commands' commands "$@"
}

_git-ignore "$@"