#compdef podmod

autoload -U is-at-least

_podmod() {
    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[@]}" \
'-c+[Path to the configuration file]:CONFIG: ' \
'--config=[Path to the configuration file]:CONFIG: ' \
'-h[Print help information]' \
'--help[Print help information]' \
'-V[Print version information]' \
'--version[Print version information]' \
":: :_podmod_commands" \
"*::: :->podmod" \
&& ret=0
    case $state in
    (podmod)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:podmod-command-$line[1]:"
        case $line[1] in
            (build)
_arguments "${_arguments_options[@]}" \
'-m+[The module to work on]:MODULE: ' \
'--module=[The module to work on]:MODULE: ' \
'-i[Quietly exit if module is already built]' \
'--idempotent[Quietly exit if module is already built]' \
'--no-prune[Don'\''t prune old images after building]' \
'-h[Print help information]' \
'--help[Print help information]' \
&& ret=0
;;
(load)
_arguments "${_arguments_options[@]}" \
'-m+[The module to work on]:MODULE: ' \
'--module=[The module to work on]:MODULE: ' \
'-i[Quietly exit if module is already loaded]' \
'--idempotent[Quietly exit if module is already loaded]' \
'-h[Print help information]' \
'--help[Print help information]' \
&& ret=0
;;
(modules)
_arguments "${_arguments_options[@]}" \
'-h[Print help information]' \
'--help[Print help information]' \
&& ret=0
;;
(run)
_arguments "${_arguments_options[@]}" \
'-m+[The module to work on]:MODULE: ' \
'--module=[The module to work on]:MODULE: ' \
'-h[Print help information]' \
'--help[Print help information]' \
'*::command -- The command to execute:' \
&& ret=0
;;
(shell)
_arguments "${_arguments_options[@]}" \
'-m+[The module to work on]:MODULE: ' \
'--module=[The module to work on]:MODULE: ' \
'-h[Print help information]' \
'--help[Print help information]' \
'::shell -- The shell command to run:' \
&& ret=0
;;
(unload)
_arguments "${_arguments_options[@]}" \
'-m+[Work on the module MODULE]:MODULE: ' \
'--module=[Work on the module MODULE]:MODULE: ' \
'-i[Quietly exit if module is not loaded]' \
'--idempotent[Quietly exit if module is not loaded]' \
'-h[Print help information]' \
'--help[Print help information]' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" \
'*::subcommand -- The subcommand whose help message to display:' \
&& ret=0
;;
        esac
    ;;
esac
}

(( $+functions[_podmod_commands] )) ||
_podmod_commands() {
    local commands; commands=(
'build:Build the kernel module' \
'load:Load the kernel module' \
'modules:List supported kernel modules' \
'run:Run a command inside a new container' \
'shell:Start a shell session inside a new container' \
'unload:Unload the kernel module' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'podmod commands' commands "$@"
}
(( $+functions[_podmod__build_commands] )) ||
_podmod__build_commands() {
    local commands; commands=()
    _describe -t commands 'podmod build commands' commands "$@"
}
(( $+functions[_podmod__help_commands] )) ||
_podmod__help_commands() {
    local commands; commands=()
    _describe -t commands 'podmod help commands' commands "$@"
}
(( $+functions[_podmod__load_commands] )) ||
_podmod__load_commands() {
    local commands; commands=()
    _describe -t commands 'podmod load commands' commands "$@"
}
(( $+functions[_podmod__modules_commands] )) ||
_podmod__modules_commands() {
    local commands; commands=()
    _describe -t commands 'podmod modules commands' commands "$@"
}
(( $+functions[_podmod__run_commands] )) ||
_podmod__run_commands() {
    local commands; commands=()
    _describe -t commands 'podmod run commands' commands "$@"
}
(( $+functions[_podmod__shell_commands] )) ||
_podmod__shell_commands() {
    local commands; commands=()
    _describe -t commands 'podmod shell commands' commands "$@"
}
(( $+functions[_podmod__unload_commands] )) ||
_podmod__unload_commands() {
    local commands; commands=()
    _describe -t commands 'podmod unload commands' commands "$@"
}

_podmod "$@"
