From f2f78b6c488e2425ae335f11594474bd0756c151 Mon Sep 17 00:00:00 2001 From: Pavel Kunyavskiy Date: Mon, 16 Oct 2023 21:08:13 +0200 Subject: [PATCH] Better help messages in cds-converter. --- src/cds-converter/src/main/kotlin/Application.kt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/cds-converter/src/main/kotlin/Application.kt b/src/cds-converter/src/main/kotlin/Application.kt index 2beda8c13..8b4ef74be 100644 --- a/src/cds-converter/src/main/kotlin/Application.kt +++ b/src/cds-converter/src/main/kotlin/Application.kt @@ -5,9 +5,11 @@ package org.icpclive import ClicsExporter import com.github.ajalt.clikt.core.* import com.github.ajalt.clikt.output.MordantHelpFormatter +import com.github.ajalt.clikt.parameters.arguments.* import com.github.ajalt.clikt.parameters.groups.* import com.github.ajalt.clikt.parameters.options.* import com.github.ajalt.clikt.parameters.types.* +import com.github.ajalt.mordant.rendering.TextColors import io.ktor.http.* import io.ktor.serialization.kotlinx.json.* import io.ktor.server.application.* @@ -153,13 +155,21 @@ object ServerCommand : CliktCommand(name = "server", help = "Start as http serve } } -object MainCommand : CliktCommand(name = "java -jar cds-converter.jar") { +object MainCommand : CliktCommand(name = "java -jar cds-converter.jar", invokeWithoutSubcommand = true, treatUnknownOptionsAsArgs = true) { init { context { helpFormatter = { MordantHelpFormatter(it, showRequiredTag = true, showDefaultValues = true)} } } + val unused by argument().multiple() override fun run() { + if (currentContext.invokedSubcommand == null) { + if (unused.isNotEmpty()) { + currentContext.terminal.danger("Unknown command ${unused.firstOrNull()}") + currentContext.terminal.info("") + } + throw PrintHelpMessage(currentContext, true) + } } }