1.4.0 release #9

Merged
Infendro merged 20 commits from develop into main 2026-01-10 07:37:21 +00:00
3 changed files with 34 additions and 33 deletions
Showing only changes of commit 6779e28792 - Show all commits

View File

@@ -21,46 +21,47 @@ repositories {
} }
dependencies { dependencies {
implementation("com.infendro:cli:1.3.1") implementation("com.infendro:cli:1.4.0")
} }
``` ```
## Usage ## Usage
```kotlin ```kotlin
fun main(args: Array<String>) { fun main(args: Array<String>) = cli {
// declare root command execute {
cli { // 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 { 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" // declare more commands...
command("test") { }
// declare arguments
val greetingArg = stringOrElse("greeting", "greet", "g", other = "Hello")
val nameArg = stringOrNull("name", "n")
execute { // declare fallback command
// retrieve the arguments command { valueCmd ->
val greeting by greetingArg execute {
val name by nameArg // retrieve the value used for the fallback command
val value by valueCmd
println("$greeting ${name ?: "World"}!") println("""command "$value" executed!""")
}
// declare more commands...
} }
}
// declare wildcard command }.run(args)
command { wildcard ->
execute {
// retrieve the value used for the wildcard command
val value by wildcard
println("command $value executed!")
}
}
}.run(args)
}
``` ```

View File

@@ -2,7 +2,7 @@ import com.infendro.plugin.infendro
import com.infendro.plugin.token import com.infendro.plugin.token
group = "com.infendro" group = "com.infendro"
version = "1.3.1" version = "1.4.0"
plugins { plugins {
alias(libs.plugins.infendro) alias(libs.plugins.infendro)

View File

@@ -10,8 +10,8 @@ import com.infendro.cli.util.Regex.OPTION
class Command private constructor( class Command private constructor(
val name: String?, val name: String?,
val commands: List<Command>, val commands: List<Command>,
val options: List<Option<*>>,
val arguments: List<Argument<*>>, val arguments: List<Argument<*>>,
val options: List<Option<*>>,
internal val execute: Context.() -> Unit, internal val execute: Context.() -> Unit,
) { ) {
val fallback: Boolean val fallback: Boolean
@@ -97,7 +97,7 @@ class Command private constructor(
if (!::_execute.isInitialized) if (!::_execute.isInitialized)
_execute = {} _execute = {}
return Command(name, commands, options, arguments, _execute) return Command(name, commands, arguments, options, _execute)
} }
} }