Compare commits
4 Commits
889f5ddb6c
...
6be1957d82
| Author | SHA1 | Date | |
|---|---|---|---|
|
6be1957d82
|
|||
|
757011af85
|
|||
|
ebd698e611
|
|||
|
810c2d4263
|
@@ -4,7 +4,7 @@ on:
|
|||||||
- main
|
- main
|
||||||
|
|
||||||
env:
|
env:
|
||||||
GIT__TOKEN: ${{ secrets.TOKEN }}
|
INFENDRO__TOKEN: ${{ secrets.TOKEN }}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
publish:
|
publish:
|
||||||
|
|||||||
19
README.md
19
README.md
@@ -1,16 +1,15 @@
|
|||||||
# Kotlin CLI
|
# cli-kt
|
||||||
|
|
||||||
This library implements a lightweight framework for implementing terminal applications.
|
`cli-kt` is a Kotlin Multiplatform framework for implementing terminal applications.
|
||||||
|
|
||||||
## Features
|
## Targets
|
||||||
|
|
||||||
* Declare commands.
|
| Target | Status |
|
||||||
* Supports both named and wildcard commands.
|
|------------------|---------------|
|
||||||
* Declare and parse type-safe arguments.
|
| JVM | Supported |
|
||||||
* Multiplatform support
|
| JavaScript | Supported |
|
||||||
* JVM
|
| Native (Linux) | Supported |
|
||||||
* JavaScript
|
| Native (Windows) | Not Supported |
|
||||||
* Native (Linux)
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
|
import com.infendro.plugin.infendro
|
||||||
|
import com.infendro.plugin.token
|
||||||
|
|
||||||
group = "com.infendro"
|
group = "com.infendro"
|
||||||
version = "1.3.0"
|
version = "1.3.0"
|
||||||
|
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
|
alias(libs.plugins.infendro)
|
||||||
alias(libs.plugins.multiplatform)
|
alias(libs.plugins.multiplatform)
|
||||||
id("maven-publish")
|
id("maven-publish")
|
||||||
}
|
}
|
||||||
@@ -16,33 +16,12 @@ kotlin {
|
|||||||
nodejs()
|
nodejs()
|
||||||
}
|
}
|
||||||
linuxX64()
|
linuxX64()
|
||||||
}
|
|
||||||
|
|
||||||
publishing {
|
|
||||||
repositories {
|
repositories {
|
||||||
maven {
|
mavenCentral()
|
||||||
url = uri("https://git.infendro.com/api/packages/Infendro/maven")
|
|
||||||
authentication.create("header", HttpHeaderAuthentication::class)
|
|
||||||
credentials(HttpHeaderCredentials::class) {
|
|
||||||
val token = secret("git.token") ?: throw GradleException()
|
|
||||||
|
|
||||||
name = "Authorization"
|
|
||||||
value = "token $token"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun secret(
|
publishing.repositories {
|
||||||
key: String,
|
infendro(token)
|
||||||
): String? {
|
|
||||||
val property = key
|
|
||||||
val environment = key
|
|
||||||
.uppercase()
|
|
||||||
.replace(".", "__")
|
|
||||||
|
|
||||||
val prop = properties[property] as String?
|
|
||||||
val env = System.getenv(environment)
|
|
||||||
|
|
||||||
return prop ?: env
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
[versions]
|
[versions]
|
||||||
kotlin = "2.2.10"
|
infendro = "1.0.0"
|
||||||
|
kotlin = "2.2.21"
|
||||||
|
|
||||||
[plugins]
|
[plugins]
|
||||||
|
infendro = { id = "com.infendro.plugin", version.ref = "infendro" }
|
||||||
multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
|
multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
|
||||||
|
|||||||
@@ -1 +1,6 @@
|
|||||||
rootProject.name = "cli"
|
rootProject.name = "cli"
|
||||||
|
|
||||||
|
pluginManagement.repositories {
|
||||||
|
maven("https://git.infendro.com/api/packages/Infendro/maven")
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.infendro.cli.command
|
package com.infendro.cli.command
|
||||||
|
|
||||||
import com.infendro.cli.command.Execution
|
|
||||||
import com.infendro.cli.argument.Argument
|
import com.infendro.cli.argument.Argument
|
||||||
import com.infendro.cli.exception.build.*
|
import com.infendro.cli.exception.build.*
|
||||||
import com.infendro.cli.exception.run.ArgumentCountException
|
import com.infendro.cli.exception.run.ArgumentCountException
|
||||||
@@ -24,8 +23,7 @@ class Command private constructor(
|
|||||||
fun run(
|
fun run(
|
||||||
args: Array<String>,
|
args: Array<String>,
|
||||||
) {
|
) {
|
||||||
val index = args
|
val index = args.withIndex()
|
||||||
.withIndex()
|
|
||||||
.find { (_, value) -> value.startsWith("--") }
|
.find { (_, value) -> value.startsWith("--") }
|
||||||
?.index ?: args.size
|
?.index ?: args.size
|
||||||
|
|
||||||
@@ -89,8 +87,7 @@ class Command private constructor(
|
|||||||
result += Execution.Arg(name, value)
|
result += Execution.Arg(name, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
arguments
|
arguments.forEach { argument ->
|
||||||
.forEach { argument ->
|
|
||||||
val count = result.count { it.name == argument.name }
|
val count = result.count { it.name == argument.name }
|
||||||
if (count !in argument.min..argument.max)
|
if (count !in argument.min..argument.max)
|
||||||
throw ArgumentCountException(argument.name, argument.min, argument.max)
|
throw ArgumentCountException(argument.name, argument.min, argument.max)
|
||||||
@@ -164,7 +161,7 @@ class Command private constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Key(
|
class Key internal constructor(
|
||||||
internal val index: Int,
|
internal val index: Int,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,45 +19,29 @@ class Execution(
|
|||||||
operator fun Command.Key.getValue(
|
operator fun Command.Key.getValue(
|
||||||
thisRef: Any?,
|
thisRef: Any?,
|
||||||
property: KProperty<*>,
|
property: KProperty<*>,
|
||||||
): String {
|
): String = commands[index].name
|
||||||
return commands[index]
|
|
||||||
.name
|
|
||||||
}
|
|
||||||
|
|
||||||
operator fun <T> Argument.Single<T>.getValue(
|
operator fun <T> Argument.Single<T>.getValue(
|
||||||
thisRef: Any?,
|
thisRef: Any?,
|
||||||
property: KProperty<*>,
|
property: KProperty<*>,
|
||||||
): T {
|
): T = arguments.single { it.name == name }
|
||||||
return arguments
|
|
||||||
.single { it.name == name }
|
|
||||||
.let { parser.parse(it.value) }
|
.let { parser.parse(it.value) }
|
||||||
}
|
|
||||||
|
|
||||||
operator fun <T> Argument.SingleOrElse<T>.getValue(
|
operator fun <T> Argument.SingleOrElse<T>.getValue(
|
||||||
thisRef: Any?,
|
thisRef: Any?,
|
||||||
property: KProperty<*>,
|
property: KProperty<*>,
|
||||||
): T {
|
): T = arguments.singleOrNull { it.name == name }
|
||||||
return arguments
|
?.let { parser.parse(it.value) } ?: other
|
||||||
.singleOrNull { it.name == name }
|
|
||||||
?.let { parser.parse(it.value) }
|
|
||||||
?: other
|
|
||||||
}
|
|
||||||
|
|
||||||
operator fun <T> Argument.SingleOrNull<T>.getValue(
|
operator fun <T> Argument.SingleOrNull<T>.getValue(
|
||||||
thisRef: Any?,
|
thisRef: Any?,
|
||||||
property: KProperty<*>,
|
property: KProperty<*>,
|
||||||
): T? {
|
): T? = arguments.singleOrNull { it.name == name }
|
||||||
return arguments
|
|
||||||
.singleOrNull { it.name == name }
|
|
||||||
?.let { parser.parse(it.value) }
|
?.let { parser.parse(it.value) }
|
||||||
}
|
|
||||||
|
|
||||||
operator fun <T> Argument.Multiple<T>.getValue(
|
operator fun <T> Argument.Multiple<T>.getValue(
|
||||||
thisRef: Any?,
|
thisRef: Any?,
|
||||||
property: KProperty<*>,
|
property: KProperty<*>,
|
||||||
): List<T> {
|
): List<T> = arguments.filter { it.name == name }
|
||||||
return arguments
|
|
||||||
.filter { it.name == name }
|
|
||||||
.map { parser.parse(it.value) }
|
.map { parser.parse(it.value) }
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user