#compdef git-sprig

autoload -U is-at-least

_git-sprig() {
    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[@]}" : \
'-C+[Superproject to read the submodules from]:DIR:_files' \
'--repo=[Superproject to read the submodules from]:DIR:_files' \
'--rev=[Revision of the superproject to use]:REV:_default' \
'-b+[Directory the submodule paths are resolved against]:DIR:_files' \
'--basedir=[Directory the submodule paths are resolved against]:DIR:_files' \
'--max-depth=[Levels of submodules to materialize (0 = unlimited)]:N:_default' \
'--remote-url=[Base URL for relative submodule URLs; defaults to the superproject'\''s remote]:URL:_default' \
'*-c+[Configuration for the fetches, like \`git -c\`]:KEY=VALUE:_default' \
'*--config=[Configuration for the fetches, like \`git -c\`]:KEY=VALUE:_default' \
'--tempdir=[Directory for the temporary repositories]:DIR:_files' \
'-j+[Number of submodules fetched at the same time (default\: CPUs, at most 8)]:N:_default' \
'--jobs=[Number of submodules fetched at the same time (default\: CPUs, at most 8)]:N:_default' \
'--generate-completions=[Print shell completions, for \`git sprig\` too, and exit]:SHELL:(bash fish zsh)' \
'--force[Replace submodule directories that have a .git of their own, discarding work in them]' \
'--stage[Replace the submodules in the superproject'\''s index with their files, ready to commit]' \
'--raw[Write files as stored, without .gitattributes conversion]' \
'--no-recursive[Do not recurse into submodules of submodules]' \
'--dry-run[Show what would be fetched without changing anything]' \
'(-v --verbose)-q[Only print errors]' \
'(-v --verbose)--quiet[Only print errors]' \
'-v[Also print how each submodule was fetched and written]' \
'--verbose[Also print how each submodule was fetched and written]' \
'--generate-man[Print the manual page, to install as git-sprig(1), and exit]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
'-V[Print version]' \
'--version[Print version]' \
&& ret=0
}

(( $+functions[_git-sprig_commands] )) ||
_git-sprig_commands() {
    local commands; commands=()
    _describe -t commands 'git-sprig commands' commands "$@"
}

if [ "$funcstack[1]" = "_git-sprig" ]; then
    _git-sprig "$@"
else
    compdef _git-sprig git-sprig
fi
