move class

This commit is contained in:
2025-08-18 00:12:41 +02:00
parent fc416d3bbb
commit aedcb9c68a
2 changed files with 8 additions and 9 deletions

View File

@@ -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

View 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) }
}
}