#compdef mise
# @generated by usage-cli from usage spec
local curcontext="$curcontext"

# caching config
_usage_mise_cache_policy() {
  if [[ -z "${lifetime}" ]]; then
    lifetime=$((60*60*4)) # 4 hours
  fi
  local -a oldp
  oldp=( "$1"(Nms+${lifetime}) )
  (( $#oldp ))
}

_mise() {
  emulate -L zsh
  typeset -A opt_args
  local curcontext="$curcontext" cache_policy

  if ! type -p usage &> /dev/null; then
      echo >&2
      echo "Error: usage CLI not found. This is required for completions to work in mise." >&2
      echo "See https://usage.jdx.dev for more information." >&2
      return 1
  fi

  local spec_file="${TMPDIR:-/tmp}/usage__usage_spec_mise_2026_7_2.spec"
  if [[ ! -f "$spec_file" ]]; then
    mise usage >| "$spec_file"
  fi
  local -a values=() descs=() inserts=()
  local needs_menu=0 line
  while IFS= read -r line; do
    local -a parts=("${(@ps:\t:)line}")
    values+=("${parts[1]}")
    descs+=("${parts[2]}")
    inserts+=("${parts[3]}")
    [[ "${parts[3]}" == "'"* ]] && needs_menu=1
  done < <(command usage complete-word --shell zsh -f "$spec_file" -- "${(Q)words[@]}")
  (( needs_menu )) && compstate[insert]=menu
  if (( ${#inserts[@]} )); then
    local -a _usage_display=()
    local _usage_i _usage_max=0 _usage_v _usage_pad
    for _usage_v in "${values[@]}"; do
      (( ${#_usage_v} > _usage_max )) && _usage_max=${#_usage_v}
    done
    for ((_usage_i=1; _usage_i<=${#values[@]}; _usage_i++)); do
      if [[ -n "${descs[_usage_i]}" ]]; then
        _usage_pad=$(( _usage_max - ${#values[_usage_i]} ))
        _usage_display+=("${values[_usage_i]}${(l:_usage_pad:: :)}  -- ${descs[_usage_i]}")
      else
        _usage_display+=("${values[_usage_i]}")
      fi
    done
    compadd -l -d _usage_display -U -Q -S '' -a inserts
  fi
  return 0
}

if [ "$funcstack[1]" = "_mise" ]; then
    _mise "$@"
else
    compdef _mise mise
fi

# vim: noet ci pi sts=0 sw=4 ts=4
