#compdef qcloud

autoload -U is-at-least

_qcloud() {
    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[@]}" \
'-h[Print help information]' \
'--help[Print help information]' \
":: :_qcloud_commands" \
"*::: :->qcloud" \
&& ret=0
    case $state in
    (qcloud)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:qcloud-command-$line[1]:"
        case $line[1] in
            (upload)
_arguments "${_arguments_options[@]}" \
'-f[本地文件名称]' \
'-k[对象名称, 如果未指定，和本地文件名称相同]' \
'-h[Print help information]' \
'--help[Print help information]' \
&& ret=0
;;
(download)
_arguments "${_arguments_options[@]}" \
'-f[本地保存文件名称, 如果未指定，和对象名称相同]' \
'-k[对象名称]' \
'-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[_qcloud_commands] )) ||
_qcloud_commands() {
    local commands; commands=(
'upload:' \
'download:' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'qcloud commands' commands "$@"
}
(( $+functions[_qcloud__download_commands] )) ||
_qcloud__download_commands() {
    local commands; commands=()
    _describe -t commands 'qcloud download commands' commands "$@"
}
(( $+functions[_qcloud__help_commands] )) ||
_qcloud__help_commands() {
    local commands; commands=()
    _describe -t commands 'qcloud help commands' commands "$@"
}
(( $+functions[_qcloud__upload_commands] )) ||
_qcloud__upload_commands() {
    local commands; commands=()
    _describe -t commands 'qcloud upload commands' commands "$@"
}

_qcloud "$@"
