#compdef rdial rdial.py
# coding=utf-8
# rdial - ZSH completion support for rdial
# Copyright © 2011-2014  James Rowe <jnrowe@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

# Most of this file is generated from rdial/__init__.py, but feel free to
# customise it!  If you make improvements, open a pull request against
# `JNRowe/rdial' with your super changes attached.

(( $+functions[__list_tasks] )) ||
__list_tasks() {
    local tmp
    tmp=(${XDG_DATA_HOME:-~/.local}/rdial/*~*~(:t:s/.csv/))
    if [ -z "${tmp}" ]; then
        _message "No rdial tasks found!"
    else
        compadd ${tmp[@]}
    fi
}

(( $+functions[__list_wrappers] )) ||
__list_wrappers() {
    local tmp
    tmp=($(sed -n '/^\[run wrappers\]/,/^$/s,^\(.*\) *=.*$,\1,p' \
        ${XDG_CONFIG_HOME:-~/.config}/rdial/config \
        .rdialrc 2>/dev/null
    ))
    tmp=(${XDG_DATA_HOME:-~/.local}/rdial/*~*~(:t:s/.csv/))
    if [ -z "${tmp}" ]; then
        _message "No rdial tasks found!"
    else
        compadd ${tmp[@]}
    fi
}

_arguments '--help[show help message and exit]' \
    "--version[show program's version number and exit]" \
    "--directory=[directory to read/write to]:select directory:_files -W ${XDG_DATA_HOME:-~/.local}" \
    ':rdial command:(fsck start stop switch run wrapper report running last ledger)' \
    '*::subcmd:->subcmd' && return 0

### DGEN_TAG: Generated from rdial/__init__.py {{{
case "$words[1]" in
(fsck)
    _arguments '--help[show help message and exit]'
    ;;
(start)
    _arguments '--help[show help message and exit]' \
        '--new[start a new task]' \
        '--time[set start time]:' \
        '--from-dir[use directory name as task]' \
        ':select task:__list_tasks'
    ;;
(stop)
    _arguments '--help[show help message and exit]' \
        '--message=[closing message]:message text: ' \
        '--file=[read closing message from file]:select file:_files' \
        '--amend[amend previous stop entry]'
    ;;
(switch)
    _arguments '--help[show help message and exit]' \
        '--from-dir[use directory name as task]' \
        '--new[start a new task]' \
        '--message=[closing message for current task]:message text: ' \
        '--file=[read closing message for current task from file]:select file:_files' \
        ':select task:__list_tasks'
    ;;
(run)
    _arguments '--help[show help message and exit]' \
        '--new[start a new task]' \
        '--time[set start time]:' \
        '--from-dir[use directory name as task]' \
        '--message=[closing message for current task]:message text: ' \
        '--file=[read closing message for current task from file]:select file:_files' \
        '--command=[command to run]:select command:_path_commands' \
        ':select task:__list_tasks'
    ;;
(wrapper)
    _arguments '--help[show help message and exit]' \
        '--time[set start time]:' \
        '--message=[closing message for current task]:message text: ' \
        '--file=[read closing message for current task from file]:select file:_files' \
        ':select wrapper:__list_wrappers'
    ;;
(report)
    _arguments '--help[show help message and exit]' \
        '--duration[filter events for specified time period]:select time period:(day week month year all)' \
        '--sort[field to sort by]:select sort field:(task time)' \
        '--reverse[reverse sort order]' \
        '--html[produce HTML output]' \
        '--human[produce human-readable output]' \
        '--from-dir[use directory name as task]' \
        ':select task:__list_tasks'
    ;;
(running)
    _arguments '--help[show help message and exit]'
    ;;
(last)
    _arguments '--help[show help message and exit]'
    ;;
(ledger)
    _arguments '--help[show help message and exit]' \
        '--duration[filter events for specified time period]:select time period:(day week month year all)' \
        '--rate=[hourly rate for task output]:set hourly rate: ' \
        '--from-dir[use directory name as task]' \
        ':select task:__list_tasks'
    ;;
(*)
    ;;
esac
### DGEN_TAG: Generated from rdial/__init__.py }}}

