Compare commits
2 Commits
52b4fd8fcb
...
889f5ddb6c
| Author | SHA1 | Date | |
|---|---|---|---|
|
889f5ddb6c
|
|||
|
d02fdfa53d
|
71
README.md
Normal file
71
README.md
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
# Kotlin CLI
|
||||||
|
|
||||||
|
This library implements a lightweight framework for implementing terminal applications.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
* Declare commands.
|
||||||
|
* Supports both named and wildcard commands.
|
||||||
|
* Declare and parse type-safe arguments.
|
||||||
|
* Multiplatform support
|
||||||
|
* JVM
|
||||||
|
* JavaScript
|
||||||
|
* Native (Linux)
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
Add the following to your `build.gradle.kts`.
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
repositories {
|
||||||
|
maven("https://git.infendro.com/api/packages/Infendro/maven")
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation("com.infendro:cli:1.3.0")
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
import com.infendro.cli.argument.stringOrElse
|
||||||
|
import com.infendro.cli.argument.stringOrNull
|
||||||
|
import com.infendro.cli.command.cli
|
||||||
|
|
||||||
|
fun main(args: Array<String>) {
|
||||||
|
// declare root command
|
||||||
|
cli {
|
||||||
|
execute {
|
||||||
|
// execution of root command (e.g., display help)
|
||||||
|
}
|
||||||
|
|
||||||
|
// declare command "test"
|
||||||
|
command("test") {
|
||||||
|
// declare arguments
|
||||||
|
val greetingArg = stringOrElse("greeting", "Hello")
|
||||||
|
val nameArg = stringOrNull("name")
|
||||||
|
|
||||||
|
execute {
|
||||||
|
// retrieve the arguments
|
||||||
|
val greeting by greetingArg
|
||||||
|
val name by nameArg
|
||||||
|
|
||||||
|
println("$greeting ${name ?: "World"}!")
|
||||||
|
}
|
||||||
|
|
||||||
|
// declare more commands...
|
||||||
|
}
|
||||||
|
|
||||||
|
// declare wildcard command
|
||||||
|
command { wildcard ->
|
||||||
|
execute {
|
||||||
|
// retrieve the value used for the wildcard command
|
||||||
|
val value by wildcard
|
||||||
|
|
||||||
|
println("command $value executed!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.run(args)
|
||||||
|
}
|
||||||
|
```
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
group = "com.infendro"
|
group = "com.infendro"
|
||||||
version = "1.2.2"
|
version = "1.3.0"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
|||||||
Reference in New Issue
Block a user