#compdef styler
# the above line should contain all commands to be completed using this file
# zsh autocompletions for styler script

local curcontext="$curcontext" state line ret=1
local cmdnames=(theme set download list help version)

_arguments -C \
  '1: :->cmds' \
  '2: :->args' \
  '3: :->subrout' && ret=0

local -a initial_commands=(
  'theme:Temporarily switch theme to specified argument'
  'set:Permanently set theme to specified argument'
  'download:Download a base16 compatible template'
  'list:Display installed processors, templates, or themes'
  'help:Display help text and exit'
  'version:Display styler information and exit'
)

__themes() {
  echo "$(styler list themes)"
}

case $state in
cmds)
  _describe -t commands 'styler cmd' initial_commands && ret=0
  ;;

args)
  case $words[2] in
  theme | set)
    _values 'themes' $(__themes) && ret=0
    ;;

  list)
    _values 'listopts' \
      'processors[Display available application processors]' \
      'templates[Display available base16 templates]' \
      'themes[Display available base16 themes]' && ret=0
    ;;

  *)
    ((ret)) && _message 'no more arguments'
    ;;

  esac
  ;;
esac
