From 6779e28792133a6ac9bbeceaebcd53c5b027e084 Mon Sep 17 00:00:00 2001 From: Infendro Date: Mon, 5 Jan 2026 15:56:14 +0100 Subject: [PATCH] bump version to 1.4.0 --- README.md | 61 ++++++++++--------- build.gradle.kts | 2 +- .../com/infendro/cli/command/Command.kt | 4 +- 3 files changed, 34 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index fdcbe38..9f11455 100644 --- a/README.md +++ b/README.md @@ -21,46 +21,47 @@ repositories { } dependencies { - implementation("com.infendro:cli:1.3.1") + implementation("com.infendro:cli:1.4.0") } ``` ## Usage ```kotlin -fun main(args: Array) { - // declare root command - cli { +fun main(args: Array) = cli { + execute { + // define execution of command (e.g., display help) + } + + // declare command "greet" + command("greet") { + // declare arguments + val speakersArg = Argument.strings().register() + + // declare options + val greetingOpt = Option.stringOrElse("greeting", "greet", "g", other = "Hello").register() + val nameOpt = Option.stringOrNull("name", "n").register() + execute { - // execution of root command (e.g., display help) + // retrieve the arguments and options + val speakers by speakersArg + val greeting by greetingOpt + val name by nameOpt + + println("${speakers.joinToString()}: $greeting ${name ?: "World"}!") } - // declare command "test" - command("test") { - // declare arguments - val greetingArg = stringOrElse("greeting", "greet", "g", other = "Hello") - val nameArg = stringOrNull("name", "n") + // declare more commands... + } - execute { - // retrieve the arguments - val greeting by greetingArg - val name by nameArg + // declare fallback command + command { valueCmd -> + execute { + // retrieve the value used for the fallback command + val value by valueCmd - println("$greeting ${name ?: "World"}!") - } - - // declare more commands... + println("""command "$value" executed!""") } - - // declare wildcard command - command { wildcard -> - execute { - // retrieve the value used for the wildcard command - val value by wildcard - - println("command $value executed!") - } - } - }.run(args) -} + } +}.run(args) ``` diff --git a/build.gradle.kts b/build.gradle.kts index df76f3b..9df02c6 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,7 +2,7 @@ import com.infendro.plugin.infendro import com.infendro.plugin.token group = "com.infendro" -version = "1.3.1" +version = "1.4.0" plugins { alias(libs.plugins.infendro) diff --git a/src/commonMain/kotlin/com/infendro/cli/command/Command.kt b/src/commonMain/kotlin/com/infendro/cli/command/Command.kt index 877c916..b9b32c4 100644 --- a/src/commonMain/kotlin/com/infendro/cli/command/Command.kt +++ b/src/commonMain/kotlin/com/infendro/cli/command/Command.kt @@ -10,8 +10,8 @@ import com.infendro.cli.util.Regex.OPTION class Command private constructor( val name: String?, val commands: List, - val options: List>, val arguments: List>, + val options: List>, internal val execute: Context.() -> Unit, ) { val fallback: Boolean @@ -97,7 +97,7 @@ class Command private constructor( if (!::_execute.isInitialized) _execute = {} - return Command(name, commands, options, arguments, _execute) + return Command(name, commands, arguments, options, _execute) } }