#compdef pyb
typeset -A opt_args


command -v pyb >/dev/null 2>&1 || return 0

local -a common_opts
common_opts=(
        '-v[Verbose output]'
        '-X[Debug output]'
        '-q[Quiet mode]'
        '-Q[Very quiet mode]'
        '-C[Disable colored output]'
        '-h[Show help]'
        '--start-project[Initialize a new project structure]'
        '-t[Show available tasks]'
)

_arguments -C '*:Task:->tasks' $common_opts && ret=0

case "$state" in
    (tasks)

    local tasks; tasks=()

    pyb -Qt | while read TASK_LINE; do
        tasks+=( $TASK_LINE )
    done

    _arguments -s '-v[Verbose output]' '-X[Debug output]' '-q[Quiet mode]' \
        '-Q[Very quiet mode]' '-C[Disable colored output]' '-h[Show help]' \
        '--start-project[Initialize a new project structure]' \
        '-t[Show available tasks]'


    _describe -t tasks 'tasks' tasks && ret=0
    ;;
esac

return 1
