# 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

  compopt -o nospace

  local cur_unquoted break_pos in_quotes
  _crazy-complete__dequote "$cur" cur_unquoted break_pos in_quotes

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

  local value having_value having_values=() remaining_values=()

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

  for value; do
    if ! _crazy-complete__array_contains "$value" "${having_values[@]}"; then
      remaining_values+=("$value")
    fi
  done

  COMPREPLY=()

  local cur_stripped="$cur_unquoted"
  if (( break_pos > -1 )); then
    cur_stripped="${cur_stripped:break_pos}"
  fi

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

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

_crazy-complete__dequote() {
  local in="$1" len=${#1} i=0 result='' ___break_pos=-1 ___in_quotes=0

  for ((; i < len; ++i)); do
    case "${in:i:1}" in
      "'")
        ___in_quotes=1
        for ((++i; i < len; ++i)); do
          [[ "${in:i:1}" == "'" ]] && { ___in_quotes=0; break; }
          result+="${in:i:1}"
        done;;
      '"')
        ___in_quotes=1
        for ((++i; i < len; ++i)); do
          [[ "${in:i:1}" == '"' ]] && { ___in_quotes=0; break; }

          if [[ "${in:i:1}" == '\' ]]; then
            result+="${in:$((++i)):1}"
          else
            result+="${in:i:1}"
          fi
        done;;
      '\')
        result+="${in:$((++i)):1}";;
      [$COMP_WORDBREAKS])
        result+="${in:i:1}"
        ___break_pos=${#result};;
      *)
        result+="${in:i:1}";;
    esac
  done

  local -n ___RESULT=$2
  local -n ___BREAK_POS=$3
  local -n ___IN_QUOTES=$4
  ___RESULT="$result"
  ___BREAK_POS=$___break_pos
  ___IN_QUOTES=$___in_quotes
}

_crazy-complete__array_contains() {
  local w='' search="$1"; shift;
  for w; do [[ "$search" == "$w" ]] && return 0; done
  return 1
}

_crazy-complete__prefix_compreply() {
  [[ "$cur" == *[$COMP_WORDBREAKS]* ]] && return

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

_crazy-complete__dequote_words() {
  local word dequoted break_pos in_quotes

  words_dequoted=()

  for word in "${words[@]}"; do
    _crazy-complete__dequote "$word" dequoted break_pos in_quotes
    words_dequoted+=("$dequoted")
  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;;
      --manual) VAR=OPT_manual; ARGS='?'; 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;;
      --option-stacking) VAR=OPT_option_stacking; ARGS=1; return;;
      --long-option-argument-separator) VAR=OPT_long_option_argument_separator; ARGS=1; return;;
      --disable) VAR=OPT_disable; ARGS=1; return;;
      --vim-modeline) VAR=OPT_vim_modeline; ARGS=1; return;;
      --bash-completions-version) VAR=OPT_bash_completions_version; 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;;
      --comment) VAR=OPT_comment; ARGS=1; return;;
      --debug) VAR=OPT_debug; ARGS=0; return;;
      --keep-comments) VAR=OPT_keep_comments; ARGS=0; return;;
      --max-line-length) VAR=OPT_max_line_length; ARGS=1; return;;
      --function-prefix) VAR=OPT_function_prefix; ARGS=1; 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 < cword; ++argi)); do
    arg="${words_dequoted[argi]}"

    case "$arg" in
      --)
        END_OF_OPTIONS=1
        POSITIONALS+=("${words_dequoted[@]:$((++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_dequoted[++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_dequoted[++argi]}"
              fi
              break;
            else
              __append_to_array "$VAR" "_OPT_ISSET_"
            fi
          fi
        done
        ;;
      *)
        POSITIONALS+=("$arg")
        ;;
    esac
  done

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

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

  local END_OF_OPTIONS POSITIONALS
  local -a OPT_help OPT_version OPT_manual OPT_parser_variable OPT_input_type
  local -a OPT_abbreviate_commands OPT_abbreviate_options OPT_repeatable_options
  local -a OPT_inherit_options OPT_option_stacking
  local -a OPT_long_option_argument_separator OPT_disable OPT_vim_modeline
  local -a OPT_bash_completions_version OPT_zsh_compdef OPT_fish_fast
  local -a OPT_fish_inline_conditions OPT_include_file OPT_comment OPT_debug
  local -a OPT_keep_comments OPT_max_line_length OPT_function_prefix OPT_output
  local -a OPT_install_system_wide OPT_uninstall_system_wide
  _crazy-complete__parse_commandline

  __complete_option() {
    local opt="$1" cur="$2" mode="$3" ret=0

    case "$opt" in
      --@(bash-completions-version|comment|function-prefix|max-line-length|parser-variable));;
      --input-type)
        COMPREPLY=($(compgen -W 'yaml json python help auto' -- "$cur"));;
      --@(abbreviate-@(commands|options)|fish-@(fast|inline-conditions)|inherit-options|option-stacking|repeatable-options|vim-modeline|zsh-compdef))
        COMPREPLY=($(compgen -W 'True False' -- "$cur"));;
      --long-option-argument-separator)
        COMPREPLY=($(compgen -W 'space equals both' -- "$cur"));;
      --disable)
        _crazy-complete__value_list , hidden final groups repeatable when;;
      --include-file|-o|--output)
        _filedir;;
      *) ret=1;;
    esac

    (( ! ret )) && return 0
    [[ "$mode" == WITH_OPTIONAL ]] || return 1
    ret=0

    case "$opt" in
      --manual);;
      *) ret=1;;
    esac

    return $ret
  }

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

  case "$cur" in
    --*=*)
      __complete_option "${cur%%=*}" "${cur#*=}" WITH_OPTIONAL && 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" WITH_OPTIONAL && {
          _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_manual[@]} )) && opts+=(--manual=)
      (( ! ${#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_option_stacking[@]} )) && opts+=(--option-stacking=)
      (( ! ${#OPT_long_option_argument_separator[@]} )) && opts+=(--long-option-argument-separator=)
      (( ! ${#OPT_disable[@]} )) && opts+=(--disable=)
      (( ! ${#OPT_vim_modeline[@]} )) && opts+=(--vim-modeline=)
      (( ! ${#OPT_bash_completions_version[@]} )) && opts+=(--bash-completions-version=)
      (( ! ${#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_comment[@]} )) && opts+=(--comment=)
      (( ! ${#OPT_debug[@]} )) && opts+=(--debug)
      (( ! ${#OPT_keep_comments[@]} )) && opts+=(--keep-comments)
      (( ! ${#OPT_max_line_length[@]} )) && opts+=(--max-line-length=)
      (( ! ${#OPT_function_prefix[@]} )) && opts+=(--function-prefix=)
      (( ! ${#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
