# MGCB autocomplete for bash

function _mgcbcomplete()
{
  local cur prev
  _get_comp_words_by_ref -n = cur prev
  
  case "$cur" in
    "--platform="* | "-t="* | "/platform="* | "/t="*)
      COMPREPLY=($(compgen -W "Windows Xbox360 iOS Android DesktopGL \
                               MacOSX WindowsStoreApp NativeClient \
                               PlayStationMobile WindowsPhone8 RaspberryPi \
                               PlayStation4 PSVita XboxOne Switch" -- ${cur#*=}))
      compopt +o nospace
      return 0;
      ;;
    "--profile="* | "-p="* | "/profile="* | "/p="*)
      COMPREPLY=($(compgen -W "Reach HiDef" -- ${cur#*=}))
      compopt +o nospace
      return 0;
      ;;
    "--build="* | "--outputDir="* | "--intermediateDir="* | \
    "--workingDir="* | "--copy="* | "--reference"* | "--@="* | \
    "-b="* | "-o="* | "-n="* | "-w="* | "-f="* | "-@="* | \
    "/build="* | "/outputDir="* | "/intermediateDir="* | \
    "/workingDir="* | "/copy="* | "/reference"* | \
    "/b="* | "/o="* | "/n="* | "/w="* | "/f="* | "/@="*)
      COMPREPLY=()
      return 0
      ;;
    "--config=" | "/config=")
      return 0;
      ;;
    "--processor=" | "--importer=" | "--processorParam=" | \
    "/processor=" | "/importer=" | "/processorParam=")
      # TODO
      return 0;
      ;;
    "-b" | "-o" | "-n" | "-w" | "-f" | "-@" | \
    "-q" | "-t" | "-p" | "-P" | "-i" | \
    "/b" | "/o" | "/n" | "/w" | "/f" | "/@" | \
    "/q" | "/t" | "/p" | "/P" | "/i")
      COMPREPLY=("$cur=")
      return 0;
      ;;
    "-c" | "-h" | "-I" | "-d" | "-q" | "-r" | \
    "/c" | "/h" | "/I" | "/d" | "/q" | "/r")
      COMPREPLY=("$cur")
      compopt +o nospace
      return 0;
      ;;
  esac
  
  if [[ "$cur" == "--"* ]]
  then
    COMPREPLY=($(compgen -W "--@= --build= --clean --compress --config= --copy= \
                             --help --importer= --incremental --intermediateDir= \
                             --launchdebugger --outputDir= --platform= --processor= \
                             --processorParam= --profile= --quiet --rebuild \
                             --reference= --workingDir=" -- $cur))
    if [[ ${COMPREPLY[0]} != *"=" ]]
    then
      compopt +o nospace
    fi
    
    return 0;
  fi
  
  if [[ "$cur" == "/"* ]]
  then
    COMPREPLY=($(compgen -W "/@= /build= /clean /compress /config= /copy= \
                             /help /importer= /incremental /intermediateDir= \
                             /launchdebugger /outputDir= /platform= /processor= \
                             /processorParam= /profile= /quiet /rebuild \
                             /reference= /workingDir=" -- $cur))
    if [[ ${COMPREPLY[0]} != *"=" ]]
    then
      compopt +o nospace
    fi
    
    return 0;
  fi
}

complete -o nospace -o default -F _mgcbcomplete mgcb
