small refactor

This commit is contained in:
2025-12-13 20:23:34 +01:00
parent ebd698e611
commit 757011af85
3 changed files with 18 additions and 37 deletions

View File

@@ -1,6 +1,5 @@
package com.infendro.cli.command
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
@@ -24,8 +23,7 @@ class Command private constructor(
fun run(
args: Array<String>,
) {
val index = args
.withIndex()
val index = args.withIndex()
.find { (_, value) -> value.startsWith("--") }
?.index ?: args.size
@@ -89,12 +87,11 @@ class Command private constructor(
result += Execution.Arg(name, value)
}
arguments
.forEach { argument ->
val count = result.count { it.name == argument.name }
if (count !in argument.min..argument.max)
throw ArgumentCountException(argument.name, argument.min, argument.max)
}
arguments.forEach { argument ->
val count = result.count { it.name == argument.name }
if (count !in argument.min..argument.max)
throw ArgumentCountException(argument.name, argument.min, argument.max)
}
return result
}
@@ -164,7 +161,7 @@ class Command private constructor(
}
}
class Key(
class Key internal constructor(
internal val index: Int,
)
}