improve help
display type for fallback commands display type and range for arguments/options
This commit is contained in:
@@ -23,8 +23,8 @@ sealed class Command private constructor(
|
||||
if (!name.matches(Regex.COMMAND)) throw InvalidCommandName(name)
|
||||
}
|
||||
|
||||
fun run(args: Array<String>) {
|
||||
when (val result = ContextParser(this, args).parse()) {
|
||||
fun run(vararg args: String) {
|
||||
when (val result = ContextParser(this, arrayOf(*args)).parse()) {
|
||||
is ContextParser.Result.Success -> result.context.execute()
|
||||
is ContextParser.Result.Help -> {
|
||||
val command = result.path.last()
|
||||
@@ -144,7 +144,7 @@ sealed class Command private constructor(
|
||||
val last = commands.last()
|
||||
if (last is Fallback<*>) throw InvalidCommandOrder()
|
||||
}
|
||||
if (commands.any { it.name == command.name }) throw DuplicateCommand(command.name)
|
||||
if (commands.any { it.name == command.name }) throw DuplicateCommand(command)
|
||||
}
|
||||
|
||||
private fun validateArgument(argument: Argument<*>) {
|
||||
@@ -155,12 +155,12 @@ sealed class Command private constructor(
|
||||
argument.required && last.optional -> throw InvalidArgumentOrder()
|
||||
}
|
||||
}
|
||||
if (arguments.any { it.name == argument.name }) throw DuplicateArgument(argument.name)
|
||||
if (arguments.any { it.name == argument.name }) throw DuplicateArgument(argument)
|
||||
}
|
||||
|
||||
private fun validateOption(option: Option<*>) {
|
||||
for (name in option.names) {
|
||||
if (options.any { name in it.names }) throw DuplicateOption(name)
|
||||
if (options.any { name in it.names }) throw DuplicateOption(option)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user