#compdef nbfc

# 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

_nbfc__query() {

  __zsh_query_contains() {
    local arg='' key="$1"; shift
    for arg; do [[ "$key" == "$arg" ]] && return 0; done
    return 1
  }

  local cmd="$1"; shift

  case "$cmd" in
    get_positional)
      printf "%s" "${POSITIONALS[$1]}"
      return 0;;
    init)
      local -a options=(${=1})
      shift;;
    *)
      echo "_nbfc__query: argv[1]: invalid command" >&2
      return 1;;
  esac


  local  long_opts_with_arg=()  long_opts_with_optional_arg=()  long_opts_without_arg=()
  local short_opts_with_arg=() short_opts_with_optional_arg=() short_opts_without_arg=()

  local option=''
  for option in "${options[@]}"; do
    case "$option" in
      --?*=)    long_opts_with_arg+=("${option%=}");;
      --?*=\?)  long_opts_with_optional_arg+=("${option%=?}");;
      --?*)     long_opts_without_arg+=("$option");;
      -?=)      short_opts_with_arg+=("${option%=}");;
      -?=\?)    short_opts_with_optional_arg+=("${option%=?}");;
      -?)       short_opts_without_arg+=("$option");;
    esac
  done

  POSITIONALS=()
  HAVING_OPTIONS=()
  OPTION_VALUES=()
  INCOMPLETE_OPTION=''

  local args=("${(Q)@}")
  local argi=2 # argi[1] is program name
  for ((; argi <= ${#args[@]}; ++argi)); do
    local arg="${args[$argi]}"
    local have_trailing_arg=$(test $argi -lt $# && echo true || echo false)

    case "$arg" in
      --)
        POSITIONALS+=("${@:$((argi + 1))}")
        break;;
      --*=*)
        HAVING_OPTIONS+=("${arg%%=*}")
        OPTION_VALUES+=("${arg#*=}");;
      --*)
        if __zsh_query_contains "$arg" "${long_opts_with_arg[@]}"; then
          if $have_trailing_arg; then
            HAVING_OPTIONS+=("$arg")
            OPTION_VALUES+=("${args[$((++argi))]}")
          fi
        else
          HAVING_OPTIONS+=("$arg")
          OPTION_VALUES+=("")
        fi
        ;;
      -?*) # ignore '-'

        local i=1 arg_length=${#arg}
        for ((; i < arg_length; ++i)); do
          local option="-${arg:$i:1}"
          local trailing_chars="${arg:$((i+1))}"

          if __zsh_query_contains "$option" "${short_opts_without_arg[@]}"; then
            HAVING_OPTIONS+=("$option")
            OPTION_VALUES+=("")
          elif __zsh_query_contains "$option" "${short_opts_with_arg[@]}"; then
            if [[ -n "$trailing_chars" ]]; then
              HAVING_OPTIONS+=("$option")
              OPTION_VALUES+=("$trailing_chars")
            elif $have_trailing_arg; then
              HAVING_OPTIONS+=("$option")
              OPTION_VALUES+=("${args[$((++argi))]}")
            fi

            continue 2
          elif __zsh_query_contains "$option" "${short_opts_with_optional_arg[@]}"; then
            HAVING_OPTIONS+=("$option")
            OPTION_VALUES+=("$trailing_chars") # may be empty
            continue 2
          fi
        done
        ;;
      *)
        POSITIONALS+=("$arg");;
    esac
  done
}

_nbfc__exec() {
  local item='' desc='' describe=()

  while IFS=$'\t' read -r item desc; do
    item="${item//:/\\:}"
    [[ -n "$desc" ]] && describe+=("$item:$desc") || describe+=("$item")
  done < <(eval "$1")

  _describe '' describe
}

_nbfc__command() {
  local items=(
    start:'Start the service'
    stop:'Stop the service'
    restart:'Restart the service'
    status:'Show the service status'
    config:'List or apply configs'
    set:'Control fan speed'
    sensors:'Configure fan sensors'
    update:'Download new configuration files'
    rate-config:'Rate a configuration file'
    acpi-dump:'Dumps information of your ACPI DSDT'
    wait-for-hwmon:'Wait for /sys/class/hwmon/hwmon* files'
    get-model-name:'Print model name for notebook'
    warranty:'Show warranty'
    support:'Show how to support the project'
    help:'Show help'
  )

  _describe -- command items
}

_nbfc_config__-s() {
  _alternative \
    ::'_files -W //usr/share/nbfc/configs' \
    ::'_files -W /var/lib/nbfc/configs' \
    ::_files
}

_nbfc_sensors__command() {
  local items=(
    list:'List available sensors and temperature files'
    show:'Show all available fans with their configuration'
    set:'Configure sensors and algorithm type for a fan'
  )

  _describe -- command items
}

_nbfc_acpi_dump__command() {
  local items=(
    registers:'List all available registers'
    ec-registers:'List all available EC registers'
    methods:'List all available ACPI methods'
    dsl:'Disassemble your DSDT'
  )

  _describe -- command items
}

_nbfc() {
  local opts='-h --help --version'
  local HAVING_OPTIONS=() OPTION_VALUES=() POSITIONALS=() INCOMPLETE_OPTION=''
  _nbfc__query init "$opts" "${words[@]}"

  case "$(_nbfc__query get_positional 1)" in
    start) _nbfc_start; return $?;;
    stop) _nbfc_stop; return $?;;
    restart) _nbfc_restart; return $?;;
    status) _nbfc_status; return $?;;
    config) _nbfc_config; return $?;;
    set) _nbfc_set; return $?;;
    sensors) _nbfc_sensors; return $?;;
    update) _nbfc_update; return $?;;
    rate-config) _nbfc_rate_config; return $?;;
    acpi-dump) _nbfc_acpi_dump; return $?;;
    wait-for-hwmon) _nbfc_wait_for_hwmon; return $?;;
    get-model-name) _nbfc_get_model_name; return $?;;
    warranty) _nbfc_warranty; return $?;;
    support) _nbfc_support; return $?;;
    help) _nbfc_help; return $?;;
  esac

  local -a args=(
    '(--help -h)'{-h,--help}'[show this help message and exit]'
    '(--version)'--version"[show program's version number and exit]"
    1:command1:_nbfc__command
  )
  _arguments -S -s -w "${args[@]}"
}

_nbfc_start() {
  local -a args=(
    '(--read-only -r)'{-r,--read-only}'[Start in read-only mode]'
    '(--help -h)'{-h,--help}'[show this help message and exit]'
    '(--version)'--version"[show program's version number and exit]"
    1:command1:_nbfc__command
  )
  _arguments -S -s -w "${args[@]}"
}

_nbfc_stop() {
  local -a args=(
    '(--help -h)'{-h,--help}'[show this help message and exit]'
    '(--version)'--version"[show program's version number and exit]"
    1:command1:_nbfc__command
  )
  _arguments -S -s -w "${args[@]}"
}

_nbfc_restart() {
  local -a args=(
    '(--read-only -r)'{-r,--read-only}'[Restart in read-only mode]'
    '(--help -h)'{-h,--help}'[show this help message and exit]'
    '(--version)'--version"[show program's version number and exit]"
    1:command1:_nbfc__command
  )
  _arguments -S -s -w "${args[@]}"
}

_nbfc_status() {
  local -a args=(
    '(--fan --service -f -s --all -a)'{-a,--all}'[Show service and fan status (default)]'
    '(--all --fan -a -f --service -s)'{-s,--service}'[Show service status]'
    '(--all --service -a -s --fan -f)'{-f+,--fan=}'[Show status of fan (zero based)]':'FAN INDEX':"{_nbfc__exec 'nbfc complete-fans'}"
    '(--watch -w)'{-w+,--watch=}'[Show status periodically]':SECONDS:"_numbers -f 'Show status periodically'"
    '(--help -h)'{-h,--help}'[show this help message and exit]'
    '(--version)'--version"[show program's version number and exit]"
    1:command1:_nbfc__command
  )
  _arguments -S -s -w "${args[@]}"
}

_nbfc_config() {
  local -a args=(
    '(--apply --recommend --set -a -r -s --list -l)'{-l,--list}'[List all available configs (default)]'
    '(--apply --list --recommend -a -l -r --set -s)'{-s+,--set=}'[Set a config]':config:'{_nbfc_config__-s}'
    '(--list --recommend --set -l -r -s --apply -a)'{-a+,--apply=}'[Set a config and enable fan control]':config:'{_nbfc_config__-s}'
    '(--apply --list --set -a -l -s --recommend -r)'{-r,--recommend}'[List configs which may work for your device]'
    '(--help -h)'{-h,--help}'[show this help message and exit]'
    '(--version)'--version"[show program's version number and exit]"
    1:command1:_nbfc__command
  )
  _arguments -S -s -w "${args[@]}"
}

_nbfc_set() {
  local -a args=(
    '(--speed -s --auto -a)'{-a,--auto}"[Set fan speed to 'auto']"
    '(--auto -a --speed -s)'{-s+,--speed=}'[Set fan speed to PERCENT]':PERCENT:"_numbers -f 'Set fan speed to PERCENT'"
    '(--fan -f)'{-f+,--fan=}'[Fan index (zero based)]':'FAN INDEX':"{_nbfc__exec 'nbfc complete-fans'}"
    '(--help -h)'{-h,--help}'[show this help message and exit]'
    '(--version)'--version"[show program's version number and exit]"
    1:command1:_nbfc__command
  )
  _arguments -S -s -w "${args[@]}"
}

_nbfc_sensors() {
  local opts='-h --help --version'
  local HAVING_OPTIONS=() OPTION_VALUES=() POSITIONALS=() INCOMPLETE_OPTION=''
  _nbfc__query init "$opts" "${words[@]}"

  case "$(_nbfc__query get_positional 2)" in
    list) _nbfc_sensors_list; return $?;;
    show) _nbfc_sensors_show; return $?;;
    set) _nbfc_sensors_set; return $?;;
  esac

  local -a args=(
    '(--help -h)'{-h,--help}'[show this help message and exit]'
    '(--version)'--version"[show program's version number and exit]"
    1:command1:_nbfc__command
    2:command2:_nbfc_sensors__command
  )
  _arguments -S -s -w "${args[@]}"
}

_nbfc_sensors_list() {
  local -a args=(
    '(--help -h)'{-h,--help}'[show this help message and exit]'
    '(--version)'--version"[show program's version number and exit]"
    1:command1:_nbfc__command
    2:command2:_nbfc_sensors__command
  )
  _arguments -S -s -w "${args[@]}"
}

_nbfc_sensors_show() {
  local -a args=(
    '(--help -h)'{-h,--help}'[show this help message and exit]'
    '(--version)'--version"[show program's version number and exit]"
    1:command1:_nbfc__command
    2:command2:_nbfc_sensors__command
  )
  _arguments -S -s -w "${args[@]}"
}

_nbfc_sensors_set() {
  local -a args=(
    '(--fan -f)'{-f+,--fan=}'[Fan index (zero based)]':'FAN INDEX':"{_nbfc__exec 'nbfc complete-fans'}"
    '(--algorithm -a)'{-a+,--algorithm=}'[Set the algorithm type]':ALGORITHM:'(Average Min Max)'
    '*'{-s+,--sensor=}'[Set sensor]':SENSOR:"{_nbfc__exec 'nbfc complete-sensors'}"
    '(--force)'--force'[Force applying sensors]'
    '(--help -h)'{-h,--help}'[show this help message and exit]'
    '(--version)'--version"[show program's version number and exit]"
    1:command1:_nbfc__command
    2:command2:_nbfc_sensors__command
  )
  _arguments -S -s -w "${args[@]}"
}

_nbfc_update() {
  local -a args=(
    '(--parallel -p)'{-p+,--parallel=}'[Set number of parallel downloads]':NUM:"_numbers 'Set number of parallel downloads'"
    '(--quiet -q)'{-q,--quiet}'[Enable quiet mode]'
    '(--help -h)'{-h,--help}'[show this help message and exit]'
    '(--version)'--version"[show program's version number and exit]"
    1:command1:_nbfc__command
  )
  _arguments -S -s -w "${args[@]}"
}

_nbfc_rate_config() {
  local -a args=(
    '(--full-help -H)'{-H,--full-help}'[Show full help]'
    '(--all -a)'{-a,--all}'[Rate all available configuration files]'
    '(--dsdt -d)'{-d+,--dsdt=}'[Use an alternative DSDT file]':FILE:_files
    '(--min-score -m)'{-m+,--min-score=}'[Set minimum rating threshold for configurations]':SCORE:"_numbers -f 'Set minimum rating threshold for configurations'"
    '(--json -j)'{-j,--json}'[Use JSON output]'
    '(--print-rules)'--print-rules'[Print configuration rules]'
    '(--rules -r)'{-r+,--rules=}'[Use an alternative rules file]':FILE:_files
    '(--no-download -n)'{-n,--no-download}"[Don't download rules file from the repository]"
    '(--help -h)'{-h,--help}'[show this help message and exit]'
    '(--version)'--version"[show program's version number and exit]"
    1:command1:_nbfc__command
    2:'Specify configuration file':'{_nbfc_config__-s}'
  )
  _arguments -S -s -w "${args[@]}"
}

_nbfc_acpi_dump() {
  local opts='-f= --file= -j --json -h --help --version'
  local HAVING_OPTIONS=() OPTION_VALUES=() POSITIONALS=() INCOMPLETE_OPTION=''
  _nbfc__query init "$opts" "${words[@]}"

  case "$(_nbfc__query get_positional 2)" in
    registers) _nbfc_acpi_dump_registers; return $?;;
    ec-registers) _nbfc_acpi_dump_ec_registers; return $?;;
    methods) _nbfc_acpi_dump_methods; return $?;;
    dsl) _nbfc_acpi_dump_dsl; return $?;;
  esac

  local -a args=(
    '(--file -f)'{-f+,--file=}'[Use an alternative DSDT file]':FILE:_files
    '(--json -j)'{-j,--json}'[Use JSON output]'
    '(--help -h)'{-h,--help}'[show this help message and exit]'
    '(--version)'--version"[show program's version number and exit]"
    1:command1:_nbfc__command
    2:command2:_nbfc_acpi_dump__command
  )
  _arguments -S -s -w "${args[@]}"
}

_nbfc_acpi_dump_registers() {
  local -a args=(
    '(--file -f)'{-f+,--file=}'[Use an alternative DSDT file]':FILE:_files
    '(--json -j)'{-j,--json}'[Use JSON output]'
    '(--help -h)'{-h,--help}'[show this help message and exit]'
    '(--version)'--version"[show program's version number and exit]"
    1:command1:_nbfc__command
    2:command2:_nbfc_acpi_dump__command
  )
  _arguments -S -s -w "${args[@]}"
}

_nbfc_acpi_dump_ec_registers() {
  local -a args=(
    '(--file -f)'{-f+,--file=}'[Use an alternative DSDT file]':FILE:_files
    '(--json -j)'{-j,--json}'[Use JSON output]'
    '(--help -h)'{-h,--help}'[show this help message and exit]'
    '(--version)'--version"[show program's version number and exit]"
    1:command1:_nbfc__command
    2:command2:_nbfc_acpi_dump__command
  )
  _arguments -S -s -w "${args[@]}"
}

_nbfc_acpi_dump_methods() {
  local -a args=(
    '(--file -f)'{-f+,--file=}'[Use an alternative DSDT file]':FILE:_files
    '(--json -j)'{-j,--json}'[Use JSON output]'
    '(--help -h)'{-h,--help}'[show this help message and exit]'
    '(--version)'--version"[show program's version number and exit]"
    1:command1:_nbfc__command
    2:command2:_nbfc_acpi_dump__command
  )
  _arguments -S -s -w "${args[@]}"
}

_nbfc_acpi_dump_dsl() {
  local -a args=(
    '(--file -f)'{-f+,--file=}'[Use an alternative DSDT file]':FILE:_files
    '(--json -j)'{-j,--json}'[Use JSON output]'
    '(--help -h)'{-h,--help}'[show this help message and exit]'
    '(--version)'--version"[show program's version number and exit]"
    1:command1:_nbfc__command
    2:command2:_nbfc_acpi_dump__command
  )
  _arguments -S -s -w "${args[@]}"
}

_nbfc_wait_for_hwmon() {
  local -a args=(
    '(--help -h)'{-h,--help}'[show this help message and exit]'
    '(--version)'--version"[show program's version number and exit]"
    1:command1:_nbfc__command
  )
  _arguments -S -s -w "${args[@]}"
}

_nbfc_get_model_name() {
  local -a args=(
    '(--help -h)'{-h,--help}'[show this help message and exit]'
    '(--version)'--version"[show program's version number and exit]"
    1:command1:_nbfc__command
  )
  _arguments -S -s -w "${args[@]}"
}

_nbfc_warranty() {
  local -a args=(
    '(--help -h)'{-h,--help}'[show this help message and exit]'
    '(--version)'--version"[show program's version number and exit]"
    1:command1:_nbfc__command
  )
  _arguments -S -s -w "${args[@]}"
}

_nbfc_support() {
  local -a args=(
    '(--upload-firmware)'--upload-firmware'[Upload your notebook firmware without prompting]'
    '(--print-command)'--print-command'[Print command for manual firmware upload]'
    '(--help -h)'{-h,--help}'[show this help message and exit]'
    '(--version)'--version"[show program's version number and exit]"
    1:command1:_nbfc__command
  )
  _arguments -S -s -w "${args[@]}"
}

_nbfc_help() {
  local -a args=(
    '(--help -h)'{-h,--help}'[show this help message and exit]'
    '(--version)'--version"[show program's version number and exit]"
    1:command1:_nbfc__command
  )
  _arguments -S -s -w "${args[@]}"
}

_nbfc "$@"

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