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:
@@ -0,0 +1,3 @@
|
||||
package com.infendro.cli.exception
|
||||
|
||||
abstract class CliException : Exception()
|
||||
@@ -0,0 +1,3 @@
|
||||
package com.infendro.cli.exception.build
|
||||
|
||||
class NoArgumentNameException : Exception()
|
||||
@@ -1,7 +0,0 @@
|
||||
package com.infendro.cli.exception.run
|
||||
|
||||
class ArgumentCountException(
|
||||
val argument: String,
|
||||
val min: Int,
|
||||
val max: Int,
|
||||
) : Exception()
|
||||
@@ -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""""
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package com.infendro.cli.exception.run
|
||||
|
||||
class InvalidArgumentException(
|
||||
val argument: String,
|
||||
) : Exception()
|
||||
@@ -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""""
|
||||
}
|
||||
@@ -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""""
|
||||
}
|
||||
@@ -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"""
|
||||
}
|
||||
@@ -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""""
|
||||
}
|
||||
|
||||
@@ -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""""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user