improve argument/option declaration
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
package com.infendro.cli.command
|
||||
|
||||
import com.infendro.cli.Dsl
|
||||
import com.infendro.cli.command.context.Context
|
||||
import com.infendro.cli.command.context.Parser
|
||||
import com.infendro.cli.exception.build.*
|
||||
import com.infendro.cli.exception.run.CliException
|
||||
import com.infendro.cli.util.Regex.COMMAND
|
||||
import com.infendro.cli.util.Regex.OPTION
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
class Command private constructor(
|
||||
val name: String?,
|
||||
@@ -23,6 +25,7 @@ class Command private constructor(
|
||||
println(e.message)
|
||||
}
|
||||
|
||||
@Dsl
|
||||
class Builder internal constructor(
|
||||
private val level: Int,
|
||||
private val name: String?,
|
||||
@@ -68,10 +71,10 @@ class Command private constructor(
|
||||
arguments += argument
|
||||
}
|
||||
|
||||
fun <T : Argument<*>> T.register() = also(::argument)
|
||||
|
||||
fun arguments(vararg arguments: Argument<*>) = arguments.forEach(::argument)
|
||||
fun <T : Argument<*>> Array<T>.register() = also(::arguments)
|
||||
|
||||
operator fun <T : Argument<*>> T.provideDelegate(thisRef: Nothing?, property: KProperty<*>) = also(::argument)
|
||||
operator fun <T : Argument<*>> T.getValue(thisRef: Nothing?, property: KProperty<*>) = this
|
||||
|
||||
fun option(option: Option<*>) {
|
||||
// validate
|
||||
@@ -85,10 +88,10 @@ class Command private constructor(
|
||||
options += option
|
||||
}
|
||||
|
||||
fun <T : Option<*>> T.register() = also(::option)
|
||||
|
||||
fun options(vararg options: Option<*>) = options.forEach(::option)
|
||||
fun <T : Option<*>> Array<T>.register() = also(::options)
|
||||
|
||||
operator fun <T : Option<*>> T.provideDelegate(thisRef: Nothing?, property: KProperty<*>) = also(::option)
|
||||
operator fun <T : Option<*>> T.getValue(thisRef: Nothing?, property: KProperty<*>) = this
|
||||
|
||||
fun execute(block: Context.() -> Unit) {
|
||||
if (::_execute.isInitialized)
|
||||
|
||||
Reference in New Issue
Block a user