move class
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package com.infendro.cli.command
|
||||
|
||||
import com.infendro.cli.Execution
|
||||
import com.infendro.cli.command.Execution
|
||||
import com.infendro.cli.argument.Argument
|
||||
import com.infendro.cli.exception.build.*
|
||||
import com.infendro.cli.exception.run.ArgumentCountException
|
||||
|
||||
65
src/commonMain/kotlin/com/infendro/cli/command/Execution.kt
Normal file
65
src/commonMain/kotlin/com/infendro/cli/command/Execution.kt
Normal file
@@ -0,0 +1,65 @@
|
||||
package com.infendro.cli.command
|
||||
|
||||
import com.infendro.cli.argument.Argument
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
class Execution(
|
||||
val commands: List<Cmd>,
|
||||
val arguments: List<Arg>,
|
||||
) {
|
||||
class Cmd(
|
||||
val name: String,
|
||||
)
|
||||
|
||||
class Arg(
|
||||
val name: String,
|
||||
val value: String?,
|
||||
)
|
||||
|
||||
operator fun Command.Key.getValue(
|
||||
thisRef: Any?,
|
||||
property: KProperty<*>,
|
||||
): String {
|
||||
return commands[index]
|
||||
.name
|
||||
}
|
||||
|
||||
operator fun <T> Argument.Single<T>.getValue(
|
||||
thisRef: Any?,
|
||||
property: KProperty<*>,
|
||||
): T {
|
||||
return parser.parse(
|
||||
arguments
|
||||
.find { it.name == name }!!
|
||||
.value
|
||||
)
|
||||
}
|
||||
|
||||
operator fun <T> Argument.SingleOrElse<T>.getValue(
|
||||
thisRef: Any?,
|
||||
property: KProperty<*>,
|
||||
): T {
|
||||
return arguments
|
||||
.find { it.name == name }
|
||||
?.let { parser.parse(it.value) }
|
||||
?: other
|
||||
}
|
||||
|
||||
operator fun <T> Argument.SingleOrNull<T>.getValue(
|
||||
thisRef: Any?,
|
||||
property: KProperty<*>,
|
||||
): T? {
|
||||
return arguments
|
||||
.find { it.name == name }
|
||||
?.let { parser.parse(it.value) }
|
||||
}
|
||||
|
||||
operator fun <T> Argument.Multiple<T>.getValue(
|
||||
thisRef: Any?,
|
||||
property: KProperty<*>,
|
||||
): List<T> {
|
||||
return arguments
|
||||
.filter { it.name == name }
|
||||
.map { parser.parse(it.value) }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user