diff options
author | Linnea Gräf <nea@nea.moe> | 2024-03-14 13:35:40 +0100 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-03-14 13:37:30 +0100 |
commit | 5a74c504da44a9dbea11da2129c2a72be8767d97 (patch) | |
tree | 29b1f07d24155dfc8ad040bc5319e0ef44ad6a55 /src | |
parent | f5862b8edb1fe025eaf1c529764f1d9aab838cbe (diff) | |
download | SkyHanniChangelogBuilder-5a74c504da44a9dbea11da2129c2a72be8767d97.tar.gz SkyHanniChangelogBuilder-5a74c504da44a9dbea11da2129c2a72be8767d97.tar.bz2 SkyHanniChangelogBuilder-5a74c504da44a9dbea11da2129c2a72be8767d97.zip |
Add check specific PR WIPautoverify
Diffstat (limited to 'src')
-rw-r--r-- | src/main/kotlin/at/hannibal2/skyhanni/changelog/Arguments.kt | 69 | ||||
-rw-r--r-- | src/main/kotlin/at/hannibal2/skyhanni/changelog/CheckSpecificPR.kt | 13 |
2 files changed, 82 insertions, 0 deletions
diff --git a/src/main/kotlin/at/hannibal2/skyhanni/changelog/Arguments.kt b/src/main/kotlin/at/hannibal2/skyhanni/changelog/Arguments.kt new file mode 100644 index 0000000..503de42 --- /dev/null +++ b/src/main/kotlin/at/hannibal2/skyhanni/changelog/Arguments.kt @@ -0,0 +1,69 @@ +package at.hannibal2.skyhanni.changelog + +class Arguments { + private val flags = mutableMapOf<String, Flag>() + + sealed interface Flag + data class BooleanFlag(var set: Boolean) : Flag + data class StringFlag(var value: String?) : Flag + + + fun <T : Flag> registerFlag(name: String, flag: T): T { + require(name.matches(Regex("^[a-z][a-z\\-]*$")) && !name.startsWith("no-")) + flags[name] = flag + return flag + } + + fun string(name: String): StringFlag { + return registerFlag(name, StringFlag(null)) + } + + fun bool(name: String, default: Boolean): BooleanFlag { + return registerFlag(name, BooleanFlag(default)) + } + + fun parseFlags(args: Array<out String>) { + var i = 0 + while (i in args.indices) { + val flag = args[i] + if (!flag.startsWith("--")) { + printHelp("Named argument provided: $flag") + } + val flagName = flag.substring(2) + if (flagName.startsWith("no-")) { + val boolFlag = flags[flagName.substring(3)] as? BooleanFlag + boolFlag ?: printHelp("Unknown flag $flag") + boolFlag.set = false + } else { + val flagObject = flags[flagName] + when (flagObject) { + is BooleanFlag -> flagObject.set = true + is StringFlag -> { + i++ + if(i !in args.indices) { printHelp("No argument provided for flag $flag") } + flagObject.value = args[i] + } + + null -> printHelp("Unknown flag $flag") + } + } + + i++ + } + } + + fun printHelp(errorMessage: String?): Nothing { + var help = "\n\n" + if (errorMessage != null) { + help += "ERROR: $errorMessage\n\n" + } + help += "Available flags:\n" + flags.forEach { (name, flag) -> + help += when (flag) { + is BooleanFlag -> " --$name, --no-$name\n" + is StringFlag -> " --$name <value>\n" + } + } + error(help) + } +}
\ No newline at end of file diff --git a/src/main/kotlin/at/hannibal2/skyhanni/changelog/CheckSpecificPR.kt b/src/main/kotlin/at/hannibal2/skyhanni/changelog/CheckSpecificPR.kt new file mode 100644 index 0000000..5a7ca3c --- /dev/null +++ b/src/main/kotlin/at/hannibal2/skyhanni/changelog/CheckSpecificPR.kt @@ -0,0 +1,13 @@ +package at.hannibal2.skyhanni.changelog + +object CheckSpecificPR { + @JvmStatic + fun main(args: Array<String>) { + val arguments = Arguments() + val prNumArg = arguments.string("pr-num") + arguments.parseFlags(args) + val prNum = prNumArg.value?.toIntOrNull() ?: arguments.printHelp("--pr-num is required") + println("Investigating PR: $prNum") + // TODO: actually test specific PR + } +}
\ No newline at end of file |