Show-Help-Optik verbessert, Kommantare ergänzt
This commit is contained in:
1 parent
b580e64e76
commit
66244db097
5 files changed
+49
-14
No files matched your search
@@ -1,3 +1,3 @@
|
|||||||
#auto generated
|
#auto generated
|
||||||
#Sun Jan 18 23:38:13 CET 2026
|
#Mon Jan 19 01:08:01 CET 2026
|
||||||
build.number=114
|
build.number=117
|
||||||
+1
-1
@@ -19,7 +19,7 @@ dependencyResolutionManagement {
|
|||||||
versionCatalogs {
|
versionCatalogs {
|
||||||
create("masterLibs") {
|
create("masterLibs") {
|
||||||
// from(files("gradle/masterlibs.versions.toml"))
|
// from(files("gradle/masterlibs.versions.toml"))
|
||||||
from("net.keinekekse:version-catalog:113")
|
from("net.keinekekse:version-catalog:116")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package net.keinekekse.args
|
package net.keinekekse.args
|
||||||
|
|
||||||
|
import net.keinekekse.util.VERSION
|
||||||
import net.keinekekse.version.Version
|
import net.keinekekse.version.Version
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -26,9 +27,18 @@ expect fun isStdInputReady(): Boolean
|
|||||||
|
|
||||||
class VerifyParameterException(message: String) : RuntimeException(message)
|
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 {
|
fun showParsingError(msg: String): Nothing {
|
||||||
println(ArgumentParserException.PARSING_ERROR_MSG + msg + "\n")
|
throw VerifyParameterException("*** ERROR parsing arguments: $msg")
|
||||||
exitApplication(2)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -48,6 +58,18 @@ fun interface RunProgram {
|
|||||||
fun run(remaining: List<String>)
|
fun run(remaining: List<String>)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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(
|
class SubCommand private constructor(
|
||||||
internal val obj: SubCommandData,
|
internal val obj: SubCommandData,
|
||||||
val ignoreCase: Boolean = false,
|
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(
|
class CommandLine(
|
||||||
val programVersion: Version,
|
val programVersion: Version,
|
||||||
val ignoreCase: Boolean = false,
|
val ignoreCase: Boolean = false,
|
||||||
@@ -320,7 +354,7 @@ class CommandLine(
|
|||||||
val globalParam = globalSubCommand.obj.params.isNotEmpty()
|
val globalParam = globalSubCommand.obj.params.isNotEmpty()
|
||||||
val remain = remainingDescription != null
|
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(programVersion.description)
|
||||||
println()
|
println()
|
||||||
println(
|
println(
|
||||||
@@ -351,8 +385,8 @@ class CommandLine(
|
|||||||
e?.message?.let {
|
e?.message?.let {
|
||||||
println()
|
println()
|
||||||
println(ArgumentParserException.PARSING_ERROR_MSG + it + "\n")
|
println(ArgumentParserException.PARSING_ERROR_MSG + it + "\n")
|
||||||
println()
|
|
||||||
}
|
}
|
||||||
|
println()
|
||||||
exitApplication(0)
|
exitApplication(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -384,7 +418,7 @@ class CommandLine(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun showVersion(): Nothing {
|
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)
|
exitApplication(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ interface AddParameter {
|
|||||||
internal class ArgumentParserException(message: String?) : RuntimeException(message) {
|
internal class ArgumentParserException(message: String?) : RuntimeException(message) {
|
||||||
companion object {
|
companion object {
|
||||||
const val PARSING_ERROR_MSG = "\n*** ERROR parsing arguments: "
|
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 showHelp() = ArgumentParserException(null)
|
||||||
fun noHelpOrVersion() =
|
fun noHelpOrVersion() =
|
||||||
ArgumentParserException("Option 'help' and option 'version' are not allowed.")
|
ArgumentParserException("Option 'help' and option 'version' are not allowed.")
|
||||||
@@ -224,6 +224,7 @@ internal fun matchSubCommand(cmd: String) =
|
|||||||
internal fun matchArgument(arg: String): Pair<String, String>? =
|
internal fun matchArgument(arg: String): Pair<String, String>? =
|
||||||
ARGUMENT_PATTERN.matchEntire(arg)?.groupValues?.let { Pair(it[1] + it[2], it[3]) }
|
ARGUMENT_PATTERN.matchEntire(arg)?.groupValues?.let { Pair(it[1] + it[2], it[3]) }
|
||||||
|
|
||||||
|
// Fehler im Quellcode anzeigen
|
||||||
internal fun showDefiningError(msg: String): Nothing {
|
internal fun showDefiningError(msg: String): Nothing {
|
||||||
println(ArgumentParserException.DEFINITION_ERROR_MSG + msg + "\n")
|
println(ArgumentParserException.DEFINITION_ERROR_MSG + msg + "\n")
|
||||||
exitApplication(1)
|
exitApplication(1)
|
||||||
|
|||||||
@@ -3,14 +3,14 @@ package net.keinekekse.util
|
|||||||
import net.keinekekse.version.Version
|
import net.keinekekse.version.Version
|
||||||
|
|
||||||
object VERSION: Version {
|
object VERSION: Version {
|
||||||
override val version = "0.3.0-beta.5+build.114"
|
override val version = "0.3.0-beta.8+build.117"
|
||||||
override val fullVersion = "0.3.0-beta.5+build.114"
|
override val fullVersion = "0.3.0-beta.8+build.117"
|
||||||
override val major = 0
|
override val major = 0
|
||||||
override val minor = 3
|
override val minor = 3
|
||||||
override val patch = 0
|
override val patch = 0
|
||||||
override val preRelease = "beta.5"
|
override val preRelease = "beta.8"
|
||||||
override val buildMetadata = "build.114"
|
override val buildMetadata = "build.117"
|
||||||
override val buildDate = "2026-01-18T22:38:13.309402Z"
|
override val buildDate = "2026-01-19T00:08:01.397532Z"
|
||||||
override val displayName = "Utility Library"
|
override val displayName = "Utility Library"
|
||||||
override val copyright = "Copyright (c) 2025-2026 Hartmut Bauer"
|
override val copyright = "Copyright (c) 2025-2026 Hartmut Bauer"
|
||||||
override val name = "util"
|
override val name = "util"
|
||||||
|
|||||||
Reference in new issue
Block a user