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

undefined arguments "eaten up" silently on allowMultipleSubcommands = true #303

Closed
HoffiMuc opened this issue Aug 1, 2021 · 1 comment · Fixed by #304
Closed

undefined arguments "eaten up" silently on allowMultipleSubcommands = true #303

HoffiMuc opened this issue Aug 1, 2021 · 1 comment · Fixed by #304

Comments

@HoffiMuc
Copy link

HoffiMuc commented Aug 1, 2021

I have a CliktCommand(allowMultipleSubcommands = true)

neither the parent CliktCommand nor any of its sub-commands define any by argument() things at all.

val subCommands = listOf(
    BootstrapInfra(),
    BootstrapK3s(),
    Scratch()
)

fun main(args: Array<String>) {
    if(args.isNotEmpty()) {

        App().subcommands(subCommands).main(args)

    } else {
        // multiple default commands on no args
        App().subcommands(subCommands).main(arrayOf(
            "bootstrap-infra",
            "bootstrap-k3s"
        ))
    }
}

class App: CliktCommand(allowMultipleSubcommands = true) {
    private val log by LoggerDelegate()

    override fun aliases(): Map<String, List<String>> = mapOf(
        "infra" to listOf("bootstrap-infra"),
        "k3s" to listOf("bootstrap-k3s"),
        "s" to listOf("scratch"),
    )

    override fun run() {
        log.info("App.run() ran!")
    }
}

if I now call my App with args e.g.:

bootstrap-infra first bootstrap-k3s 'second' 'third fourth' 'fifth'

I'd expect the App to complain that there is no command first or second or ...

but these args are silently eaten up by Clikt without complaining anywhere.

(so if a user just forgot to prefix an optional opt with '--' it will now just silently be ignored)

even if I have all sub-commands with CliktCommand(printHelpOnEmptyArgs = true)

bootstrap-infra bootstrap-k3s eins "zwei drei" vier'

does not issue any error or the help.

Is that intentional or am I missing something?

@ajalt
Copy link
Owner

ajalt commented Aug 2, 2021

Thanks for the report! I'll make a new release one Kotlin 1.5.30 is out. In the mean time, you can use a snapshot build to see if the fix works for you.

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