#compdef lineup

autoload -U is-at-least

_lineup() {
    typeset -A opt_args
    typeset -a _arguments_options
    local ret=1

    if is-at-least 5.2; then
        _arguments_options=(-s -S -C)
    else
        _arguments_options=(-s -C)
    fi

    local context curcontext="$curcontext" state line
    _arguments "${_arguments_options[@]}" : \
'-m+[]:MANIFEST:_files' \
'--manifest=[]:MANIFEST:_files' \
'--num-threads=[]:NUM:_default' \
'--log-level=[]:LEVEL:(off error warn info debug trace)' \
'--worker-exists=[]:ACTION:(fail ignore replace)' \
'*-e+[]:EXTRA_VARS:_default' \
'*--extra-vars=[]:EXTRA_VARS:_default' \
'--fs-var-dir=[Store fs vars in the dir insted of a tmpdir]:DIR:_files' \
'--skip-history=[Skip tasks from history file (use --completed-tasks-append format)]:FILE:_files' \
'*--taskline-skip=[Skip runnig every taskline with this name (return json encoded value if set)]:NAME[=VALUE]:_default' \
'*--taskset-skip=[Do not run this tasks from taskset (split nested tasks on .)]:TASK:_default' \
'--taskset-first=[First task run from taskset (split nested tasks on .)]:TASK:_default' \
'--taskset-last=[Last task run from taskset (split nested tasks on .)]:TASK:_default' \
'--completed-tasks-append=[Append all completed tasks to a file]:FILE:_files' \
'--no-cleanup[Do not cleanup after successefully run all tasks]' \
'(--fs-var-dir --skip-history --completed-tasks-append)--resume[Skip completed tasks (files stored in .lineup dir)]' \
'--cleanup[Cleanup after successefully run all tasks]' \
'--cleanup-before[Cleanup before running tasks]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
":: :_lineup_commands" \
"*::: :->lineup" \
&& ret=0
    case $state in
    (lineup)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:lineup-command-$line[1]:"
        case $line[1] in
            (completion)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
':shell:(bash elvish fish powershell zsh)' \
&& ret=0
;;
(cleanup)
_arguments "${_arguments_options[@]}" : \
'-m+[]:MANIFEST:_files' \
'--manifest=[]:MANIFEST:_files' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(init)
_arguments "${_arguments_options[@]}" : \
'-p+[]:PROFILE:_default' \
'--profile=[]:PROFILE:_default' \
'-m+[]:MANIFEST:_files' \
'--manifest=[]:MANIFEST:_files' \
'*-e+[]:EXTRA_VARS:_default' \
'*--extra-vars=[]:EXTRA_VARS:_default' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
":: :_lineup__help_commands" \
"*::: :->help" \
&& ret=0

    case $state in
    (help)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:lineup-help-command-$line[1]:"
        case $line[1] in
            (completion)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(cleanup)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(init)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
        esac
    ;;
esac
;;
        esac
    ;;
esac
}

(( $+functions[_lineup_commands] )) ||
_lineup_commands() {
    local commands; commands=(
'completion:Print shell completion' \
'cleanup:Cleanup all artifacts\: workers, networks and storages' \
'init:Create lineup manifest' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'lineup commands' commands "$@"
}
(( $+functions[_lineup__cleanup_commands] )) ||
_lineup__cleanup_commands() {
    local commands; commands=()
    _describe -t commands 'lineup cleanup commands' commands "$@"
}
(( $+functions[_lineup__completion_commands] )) ||
_lineup__completion_commands() {
    local commands; commands=()
    _describe -t commands 'lineup completion commands' commands "$@"
}
(( $+functions[_lineup__help_commands] )) ||
_lineup__help_commands() {
    local commands; commands=(
'completion:Print shell completion' \
'cleanup:Cleanup all artifacts\: workers, networks and storages' \
'init:Create lineup manifest' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'lineup help commands' commands "$@"
}
(( $+functions[_lineup__help__cleanup_commands] )) ||
_lineup__help__cleanup_commands() {
    local commands; commands=()
    _describe -t commands 'lineup help cleanup commands' commands "$@"
}
(( $+functions[_lineup__help__completion_commands] )) ||
_lineup__help__completion_commands() {
    local commands; commands=()
    _describe -t commands 'lineup help completion commands' commands "$@"
}
(( $+functions[_lineup__help__help_commands] )) ||
_lineup__help__help_commands() {
    local commands; commands=()
    _describe -t commands 'lineup help help commands' commands "$@"
}
(( $+functions[_lineup__help__init_commands] )) ||
_lineup__help__init_commands() {
    local commands; commands=()
    _describe -t commands 'lineup help init commands' commands "$@"
}
(( $+functions[_lineup__init_commands] )) ||
_lineup__init_commands() {
    local commands; commands=()
    _describe -t commands 'lineup init commands' commands "$@"
}

if [ "$funcstack[1]" = "_lineup" ]; then
    _lineup "$@"
else
    compdef _lineup lineup
fi
