# bash completion support for tractor
# DO NOT EDIT.
# This script is autogenerated by fire/completion.py.

_complete-tractor()
{
  local cur prev opts lastcommand
  COMPREPLY=()
  prev="${COMP_WORDS[COMP_CWORD-1]}"
  cur="${COMP_WORDS[COMP_CWORD]}"
  lastcommand=$(get_lastcommand)

  opts=""
  GLOBAL_OPTIONS=""


  case "${lastcommand}" in

    newid)

      if is_prev_global; then
        opts="${GLOBAL_OPTIONS}"
      else
        opts="--verbose ${GLOBAL_OPTIONS}"
      fi
      opts=$(filter_options $opts)
    ;;

    restart)

      if is_prev_global; then
        opts="${GLOBAL_OPTIONS}"
      else
        opts="--verbose ${GLOBAL_OPTIONS}"
      fi
      opts=$(filter_options $opts)
    ;;

    unset)

      if is_prev_global; then
        opts="${GLOBAL_OPTIONS}"
      else
        opts="--verbose ${GLOBAL_OPTIONS}"
      fi
      opts=$(filter_options $opts)
    ;;

    stop)

      if is_prev_global; then
        opts="${GLOBAL_OPTIONS}"
      else
        opts="--verbose ${GLOBAL_OPTIONS}"
      fi
      opts=$(filter_options $opts)
    ;;

    killtor)

      if is_prev_global; then
        opts="${GLOBAL_OPTIONS}"
      else
        opts="--verbose ${GLOBAL_OPTIONS}"
      fi
      opts=$(filter_options $opts)
    ;;

    start)

      if is_prev_global; then
        opts="${GLOBAL_OPTIONS}"
      else
        opts="--verbose ${GLOBAL_OPTIONS}"
      fi
      opts=$(filter_options $opts)
    ;;

    tractor)

      opts="bridgesfile isconnected isrunning isset killtor newid restart set start stop unset ${GLOBAL_OPTIONS}"
      opts=$(filter_options $opts)
    ;;

    set)

      if is_prev_global; then
        opts="${GLOBAL_OPTIONS}"
      else
        opts="--verbose ${GLOBAL_OPTIONS}"
      fi
      opts=$(filter_options $opts)
    ;;
  esac

  COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
  return 0
}

get_lastcommand()
{
  local lastcommand i

  lastcommand=
  for ((i=0; i < ${#COMP_WORDS[@]}; ++i)); do
    if [[ ${COMP_WORDS[i]} != -* ]] && [[ -n ${COMP_WORDS[i]} ]] && [[
      ${COMP_WORDS[i]} != $cur ]]; then
      lastcommand=${COMP_WORDS[i]}
    fi
  done

  echo $lastcommand
}

filter_options()
{
  local opts
  opts=""
  for opt in "$@"
  do
    if ! option_already_entered $opt; then
      opts="$opts $opt"
    fi
  done

  echo $opts
}

option_already_entered()
{
  local opt
  for opt in ${COMP_WORDS[@]:0:COMP_CWORD}
  do
    if [ $1 == $opt ]; then
      return 0
    fi
  done
  return 1
}

is_prev_global()
{
  local opt
  for opt in $GLOBAL_OPTIONS
  do
    if [ $opt == $prev ]; then
      return 0
    fi
  done
  return 1
}

complete -F _complete-tractor tractor
