Update doc printer for lang changes

This commit is contained in:
Octavia Togami 2020-10-17 22:32:27 -07:00
parent 83e744bae2
commit f449e55f98
No known key found for this signature in database
GPG Key ID: CC364524D1983C99
4 changed files with 85 additions and 29 deletions

View File

@ -0,0 +1,8 @@
package com.sk89q.worldedit.internal.util
import com.sk89q.worldedit.LocalConfiguration
object DocumentationConfiguration : LocalConfiguration() {
override fun load() {
}
}

View File

@ -0,0 +1,45 @@
package com.sk89q.worldedit.internal.util
import com.sk89q.worldedit.entity.Player
import com.sk89q.worldedit.extension.platform.AbstractPlatform
import com.sk89q.worldedit.world.World
import org.enginehub.piston.CommandManager
import java.nio.file.Files
import java.nio.file.Paths
import java.util.Properties
class DocumentationPlatform : AbstractPlatform() {
override fun getPlatformName() = "Documentation"
override fun getVersion(): String {
val props = Files.newBufferedReader(Paths.get("./gradle.properties")).use { reader ->
Properties().also { it.load(reader) }
}
return props.getProperty("version") ?: "No version property in `gradle.properties`"
}
override fun getConfiguration() = DocumentationConfiguration
override fun getPlatformVersion() = version
override fun getRegistries() = error("Documentation does not provide this")
override fun getDataVersion() = error("Documentation does not provide this")
override fun isValidMobType(type: String?) = error("Documentation does not provide this")
override fun matchPlayer(player: Player?) = error("Documentation does not provide this")
override fun matchWorld(world: World?) = error("Documentation does not provide this")
override fun registerCommands(commandManager: CommandManager?) = error("Documentation does not provide this")
override fun registerGameHooks() = error("Documentation does not provide this")
override fun getCapabilities() = error("Documentation does not provide this")
override fun getSupportedSideEffects() = error("Documentation does not provide this")
}

View File

@ -56,21 +56,23 @@ class DocumentationPrinter private constructor() {
private val permsOutput = StringBuilder()
private val matchedCommands = mutableSetOf<String>()
private suspend inline fun <reified T> SequenceScope<String>.yieldAllCommandsIn() {
val sourceFile = Paths.get("worldedit-core/src/main/java/" + T::class.qualifiedName!!.replace('.', '/') + ".java")
require(Files.exists(sourceFile)) {
"Source not found for ${T::class.qualifiedName}, looked at ${sourceFile.toAbsolutePath()}"
}
Files.newBufferedReader(sourceFile).useLines { lines ->
var inCommand = false
for (line in lines) {
if (inCommand) {
when (val match = nameRegex.find(line)) {
null -> if (line.trim() == ")") inCommand = false
else -> yield(match.groupValues[1])
private inline fun <reified T> findCommandsIn(): Sequence<String> {
return sequence {
val sourceFile = Paths.get("worldedit-core/src/main/java/" + T::class.qualifiedName!!.replace('.', '/') + ".java")
require(Files.exists(sourceFile)) {
"Source not found for ${T::class.qualifiedName}, looked at ${sourceFile.toAbsolutePath()}"
}
Files.newBufferedReader(sourceFile).useLines { lines ->
var inCommand = false
for (line in lines) {
if (inCommand) {
when (val match = nameRegex.find(line)) {
null -> if (line.trim() == ")") inCommand = false
else -> yield(match.groupValues[1])
}
} else if (line.contains("@Command(")) {
inCommand = true
}
} else if (line.contains("@Command(")) {
inCommand = true
}
}
}
@ -81,36 +83,36 @@ private fun writeAllCommands() {
dumpSection("General Commands") {
yield("worldedit")
yieldAllCommandsIn<HistoryCommands>()
yieldAllCommandsIn<GeneralCommands>()
yieldAll(findCommandsIn<HistoryCommands>())
yieldAll(findCommandsIn<GeneralCommands>())
}
dumpSection("Navigation Commands") {
yieldAllCommandsIn<NavigationCommands>()
yieldAll(findCommandsIn<NavigationCommands>())
}
dumpSection("Selection Commands") {
yieldAllCommandsIn<SelectionCommands>()
yieldAll(findCommandsIn<SelectionCommands>())
yield("/expand")
}
dumpSection("Region Commands") {
yieldAllCommandsIn<RegionCommands>()
yieldAll(findCommandsIn<RegionCommands>())
}
dumpSection("Generation Commands") {
yieldAllCommandsIn<GenerationCommands>()
yieldAll(findCommandsIn<GenerationCommands>())
}
dumpSection("Schematic and Clipboard Commands") {
yield("schematic")
yieldAllCommandsIn<ClipboardCommands>()
yieldAll(findCommandsIn<ClipboardCommands>())
}
dumpSection("Tool Commands") {
yield("tool")
yieldAllCommandsIn<ToolCommands>()
yieldAllCommandsIn<ToolUtilCommands>()
yieldAll(findCommandsIn<ToolCommands>().filter { it != "stacker" })
yieldAll(findCommandsIn<ToolUtilCommands>())
}
dumpSection("Super Pickaxe Commands") {
@ -122,24 +124,24 @@ private fun writeAllCommands() {
}
dumpSection("Biome Commands") {
yieldAllCommandsIn<BiomeCommands>()
yieldAll(findCommandsIn<BiomeCommands>())
}
dumpSection("Chunk Commands") {
yieldAllCommandsIn<ChunkCommands>()
yieldAll(findCommandsIn<ChunkCommands>())
}
dumpSection("Snapshot Commands") {
yieldAllCommandsIn<SnapshotUtilCommands>()
yieldAll(findCommandsIn<SnapshotUtilCommands>())
yield("snapshot")
}
dumpSection("Scripting Commands") {
yieldAllCommandsIn<ScriptingCommands>()
yieldAll(findCommandsIn<ScriptingCommands>())
}
dumpSection("Utility Commands") {
yieldAllCommandsIn<UtilityCommands>()
yieldAll(findCommandsIn<UtilityCommands>())
}
writeFooter()
@ -335,6 +337,7 @@ private fun commandTableEntries(command: Command, parents: Stream<Command>): Map
@JvmStatic
fun main(args: Array<String>) {
try {
WorldEdit.getInstance().platformManager.register(DocumentationPlatform())
val printer = DocumentationPrinter()
printer.writeAllCommands()

View File

@ -57,7 +57,7 @@ private static Component makeDeprecatedFooter(String reason, Component replaceme
.append(DEPRECATION_MARKER)
.append(" " + reason + ".")
.append(TextComponent.newline())
.append(replacement.color(TextColor.GOLD).decoration(TextDecoration.ITALIC, true))
.append(replacement.color(TextColor.GOLD))
.build();
}