Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cooccuring option group with required options is passed as nullable #495

Open
realkarmakun opened this issue Mar 9, 2024 · 1 comment
Open

Comments

@realkarmakun
Copy link

realkarmakun commented Mar 9, 2024

I have following optional group idea is to make it required at all times and use coocurring group as those options are needed for almost all commands:

class ExplicitCredentials: OptionGroup() {
    val panelUrl: String by option("--url", "-u")
        .required()
        .help("Pterodactyl Instance")
    val apiKey: String by option("--api-key", "-a")
        .required()
        .help("API key for an Instance")
}

The usage of said group is as follows

class PowerActionCommand : CliktCommand(name = "power") {
    val credentials by ExplicitCredentials().cooccurring()
    val servers by ServerIds().cooccurring()
    val action: PowerAction by argument().enum()

    override fun run() {
        credentials?.let { creds ->
            val api = PteroBuilder.createClient(creds.panelUrl, creds.apiKey)
            servers?.let {
                for (server in it.serverIds) {
                    api.retrieveServerByIdentifier(server)
                        .flatMap { clientServer -> clientServer.setPower(action) }
                        .execute()
                }
            }
        } ?: echo("No credentials specified")
    }
}

Is it possible to mark group as not nullable in this case?

@ajalt
Copy link
Owner

ajalt commented Mar 9, 2024

I might be misunderstanding the request, but if you want all the options in the group to be required all the time, you don't need coocurring. Just do val group by MyGroup().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants