#!/usr/bin/env zsh
# Command completion for caupain
# Generated by Clikt

autoload -Uz compinit
compinit
autoload -Uz bashcompinit
bashcompinit

__skip_opt_eq() {
    # this takes advantage of the fact that bash functions can write to local
    # variables in their callers
    (( i = i + 1 ))
    if [[ "${COMP_WORDS[$i]}" == '=' ]]; then
          (( i = i + 1 ))
    fi
}

__complete_files() {
   # Generate filename completions
   local word="$1"
   local IFS=$'\n'

   # quote each completion to support spaces and special characters
   COMPREPLY=($(compgen -o filenames -f -- "$word" | while read -r line; do
       printf "%q\n" "$line"
   done))
}

_caupain() {
  local i=1
  local in_param=''
  local fixed_arg_names=()
  local vararg_name=''
  local can_parse_options=1

  while [[ ${i} -lt $COMP_CWORD ]]; do
    if [[ ${can_parse_options} -eq 1 ]]; then
      case "${COMP_WORDS[$i]}" in
        --)
          can_parse_options=0
          (( i = i + 1 ));
          continue
          ;;
        -i|--version-catalog)
          __skip_opt_eq
          (( i = i + 1 ))
          [[ ${i} -gt COMP_CWORD ]] && in_param='--version-catalog' || in_param=''
          continue
          ;;
        --gradle-wrapper-properties)
          __skip_opt_eq
          (( i = i + 1 ))
          [[ ${i} -gt COMP_CWORD ]] && in_param='--gradle-wrapper-properties' || in_param=''
          continue
          ;;
        -e|--excluded)
          __skip_opt_eq
          (( i = i + 1 ))
          [[ ${i} -gt COMP_CWORD ]] && in_param='--excluded' || in_param=''
          continue
          ;;
        -c|--config)
          __skip_opt_eq
          (( i = i + 1 ))
          [[ ${i} -gt COMP_CWORD ]] && in_param='--config' || in_param=''
          continue
          ;;
        --policy-plugin-dir)
          __skip_opt_eq
          (( i = i + 1 ))
          [[ ${i} -gt COMP_CWORD ]] && in_param='--policy-plugin-dir' || in_param=''
          continue
          ;;
        -p|--policy)
          __skip_opt_eq
          (( i = i + 1 ))
          [[ ${i} -gt COMP_CWORD ]] && in_param='--policy' || in_param=''
          continue
          ;;
        --list-policies)
          __skip_opt_eq
          in_param=''
          continue
          ;;
        --gradle-stability-level)
          __skip_opt_eq
          (( i = i + 1 ))
          [[ ${i} -gt COMP_CWORD ]] && in_param='--gradle-stability-level' || in_param=''
          continue
          ;;
        -t|--output-type)
          __skip_opt_eq
          (( i = i + 1 ))
          [[ ${i} -gt COMP_CWORD ]] && in_param='--output-type' || in_param=''
          continue
          ;;
        -o|--output)
          __skip_opt_eq
          (( i = i + 1 ))
          [[ ${i} -gt COMP_CWORD ]] && in_param='--output' || in_param=''
          continue
          ;;
        --show-version-references)
          __skip_opt_eq
          in_param=''
          continue
          ;;
        --in-place)
          __skip_opt_eq
          in_param=''
          continue
          ;;
        --cache-dir)
          __skip_opt_eq
          (( i = i + 1 ))
          [[ ${i} -gt COMP_CWORD ]] && in_param='--cache-dir' || in_param=''
          continue
          ;;
        --no--cache)
          __skip_opt_eq
          in_param=''
          continue
          ;;
        -q|--quiet)
          __skip_opt_eq
          in_param=''
          continue
          ;;
        -v|--verbose)
          __skip_opt_eq
          in_param=''
          continue
          ;;
        -d|--debug)
          __skip_opt_eq
          in_param=''
          continue
          ;;
        --debug-http-calls)
          __skip_opt_eq
          in_param=''
          continue
          ;;
        --version)
          __skip_opt_eq
          in_param=''
          continue
          ;;
        -h|--help)
          __skip_opt_eq
          in_param=''
          continue
          ;;
      esac
    fi
    case "${COMP_WORDS[$i]}" in
      *)
        (( i = i + 1 ))
        # drop the head of the array
        fixed_arg_names=("${fixed_arg_names[@]:1}")
        ;;
    esac
  done
  local word="${COMP_WORDS[$COMP_CWORD]}"
  if [[ "${word}" =~ ^[-] ]]; then
    COMPREPLY=($(compgen -W '-i --version-catalog --gradle-wrapper-properties -e --excluded -c --config --policy-plugin-dir -p --policy --list-policies --gradle-stability-level -t --output-type -o --output --show-version-references --in-place --cache-dir --no--cache -q --quiet -v --verbose -d --debug --debug-http-calls --version -h --help' -- "${word}"))
    return
  fi

  # We're either at an option's value, or the first remaining fixed size
  # arg, or the vararg if there are no fixed args left
  [[ -z "${in_param}" ]] && in_param=${fixed_arg_names[0]}
  [[ -z "${in_param}" ]] && in_param=${vararg_name}

  case "${in_param}" in
    "--version-catalog")
       __complete_files "${word}"
      ;;
    "--gradle-wrapper-properties")
       __complete_files "${word}"
      ;;
    "--excluded")
      ;;
    "--config")
       __complete_files "${word}"
      ;;
    "--policy-plugin-dir")
       __complete_files "${word}"
      ;;
    "--policy")
      ;;
    "--list-policies")
      ;;
    "--gradle-stability-level")
      COMPREPLY=($(compgen -W 'stable rc milestone release-nightly nightly' -- "${word}"))
      ;;
    "--output-type")
      COMPREPLY=($(compgen -W 'console html markdown json' -- "${word}"))
      ;;
    "--output")
       __complete_files "${word}"
      ;;
    "--show-version-references")
      ;;
    "--in-place")
      ;;
    "--cache-dir")
       __complete_files "${word}"
      ;;
    "--no--cache")
      ;;
    "--quiet")
      ;;
    "--verbose")
      ;;
    "--debug")
      ;;
    "--debug-http-calls")
      ;;
    "--version")
      ;;
    "--help")
      ;;
  esac
}

complete -F _caupain caupain
