From 66244db097c101bcff357a623eb1781cd4dc6d29 Mon Sep 17 00:00:00 2001 From: Hartmut Bauer Date: Mon, 19 Jan 2026 01:13:02 +0100 Subject: [PATCH] =?UTF-8?q?Show-Help-Optik=20verbessert,=20Kommantare=20er?= =?UTF-8?q?g=C3=A4nzt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- buildnumber.properties | 4 +- settings.gradle.kts | 2 +- .../kotlin/net/keinekekse/args/impl.kt | 44 ++++++++++++++++--- .../kotlin/net/keinekekse/args/internal.kt | 3 +- .../kotlin/net/keinekekse/util/Version.kt | 10 ++--- 5 files changed, 49 insertions(+), 14 deletions(-) diff --git a/buildnumber.properties b/buildnumber.properties index 4e78d91..f8b2234 100644 --- a/buildnumber.properties +++ b/buildnumber.properties @@ -1,3 +1,3 @@ #auto generated -#Sun Jan 18 23:38:13 CET 2026 -build.number=114 +#Mon Jan 19 01:08:01 CET 2026 +build.number=117 diff --git a/settings.gradle.kts b/settings.gradle.kts index 066964c..0850fa1 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -19,7 +19,7 @@ dependencyResolutionManagement { versionCatalogs { create("masterLibs") { // from(files("gradle/masterlibs.versions.toml")) - from("net.keinekekse:version-catalog:113") + from("net.keinekekse:version-catalog:116") } } } diff --git a/src/commonMain/kotlin/net/keinekekse/args/impl.kt b/src/commonMain/kotlin/net/keinekekse/args/impl.kt index cedcab5..2f5bd38 100644 --- a/src/commonMain/kotlin/net/keinekekse/args/impl.kt +++ b/src/commonMain/kotlin/net/keinekekse/args/impl.kt @@ -1,5 +1,6 @@ package net.keinekekse.args +import net.keinekekse.util.VERSION import net.keinekekse.version.Version /** @@ -26,9 +27,18 @@ expect fun isStdInputReady(): Boolean class VerifyParameterException(message: String) : RuntimeException(message) +/** + * Throws a [VerifyParameterException] with the specified error message. + * This function is used to signal that there was an error during argument parsing. + * + * For use in the application. The exception will be caught by the command-line parser + * and displayed to the user via showHelp(). + * + * @param msg The error message to include in the exception. + * @throws VerifyParameterException with the provided error message. + */ fun showParsingError(msg: String): Nothing { - println(ArgumentParserException.PARSING_ERROR_MSG + msg + "\n") - exitApplication(2) + throw VerifyParameterException("*** ERROR parsing arguments: $msg") } /** @@ -48,6 +58,18 @@ fun interface RunProgram { fun run(remaining: List) } +/** + * Represents a subcommand that can be added to a command-line argument parser. + * + * A `SubCommand` is used to define and configure subcommands in a CLI application, + * allowing for structured argument parsing and execution of specific logic based + * on the subcommand invoked. It provides mechanisms to add parameters to the + * subcommand, define execution logic, and manage case sensitivity for argument + * names. + * + * @property obj Internal data container for subcommand-specific configuration and parameters. + * @property ignoreCase Defines whether argument names are case-insensitive. Defaults to `false`. + */ class SubCommand private constructor( internal val obj: SubCommandData, val ignoreCase: Boolean = false, @@ -133,6 +155,18 @@ class SubCommand private constructor( } +/** + * Represents a command-line interface for parsing and executing commands, subcommands, and parameters. + * + * This class facilitates defining global parameters and subcommands, parsing provided arguments, + * validating inputs, and executing the corresponding actions. It supports various types of parameters, + * including strings, long integers, and booleans, with both optional and mandatory requirements. + * Additionally, it provides options for ignoring case sensitivity and handling remaining parameters. + * + * @param programVersion The version information of the program, including display name and copyright. + * @param ignoreCase Determines whether the parsing should ignore case sensitivity for commands and parameters. + * @param remainingDescription The description for remaining command-line arguments, or null if no arguments are allowed. + */ class CommandLine( val programVersion: Version, val ignoreCase: Boolean = false, @@ -320,7 +354,7 @@ class CommandLine( val globalParam = globalSubCommand.obj.params.isNotEmpty() val remain = remainingDescription != null - println("${programVersion.displayName} ${programVersion.version} ${programVersion.copyright}\n") + println("\n${programVersion.displayName} ${programVersion.version} ${programVersion.copyright}\n") println(programVersion.description) println() println( @@ -351,8 +385,8 @@ class CommandLine( e?.message?.let { println() println(ArgumentParserException.PARSING_ERROR_MSG + it + "\n") - println() } + println() exitApplication(0) } @@ -384,7 +418,7 @@ class CommandLine( } private fun showVersion(): Nothing { - println("${programVersion.displayName} ${programVersion.fullVersion} ${programVersion.copyright}\n") + println("\n${programVersion.displayName} ${programVersion.fullVersion} ${programVersion.copyright}\n\n(${VERSION.displayName} ${VERSION.fullVersion} ${VERSION.copyright})\n") exitApplication(0) } diff --git a/src/commonMain/kotlin/net/keinekekse/args/internal.kt b/src/commonMain/kotlin/net/keinekekse/args/internal.kt index bf11abc..cc7a879 100644 --- a/src/commonMain/kotlin/net/keinekekse/args/internal.kt +++ b/src/commonMain/kotlin/net/keinekekse/args/internal.kt @@ -152,7 +152,7 @@ interface AddParameter { internal class ArgumentParserException(message: String?) : RuntimeException(message) { companion object { const val PARSING_ERROR_MSG = "\n*** ERROR parsing arguments: " - const val DEFINITION_ERROR_MSG = "\n*** ERROR defining arguments: " + const val DEFINITION_ERROR_MSG = "\n***\n*** ERROR defining arguments in source code: " fun showHelp() = ArgumentParserException(null) fun noHelpOrVersion() = ArgumentParserException("Option 'help' and option 'version' are not allowed.") @@ -224,6 +224,7 @@ internal fun matchSubCommand(cmd: String) = internal fun matchArgument(arg: String): Pair? = ARGUMENT_PATTERN.matchEntire(arg)?.groupValues?.let { Pair(it[1] + it[2], it[3]) } +// Fehler im Quellcode anzeigen internal fun showDefiningError(msg: String): Nothing { println(ArgumentParserException.DEFINITION_ERROR_MSG + msg + "\n") exitApplication(1) diff --git a/src/commonMain/kotlin/net/keinekekse/util/Version.kt b/src/commonMain/kotlin/net/keinekekse/util/Version.kt index bb52d5d..c2465c1 100644 --- a/src/commonMain/kotlin/net/keinekekse/util/Version.kt +++ b/src/commonMain/kotlin/net/keinekekse/util/Version.kt @@ -3,14 +3,14 @@ package net.keinekekse.util import net.keinekekse.version.Version object VERSION: Version { - override val version = "0.3.0-beta.5+build.114" - override val fullVersion = "0.3.0-beta.5+build.114" + override val version = "0.3.0-beta.8+build.117" + override val fullVersion = "0.3.0-beta.8+build.117" override val major = 0 override val minor = 3 override val patch = 0 - override val preRelease = "beta.5" - override val buildMetadata = "build.114" - override val buildDate = "2026-01-18T22:38:13.309402Z" + override val preRelease = "beta.8" + override val buildMetadata = "build.117" + override val buildDate = "2026-01-19T00:08:01.397532Z" override val displayName = "Utility Library" override val copyright = "Copyright (c) 2025-2026 Hartmut Bauer" override val name = "util"