#compdef superctl
#
# superctl(1) completion

_superctl() {
    local line state

    _arguments -C \
        "1: :->cmds" \
        "*::arg:->args"
    case "$state" in
        cmds)
            _values "superctl commands" \
                "start[Start the given service]" \
                "stop[Stop the given service]" \
                "restart[Restart the given service]" \
                "enable[Enable the given service]" \
                "disable[Disable the given service]" \
                "status[Get status for the give service(s), or all services if not specified]" \
                "set-env[Set one or more environment variables for running services, either to the value specified or the value from the current environment if it is set]" \
                "reload[Reload service config from disk, adding any new config found]" \
                {-h,--help}"[Show help]" \
                "(--version)--version[Show version]"
            ;;
        args)
            local services=($(superctl status | cut -f1 -d' '))
            case $line[1] in
                start)
                    _arguments -s \
                        ':services:($services)'
                    ;;
                stop)
                    _arguments -s \
                        ':services:($services)'
                    ;;
                restart)
                    _arguments -s \
                        ':services:($services)'
                    ;;
                enable)
                    _arguments -s \
                        ':services:($services)' \
                        {-n,--now}"[Stop service after disabling it]"
                    ;;
                disable)
                    _arguments -s \
                        ':services:($services)' \
                        {-n,--now}"[Stop service after disabling it]"
                    ;;
                status)
                    _arguments -s \
                        ':services:($services)'
                    ;;
            esac
            ;;
    esac
}
