refactor argument system

- arguments can have multiple names simultaneously
- argument values can be passed using spaces (e.g., --arg value)
- single-character arguments can be passed using a single dash (e.g., --a -> -a)
- multiple single-character arguments can be combined (e.g., -a -b -> -ab)
- simplify custom arguments using generic classes
This commit is contained in:
2025-12-27 17:30:05 +01:00
parent 6be1957d82
commit 79629ae68d
17 changed files with 258 additions and 388 deletions

View File

@@ -1,7 +0,0 @@
package com.infendro.cli.exception.run
class ArgumentCountException(
val argument: String,
val min: Int,
val max: Int,
) : Exception()

View File

@@ -0,0 +1,10 @@
package com.infendro.cli.exception.run
import com.infendro.cli.exception.CliException
class DuplicateArgumentException(
val argument: String,
) : CliException() {
override val message: String
get() = """duplicate argument "$argument""""
}

View File

@@ -1,5 +0,0 @@
package com.infendro.cli.exception.run
class InvalidArgumentException(
val argument: String,
) : Exception()

View File

@@ -0,0 +1,10 @@
package com.infendro.cli.exception.run
import com.infendro.cli.exception.CliException
class MalformedArgumentException(
val argument: String,
) : CliException() {
override val message: String
get() = """malformed argument "$argument""""
}

View File

@@ -0,0 +1,10 @@
package com.infendro.cli.exception.run
import com.infendro.cli.exception.CliException
class MissingArgumentException(
val argument: String,
) : CliException() {
override val message: String
get() = """missing argument "$argument""""
}

View File

@@ -0,0 +1,11 @@
package com.infendro.cli.exception.run
import com.infendro.cli.exception.CliException
class ParseException(
val text: String?,
val type: String,
) : CliException() {
override val message: String
get() = """"$text" cannot be converted to $type"""
}

View File

@@ -1,5 +1,10 @@
package com.infendro.cli.exception.run
import com.infendro.cli.exception.CliException
class UnknownArgumentException(
val argument: String,
) : Exception()
) : CliException() {
override val message: String
get() = """unknown argument "$argument""""
}

View File

@@ -1,5 +1,10 @@
package com.infendro.cli.exception.run
import com.infendro.cli.exception.CliException
class UnknownCommandException(
val command: String,
) : Exception()
) : CliException() {
override val message: String
get() = """unknown command "$command""""
}