# 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

function _nbfc__positional_contains
  set -l positional_num $argv[1]
  set -e argv[1]
  contains -- $__QUERY_CACHE_POSITIONALS[$positional_num] $argv
end

function _nbfc__query_init
  set -l definitions $argv
  set -l positionals
  set -l having_options
  set -l option_values
  set -l last_arg_is_option_argument false

  function _nbfc_match_positionals -S
    set -l patterns (string split -- '>' "$argv[1]")
    set -l i (count $patterns)

    while test $i -ge 1
      string match -q -r -- "^$patterns[$i]\$" "$positionals[$i]" || return 1
      set i (math $i - 1)
    end
  end

  function _nbfc_get_option -S
    set -l option $argv[1]
    set -l i (count $definitions)

    while test $i -ge 1
      set -l split (string split -m 1 -- '=>' $definitions[$i])
      if _nbfc_match_positionals "$split[1]"
        set -l opt
        for opt in (string split -- ' ' $split[2])
          test "$opt" = "$option"   && begin echo '0'; return; end
          test "$opt" = "$option="  && begin echo '1'; return; end
          test "$opt" = "$option=?" && begin echo '?'; return; end
        end
      end

      set i (math $i - 1)
    end
  end

  set -l cmdline (commandline -poc)
  set -l cmdline_count (count $cmdline)

  set -l argi 2 # cmdline[1] is command name
  while test $argi -le $cmdline_count
    set -l arg "$cmdline[$argi]"
    set -l have_trailing_arg (test $argi -lt $cmdline_count && echo true || echo false)

    switch $arg
      case '-'
        set -a positionals -
      case '--'
        set -a positionals $cmdline[$(math $argi + 1)..]
        break
      case '--*=*'
        set -l split (string split -m 1 -- '=' $arg)
        set -a having_options $split[1]
        set -a option_values "$split[2]"
      case '--*'
        set -l option_type (_nbfc_get_option $arg)
        if test "$option_type" = '1'
          if $have_trailing_arg
            set -a having_options $arg
            set -a option_values $cmdline[(math $argi + 1)]
            set argi (math $argi + 1)
          else
            set last_arg_is_option_argument true
          end
        else
          set -a having_options $arg
          set -a option_values ''
        end
      case '-*'
        set -l end_of_parsing false

        set -l arg_length (string length -- $arg)
        set -l i 2
        while not $end_of_parsing; and test $i -le $arg_length
          set -l option "-$(string sub -s $i -l 1 -- $arg)"
          set -l trailing_chars "$(string sub -s (math $i + 1) -- $arg)"
          set -l option_type (_nbfc_get_option $option)

          if test "$option_type" = '0'
            set -a having_options $option
            set -a option_values ''
          else if test "$option_type" = '1'
            set end_of_parsing true

            if test -n "$trailing_chars"
              set -a having_options $option
              set -a option_values $trailing_chars
            else if $have_trailing_arg
              set -a having_options $option
              set -a option_values $cmdline[(math $argi + 1)]
              set argi (math $argi + 1)
            else
              set last_arg_is_option_argument true
            end
          else if test "$option_type" = '?'
            set end_of_parsing true
            set -a having_options $option
            set -a option_values "$trailing_chars" # may be empty
          end

          set i (math $i + 1)
        end
      case '*'
        set -a positionals $arg
    end

    set argi (math $argi + 1)
  end

  set -g __QUERY_CACHE_POSITIONALS    $positionals
  set -g __QUERY_CACHE_HAVING_OPTIONS $having_options
  set -g __QUERY_CACHE_OPTION_VALUES  $option_values

  set -l cmdline_last_arg (commandline -ct | string unescape)
  set -g __QUERY_CACHE_CURRENT_ARG $cmdline_last_arg

  $last_arg_is_option_argument && return

  set -l split (string split -m1 -- '=' $cmdline_last_arg)
  if test $status -eq 0 && contains -- (_nbfc_get_option $split[1]) '1' '?'
    set -g __QUERY_CACHE_CURRENT_ARG $split[2]
    return
  end

  set -l arg_length (string length -- $cmdline_last_arg)
  set -l i 2
  while test $i -le $arg_length
    set -l option "-$(string sub -s $i -l 1 -- $cmdline_last_arg)"
    if contains -- (_nbfc_get_option $option) '1' '?'
      set -g __QUERY_CACHE_CURRENT_ARG (string sub -s (math $i + 1) -- $cmdline_last_arg)
      return
    end

    set i (math $i + 1)
  end
end

function _nbfc__has_option
  set -l option
  for option in $__QUERY_CACHE_HAVING_OPTIONS
    contains -- $option $argv && return 0
  end

  return 1
end

function _nbfc__filedir

  argparse --max-args 0 'd/description=' 'D/directories' 'C/cd=' \
      -- $argv || return 1

  set -l comp (_nbfc__get_completing_arg)
  set -l desc
  set -l files

  if set -q _flag_cd[1]
    pushd $_flag_cd 2>/dev/null || return 1
    set files (complete -C"'' $comp")
    popd
  else
    set files (complete -C"'' $comp")
  end

  if set -q _flag_description[1]
    set desc $_flag_description
  else if set -g _flag_directories
    set desc 'Directory'
  end

  if set -q files[1]
    if set -q _flag_directories[1]
      set files (printf '%s\n' $files | string match -r '.*/$')
    end

    printf '%s\n' $files\t"$desc"
  end
end

function _nbfc__get_completing_arg
  if test -n "$__fish_stripprefix"
    string replace -r -- $__fish_stripprefix '' "$__QUERY_CACHE_CURRENT_ARG"
  else
    printf '%s\n' "$__QUERY_CACHE_CURRENT_ARG"
  end
end

function _nbfc__num_of_positionals
  switch (count $argv)
    case 0
      count $__QUERY_CACHE_POSITIONALS
    case 2
      test (count $__QUERY_CACHE_POSITIONALS) $argv[1] $argv[2] && return 0 || return 1
  end
end

function _nbfc__prepare
  _nbfc__query_init \
    '=>-h --help --version' \
    '(start)=>-r --read-only' \
    '(restart)=>-r --read-only' \
    '(status)=>-a --all -s --service -f= --fan= -w= --watch=' \
    '(config)=>-l --list -s= --set= -a= --apply= -r --recommend' \
    '(set)=>-a --auto -s= --speed= -f= --fan=' \
    '(sensors)>(set)=>-f= --fan= -a= --algorithm= -s= --sensor= --force' \
    '(update)=>-p= --parallel= -q --quiet' \
    '(rate\-config)=>-H --full-help -a --all -d= --dsdt= -D= --dsdt-dir= -m= --min-score= -j --json --print-rules -r= --rules= -n --no-download' \
    '(acpi\-dump)=>-d= --dsdt= -D= --dsdt-dir= -j --json' \
    '(support)=>--upload-firmware --print-command --create-archive='
  return 0
end

function _nbfc_sensors__command
  printf '%s\t%s\n' \
    list 'List available sensors and temperature files' \
    show 'Show all available fans with their configuration' \
    set 'Configure sensors and algorithm type for a fan'
end

function _nbfc_acpi_dump__command
  printf '%s\t%s\n' \
    registers 'List all available registers' \
    ec-registers 'List all available EC registers' \
    methods 'List all available ACPI methods' \
    dsl 'Disassemble your ACPI tables'
end

function _nbfc__command
  printf '%s\t%s\n' \
    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' \
    xml2json 'Convert an XML configuration to JSON' \
    warranty 'Show warranty' \
    support 'Show how to support the project' \
    faq 'Show NBFC FAQ manual' \
    help 'Show help'
end

set -l prog 'nbfc'
set -l P '_nbfc__prepare'
set -l positional_contains '_nbfc__positional_contains'
set -l has_option '_nbfc__has_option'
set -l num_of_positionals '_nbfc__num_of_positionals'

# Delete existing completions
complete -c $prog -e

# Generally disable file completion
complete -c $prog -x

# command nbfc
set -l C000 "not $has_option -h --help"
set -l C001 "not $has_option --version"
set -l C002 "$num_of_positionals -eq 0"
complete -c $prog -n $P -n $C000 -s h -l help -d 'show this help message and exit' -f
complete -c $prog -n $P -n $C001 -l version -d "show program's version number and exit" -f
complete -c $prog -n $P -n $C002 -d Commands -f -a '(_nbfc__command)'

# command nbfc start
set -l C000 "$positional_contains 1 start"
set -l C001 "not $has_option -r --read-only"
complete -c $prog -n $P -n $C000 -n $C001 -s r -l read-only -d 'Start in read-only mode' -f

# command nbfc restart
set -l C000 "$positional_contains 1 restart"
set -l C001 "not $has_option -r --read-only"
complete -c $prog -n $P -n $C000 -n $C001 -s r -l read-only -d 'Restart in read-only mode' -f

# command nbfc status
set -l C000 "$positional_contains 1 status"
set -l C001 "not $has_option -s --service -f --fan -a --all"
set -l C002 "not $has_option -a --all -f --fan -s --service"
set -l C003 "not $has_option -a --all -s --service"
set -l C004 "not $has_option -w --watch"
complete -c $prog -n $P -n $C000 -n $C001 -s a -l all -d 'Show service and fan status (default)' -f
complete -c $prog -n $P -n $C000 -n $C002 -s s -l service -d 'Show service status' -f
complete -c $prog -n $P -n $C000 -n $C003 -s f -l fan -d 'Show status of fan (zero based)' -x -a '(nbfc complete-fans)'
complete -c $prog -n $P -n $C000 -n $C004 -s w -l watch -d 'Show status periodically' -x

# command nbfc config
set -l C000 "$positional_contains 1 config"
set -l C001 "not $has_option -s --set -a --apply -r --recommend -l --list"
set -l C002 "not $has_option -l --list -a --apply -r --recommend -s --set"
set -l C003 "not $has_option -l --list -s --set -r --recommend -a --apply"
set -l C004 "not $has_option -l --list -s --set -a --apply -r --recommend"
complete -c $prog -n $P -n $C000 -n $C001 -s l -l list -d 'List all available configs (default)' -f
complete -c $prog -n $P -n $C000 -n $C002 -s s -l set -d 'Set a config' -x -a '(_nbfc__filedir -C //usr/share/nbfc/configs; _nbfc__filedir -C /var/lib/nbfc/configs; _nbfc__filedir)'
complete -c $prog -n $P -n $C000 -n $C003 -s a -l apply -d 'Set a config and enable fan control' -x -a '(_nbfc__filedir -C //usr/share/nbfc/configs; _nbfc__filedir -C /var/lib/nbfc/configs; _nbfc__filedir)'
complete -c $prog -n $P -n $C000 -n $C004 -s r -l recommend -d 'List configs which may work for your device' -f

# command nbfc set
set -l C000 "$positional_contains 1 set"
set -l C001 "not $has_option -s --speed -a --auto"
set -l C002 "not $has_option -a --auto -s --speed"
set -l C003 "not $has_option -f --fan"
complete -c $prog -n $P -n $C000 -n $C001 -s a -l auto -d "Set fan speed to 'auto'" -f
complete -c $prog -n $P -n $C000 -n $C002 -s s -l speed -d 'Set fan speed to PERCENT' -x
complete -c $prog -n $P -n $C000 -n $C003 -s f -l fan -d 'Fan index (zero based)' -x -a '(nbfc complete-fans)'

# command nbfc sensors
set -l C000 "$num_of_positionals -eq 1"
set -l C001 "$positional_contains 1 sensors"
complete -c $prog -n $P -n $C000 -n $C001 -d Commands -f -a '(_nbfc_sensors__command)'

# command nbfc sensors set
set -l C000 "$positional_contains 1 sensors"
set -l C001 "$positional_contains 2 set"
set -l C002 "not $has_option -f --fan"
set -l C003 "not $has_option -a --algorithm"
set -l C004 "not $has_option --force"
complete -c $prog -n $P -n $C000 -n $C001 -n $C002 -s f -l fan -d 'Fan index (zero based)' -x -a '(nbfc complete-fans)'
complete -c $prog -n $P -n $C000 -n $C001 -n $C003 -s a -l algorithm -d 'Set the algorithm type' -x -a 'Average Min Max'
complete -c $prog -n $P -n $C000 -n $C001 -s s -l sensor -d 'Set sensor' -x -a '(nbfc complete-sensors)'
complete -c $prog -n $P -n $C000 -n $C001 -n $C004 -l force -d 'Force applying sensors' -f

# command nbfc update
set -l C000 "$positional_contains 1 update"
set -l C001 "not $has_option -p --parallel"
set -l C002 "not $has_option -q --quiet"
complete -c $prog -n $P -n $C000 -n $C001 -s p -l parallel -d 'Set number of parallel downloads' -x
complete -c $prog -n $P -n $C000 -n $C002 -s q -l quiet -d 'Enable quiet mode' -f

# command nbfc rate-config
set -l C000 "$positional_contains 1 rate-config"
set -l C001 "not $has_option -H --full-help"
set -l C002 "not $has_option -a --all"
set -l C003 "not $has_option -D --dsdt-dir"
set -l C004 "not $has_option -d --dsdt -D --dsdt-dir"
set -l C005 "not $has_option -m --min-score"
set -l C006 "not $has_option -j --json"
set -l C007 "not $has_option --print-rules"
set -l C008 "not $has_option -r --rules"
set -l C009 "not $has_option -n --no-download"
set -l C010 "$num_of_positionals -eq 1"
complete -c $prog -n $P -n $C000 -n $C001 -s H -l full-help -d 'Show full help' -f
complete -c $prog -n $P -n $C000 -n $C002 -s a -l all -d 'Rate all available configuration files' -f
complete -c $prog -n $P -n $C000 -n $C003 -s d -l dsdt -d 'Use an alternative DSDT file' -Fr
complete -c $prog -n $P -n $C000 -n $C004 -s D -l dsdt-dir -d 'Use an alternative DSDT dir' -x -a '(__fish_complete_directories)'
complete -c $prog -n $P -n $C000 -n $C005 -s m -l min-score -d 'Set minimum rating threshold for configurations' -x
complete -c $prog -n $P -n $C000 -n $C006 -s j -l json -d 'Use JSON output' -f
complete -c $prog -n $P -n $C000 -n $C007 -l print-rules -d 'Print configuration rules' -f
complete -c $prog -n $P -n $C000 -n $C008 -s r -l rules -d 'Use an alternative rules file' -Fr
complete -c $prog -n $P -n $C000 -n $C009 -s n -l no-download -d "Don't download rules file from the repository" -f
complete -c $prog -n $P -n $C010 -n $C000 -d 'Specify configuration file' -x -a '(_nbfc__filedir -C //usr/share/nbfc/configs; _nbfc__filedir -C /var/lib/nbfc/configs; _nbfc__filedir)'

# command nbfc acpi-dump
set -l C000 "$positional_contains 1 acpi-dump"
set -l C001 "not $has_option -D --dsdt-dir"
set -l C002 "not $has_option -d --dsdt -D --dsdt-dir"
set -l C003 "not $has_option -j --json"
set -l C004 "$num_of_positionals -eq 1"
complete -c $prog -n $P -n $C000 -n $C001 -s d -l dsdt -d 'Use an alternative DSDT file' -Fr
complete -c $prog -n $P -n $C000 -n $C002 -s D -l dsdt-dir -d 'Use an alternative DSDT directory' -x -a '(__fish_complete_directories)'
complete -c $prog -n $P -n $C000 -n $C003 -s j -l json -d 'Use JSON output' -f
complete -c $prog -n $P -n $C004 -n $C000 -d Commands -f -a '(_nbfc_acpi_dump__command)'

# command nbfc xml2json
set -l C000 "$num_of_positionals -eq 1"
set -l C001 "$positional_contains 1 xml2json"
complete -c $prog -n $P -n $C000 -n $C001 -d 'Specify configuration file' -Fr

# command nbfc support
set -l C000 "$positional_contains 1 support"
set -l C001 "not $has_option --print-command --create-archive --upload-firmware"
set -l C002 "not $has_option --upload-firmware --create-archive --print-command"
set -l C003 "not $has_option --upload-firmware --print-command --create-archive"
complete -c $prog -n $P -n $C000 -n $C001 -l upload-firmware -d 'Upload your notebook firmware without prompting' -f
complete -c $prog -n $P -n $C000 -n $C002 -l print-command -d 'Print command for manual firmware upload' -f
complete -c $prog -n $P -n $C000 -n $C003 -l create-archive -d 'Create a support archive' -Fr

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