#compdef distrobox-upgrade

_distrobox-upgrade() {
    local expl
    local -a options
    local _db_cc

    _db_cc=("${(@f)$(distrobox list | sed 1d | awk -F'|' '{print $2}' | sed 's/^[ \t]*//;s/[ \t]*$//')}")
    
    options=(
        '(-a --all)'{-a,--all}'[upgrade all distroboxes]'
        '--running[perform only for running distroboxes]'
        '(-r --root)'{-r,--root}'[launch podman/docker/lilipod with root privileges]'
        '(-h --help)'{-h,--help}'[show this message]'
        '(-v --verbose)'{-v,--verbose}'[show more verbosity]'
        '(-V --version)'{-V,--version}'[show version]'
    )

    _message -r "Upgrade distroboxes using container's package manager."
    if [[ -n "$_db_cc" ]]; then
      _arguments \
        '*:containers:_distrobox_containers' \
        $options[@]
    else
      _message -r "No containers exist."
      _arguments $options[@]
    fi

}

_distrobox-upgrade
