small refactor
This commit is contained in:
@@ -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,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user