#compdef pantry pantryd
#
# Here are completion functions for zsh, for both pantry and
# pantryd. If you copy this file to a directory in your zsh fpath,
# then you will get tab completion for Pantry in zsh.
#
# If you have no idea what I'm talking about, get started here
# (registration required, sorry, these are the best free links I can
# find):
#
# http://www.linux-mag.com/id/1053
# http://www.linux-mag.com/id/1106
#
# Of course many other shells also do completions; if you write
# those and send them to me then I will include them in the next
# release of Pantry.

local arguments
local traits="name group quantity unit date meal comment order refuse percent-refuse yield instructions"
local Traits="Name Group Quantity Unit Date Meal Comment Order Refuse Percent-refuse Yield Instructions"

case "$service" in
    (pantry)
        arguments=(
            '--open=[close current file and open new one]:filename:_files'
            '--read=[append contents of file to currently open file]:filename:_files'
            '--close[close currently open file]'
            '--save[save currently open file]'
            '--save-as=[save current file under different name]:filename:_files'
            '--quit[shut down server]'
            '--status[show current server status]'

            '*'{--search=,-s+}'[select foods whose trait matches regexp]:trait name:('${traits}'):regexp:'
            '*'{--change=,-c+}'[change trait]:trait name:('${traits}'):new value:'
            '--by-nut[set quantity of food so amount of nut-name = qty]:nutrient name: :quantity:'
            '(--refuse -r)'{--refuse,-r}'[reduce quantity by percent refuse]'

            '*--change-nut[change nutrient value]:nutrient name: :nutrient value:'
            '*--rename-nut[rename nutrient matching a pattern]:regexp: :new name:'
            '*--delete-nuts[delete nutrients matching a pattern]:regexp:'
            '*--change-avail-unit[change available unit value]:unit name: :new value:'
            '*--rename-avail-unit[rename available unit matching a pattern]:regexp: :new name:'
            '*--delete-avail-units[delete available units matching a pattern]:regexp:'
            '*--add-ingredients[add ingredients from a collection]:collection name:'
            '*--delete-ingredients[delete ingredients whose name matches a pattern]:regexp:'

            '(-i --ignore-case)'{--ignore-case,-i}'[make all patterns case insensitive]'
            '(-x --exact-match)'{--exact-match,-x}'[patterns must match exactly (turns off regexps)]'
            '--edit[edit foods in place]'
            '--delete[delete matching foods]'
            '--create[create a new food]'
            '--limit[limit number of foods in buffer to number]:number:'

            {'*--print=','*-p+'}'[print report]:report name:(name info recipe units paste groups nuts Nuts goals Goals blank)'
            {'*--key=','*-k+'}'[sort by trait]:trait name:('${traits}' '${Traits}')'
            {'*--goal=','*-g+'}'[add nutrient to nutrient list]:nutrient name: :goal:'
            {'*--list=','*-l+'}'[append string to list of sort orders for trait]:('${traits}'):string'

            {'*--add=','*-a+'}'[add buffer to collection]:collection name:'
            '(-o, --auto-order)'{--auto-order,-o}'[automatically increment order trait when adding foods]'

            '(-h --help)'{--help,-h}'[show brief help and exit]'
            '(-v --version)'{--version,-v}'[show version information and exit]'
            '--copyright[show copyright and license information and exit]'
            ':collection name to search:'
        )
        ;;

    (pantryd)
        arguments=(
            '(--foreground -f)'{--foreground,-f}'[run server in foreground (useful for debugging)]'
            '(--help -h)'{--help,-h}'[show brief help and exit]'
            )
        ;;
esac

_arguments -s $arguments
# vim: set ts=8 sts=4 sw=4 ai:
