# 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_service__has_option
  set -l option
  for option in $__QUERY_CACHE_HAVING_OPTIONS
    contains -- $option $argv && return 0
  end

  return 1
end

function _nbfc_service__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_service_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 true
        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_service_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_service_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_service_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_service_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_service__prepare
  _nbfc_service__query_init \
    '=>-h --help -r --read-only -f --fork -d --debug -c= --config-file= -e= --embedded-controller='
  return 0
end

set -l prog 'nbfc_service'
set -l P '_nbfc_service__prepare'
set -l has_option '_nbfc_service__has_option'

# Delete existing completions
complete -c $prog -e

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

# command nbfc_service
set -l C000 "not $has_option -h --help"
set -l C001 "not $has_option -r --read-only"
set -l C002 "not $has_option -f --fork"
set -l C003 "not $has_option -d --debug"
set -l C004 "not $has_option -c --config-file"
set -l C005 "not $has_option -e --embedded-controller"
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 -s r -l read-only -d 'Start in read-only mode' -f
complete -c $prog -n $P -n $C002 -s f -l fork -d 'Switch process to background after sucessfully started' -f
complete -c $prog -n $P -n $C003 -s d -l debug -d 'Enable tracing of reads and writes of the embedded controller' -f
complete -c $prog -n $P -n $C004 -s c -l config-file -d 'Use alternative config file (default /etc/nbfc/nbfc.json)' -Fr
complete -c $prog -n $P -n $C005 -s e -l embedded-controller -d 'Specify embedded controller to use' -x -a 'dummy dev_port ec_sys acpi_ec'

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