# This script was generated by crazy-complete.
# crazy-complete: A tool that creates robust and reliable autocompletion scripts for Bash, Fish and Zsh.
# For more information, visit: https://github.com/crazy-complete/crazy-complete

_crazy-complete__value_list() {
  local separator="$1"; shift

  if [[ -z "$cur" ]]; then
    COMPREPLY=("$@")
    return
  fi

  local value having_value found_value
  local -a having_values remaining_values

  IFS="$separator" read -r -a having_values <<< "$cur"

  for value; do
    found_value=0

    for having_value in "${having_values[@]}"; do
      if [[ "$value" == "$having_value" ]]; then
        found_value=1
        break
      fi
    done

    if (( ! found_value )); then
      remaining_values+=("$value")
    fi
  done

  COMPREPLY=()

  if [[ "${cur: -1}" == "$separator" ]]; then
    for value in "${remaining_values[@]}"; do
      COMPREPLY+=("$cur$value")
    done
  elif (( ${#having_values[@]} )); then
    local cur_last_value=${having_values[-1]}

    for value in "${remaining_values[@]}"; do
      if [[ "$value" == "$cur_last_value"* ]]; then
        COMPREPLY+=("${cur%"$cur_last_value"}$value")
      fi
    done
  fi
}

_crazy-complete__prefix_compreply() {
  local i prefix="$1"
  for ((i=0; i < ${#COMPREPLY[@]}; ++i)); do
    COMPREPLY[i]="$prefix${COMPREPLY[i]}"
  done
}

_crazy-complete__parse_commandline() {
  POSITIONALS=()
  END_OF_OPTIONS=0

  local cmd="root" argi arg i char trailing_chars VAR ARGS

  __find_option() {
    case "$2" in
      -h|--help) VAR=OPT_help; ARGS=0; return;;
      --version) VAR=OPT_version; ARGS=0; return;;
      --parser-variable) VAR=OPT_parser_variable; ARGS=1; return;;
      --input-type) VAR=OPT_input_type; ARGS=1; return;;
      --abbreviate-commands) VAR=OPT_abbreviate_commands; ARGS=1; return;;
      --abbreviate-options) VAR=OPT_abbreviate_options; ARGS=1; return;;
      --repeatable-options) VAR=OPT_repeatable_options; ARGS=1; return;;
      --inherit-options) VAR=OPT_inherit_options; ARGS=1; return;;
      --disable) VAR=OPT_disable; ARGS=1; return;;
      --vim-modeline) VAR=OPT_vim_modeline; ARGS=1; return;;
      --zsh-compdef) VAR=OPT_zsh_compdef; ARGS=1; return;;
      --fish-fast) VAR=OPT_fish_fast; ARGS=1; return;;
      --fish-inline-conditions) VAR=OPT_fish_inline_conditions; ARGS=1; return;;
      --include-file) VAR=OPT_include_file; ARGS=1; return;;
      --debug) VAR=OPT_debug; ARGS=0; return;;
      -o|--output) VAR=OPT_output; ARGS=1; return;;
      -i|--install-system-wide) VAR=OPT_install_system_wide; ARGS=0; return;;
      -u|--uninstall-system-wide) VAR=OPT_uninstall_system_wide; ARGS=0; return;;
    esac
    return 1
  }

  __append_to_array() {
    local -n arr=$1
    arr+=("$2")
  }

  for ((argi=1; argi < ${#words[@]} - 1; ++argi)); do
    arg="${words[argi]}"

    case "$arg" in
      --)
        END_OF_OPTIONS=1
        POSITIONALS+=("${words[@]:$((++argi))}")
        return;;
      --*=*)
        if __find_option "$cmd" "${arg%%=*}"
        then __append_to_array "$VAR" "${arg#*=}"
        fi;;
      --*)
        if __find_option "$cmd" "$arg"; then
          if [[ "$ARGS" == 1 ]]
          then __append_to_array "$VAR" "${words[++argi]}"
          else __append_to_array "$VAR" "_OPT_ISSET_"
          fi
        fi;;
      -?*) # ignore '-'

        for ((i=1; i < ${#arg}; ++i)); do
          char="${arg:$i:1}"
          trailing_chars="${arg:$((i + 1))}"

          if __find_option "$cmd" "-$char"; then
            if [[ "$ARGS" == 1 ]]; then
              if [[ -n "$trailing_chars" ]]
              then __append_to_array "$VAR" "$trailing_chars"
              else __append_to_array "$VAR" "${words[++argi]}"
              fi
              break;
            else
              __append_to_array "$VAR" "_OPT_ISSET_"
            fi
          fi
        done
        ;;
      *)
        POSITIONALS+=("$arg")
        ;;
    esac
  done

  for ((; argi < ${#words[@]}; ++argi)); do
    case "${words[argi]}" in
      -?*);;
      *) POSITIONALS+=("${words[argi]}");;
    esac
  done
}

_crazy_complete() {
  local cur prev words cword split
  _init_completion -n = || return

  local END_OF_OPTIONS POSITIONALS
  local -a OPT_help OPT_version OPT_parser_variable OPT_input_type OPT_abbreviate_commands OPT_abbreviate_options OPT_repeatable_options OPT_inherit_options OPT_disable OPT_vim_modeline OPT_zsh_compdef OPT_fish_fast OPT_fish_inline_conditions OPT_include_file OPT_debug OPT_output OPT_install_system_wide OPT_uninstall_system_wide

  _crazy-complete__parse_commandline

  local COMP_WORDBREAKS=''

  __complete_option() {
    local opt="$1" cur="$2"

    case "$opt" in
      --parser-variable)
        return 0;;
      --input-type)
        COMPREPLY=($(compgen -W 'yaml json python help auto' -- "$cur"))
        return 0;;
      --abbreviate-commands|--abbreviate-options|--repeatable-options|--inherit-options|--vim-modeline|--zsh-compdef|--fish-fast|--fish-inline-conditions)
        COMPREPLY=($(compgen -W 'True False' -- "$cur"))
        return 0;;
      --disable)
        _crazy-complete__value_list , hidden final groups repeatable when
        return 0;;
      --include-file|--output|-o)
        _filedir
        return 0;;
    esac

    return 1
  }

  case "$prev" in
    --*) __complete_option "$prev" "$cur" && return 0;;
    -*([hiu])[o])
         __complete_option "-${prev: -1}" "$cur" && return 0;;
  esac

  case "$cur" in
    --*=*)
      __complete_option "${cur%%=*}" "${cur#*=}" && return 0;;
    --*);;
    -*=*);;
    -*([hiu])[o]*)
      local i
      for ((i=2; i <= ${#cur}; ++i)); do
        local pre="${cur:0:$i}" value="${cur:$i}"
        __complete_option "-${pre: -1}" "$value" && {
          _crazy-complete__prefix_compreply "$pre"
          return 0
        }
      done;;
  esac

  if (( ! END_OF_OPTIONS )) && [[ "$cur" = -* ]]; then
    local -a opts
    if (( ! ${#OPT_help[@]} && ! ${#OPT_version[@]} )); then
      opts+=(-h --help --version)
      (( ! ${#OPT_parser_variable[@]} )) && opts+=(--parser-variable=)
      (( ! ${#OPT_input_type[@]} )) && opts+=(--input-type=)
      (( ! ${#OPT_abbreviate_commands[@]} )) && opts+=(--abbreviate-commands=)
      (( ! ${#OPT_abbreviate_options[@]} )) && opts+=(--abbreviate-options=)
      (( ! ${#OPT_repeatable_options[@]} )) && opts+=(--repeatable-options=)
      (( ! ${#OPT_inherit_options[@]} )) && opts+=(--inherit-options=)
      (( ! ${#OPT_disable[@]} )) && opts+=(--disable=)
      (( ! ${#OPT_vim_modeline[@]} )) && opts+=(--vim-modeline=)
      (( ! ${#OPT_zsh_compdef[@]} )) && opts+=(--zsh-compdef=)
      (( ! ${#OPT_fish_fast[@]} )) && opts+=(--fish-fast=)
      (( ! ${#OPT_fish_inline_conditions[@]} )) && opts+=(--fish-inline-conditions=)
      (( ! ${#OPT_include_file[@]} )) && opts+=(--include-file=)
      (( ! ${#OPT_debug[@]} )) && opts+=(--debug)
      (( ! ${#OPT_install_system_wide[@]} && ! ${#OPT_output[@]} && ! ${#OPT_uninstall_system_wide[@]} )) && opts+=(-o --output= -i --install-system-wide -u --uninstall-system-wide)
    fi
    COMPREPLY+=($(compgen -W "${opts[*]}" -- "$cur"))
    [[ ${COMPREPLY-} == *= ]] && compopt -o nospace
    return 1
  fi

  (( ${#POSITIONALS[@]} == 1 )) && {
    COMPREPLY=($(compgen -W 'bash fish zsh json yaml' -- "$cur"))
    return 0;
  }

  (( ${#POSITIONALS[@]} == 2 )) && {
    _filedir
    return 0;
  }

  return 1
}

complete -F _crazy_complete crazy-complete

# vim: ft=sh ts=2 sts=2 sw=2 et
