#compdef gengo

autoload -U is-at-least

_gengo() {
  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[@]}" : \
    '(-l)--read-limit[The maximum number of bytes to read from each file (default: 1048576)]:READ_LIMIT:' \
    '(--read-limit)-l[The maximum number of bytes to read from each file (default: 1048576)]:READ_LIMIT:' \
    '(-a)--all[Report on all files, even if they are not detectable]' \
    '(-all)-a[Report on all files, even if they are not detectable]' \
    '(-b)--breakdown[Include detailed statistics for each language]' \
    '(--breakdown)-b[Include detailed statistics for each language]' \
    '--color[Control when colors are displayed (default: auto)]:COLOR:(auto ansi always never)' \
    '(-F)--format[The format to use for output (default: pretty)]:FORMAT:(pretty json)' \
    '(--format)-F[The format to use for output (default: pretty)]:FORMAT:(pretty json)' \
    '(-h)--help[Print help (see a summary with -h)]' \
    '(--help)-h[Print help (see a summary with -h)]' \
    '(-V)--version[Print version]' \
    '(--version)-V[Print version]' \
    '1: :_gengo_commands' \
    '*:: :->command_args' && ret=0

case "$state" in
  (command_args)
    case $words[1] in
      (git)
        _arguments \
          '-R[The path to the repository to analyze (default: .)]:REPOSITORY:' \
          '--repository[The path to the repository to analyze (default: .)]:REPOSITORY:' \
          '-r[The git revision to analyze (default: HEAD)]:REVISION:' \
          '--rev[The git revision to analyze (default: HEAD)]:REVISION:' \
          '-h[Print help]' \
          '--help[Print help]' \
          '-V[Print version]' \
          '--version[Print version]' \
        && ret=0
        ;;
      (directory)
        _arguments \
          '-D[The path to the directory to analyze (default: .)]:directory:' \
          '--directory[The path to the directory to analyze (default: .)]:directory:' \
          '-h[Print help]' \
          '--help[Print help]' \
          '-V[Print version]' \
          '--version[Print version]' \
        && ret=0
        ;;
    esac
  ;;
esac

return ret
}

(( $+functions[_gengo_commands] )) ||
_gengo_commands() {
  local -a commands
  commands=(
    'git:Analyze a git repository'
    'directory:Analyze a directory'
    'help:Print this message or the help of the given subcommand(s)'
  )
  _describe 'command' commands
}

_gengo "$@"
