Format code

This commit is contained in:
2026-05-16 23:08:09 +02:00
parent 81dd8045f2
commit d110df924e
562 changed files with 11025 additions and 10059 deletions
+3 -2
View File
@@ -8,11 +8,12 @@ import com.github.ajalt.clikt.parameters.options.flag
import com.github.ajalt.clikt.parameters.options.option
import de.steamwar.db.Database
class DatabaseCommand: CliktCommand(name = "db") {
class DatabaseCommand : CliktCommand(name = "db") {
val useProduction by option().flag()
val db by findOrSetObject { Database }
override fun help(context: Context): String = "Run database commands"
override fun help(context: Context): String =
"Run database commands"
override fun run() {
if (!useProduction && db.database == "production") {
+12 -11
View File
@@ -7,19 +7,20 @@ import de.steamwar.db.Database
import de.steamwar.db.execute
import de.steamwar.db.useDb
class InfoCommand: CliktCommand() {
class InfoCommand : CliktCommand() {
val db by requireObject<Database>()
override fun run() = useDb {
val tables = execute("SHOW TABLES") { it.getString(1) }
override fun run() =
useDb {
val tables = execute("SHOW TABLES") { it.getString(1) }
echo(
table {
header { row("Name") }
body {
tables.map { row(it) }
echo(
table {
header { row("Name") }
body {
tables.map { row(it) }
}
}
}
)
}
)
}
}
+18 -17
View File
@@ -10,24 +10,25 @@ import de.steamwar.db.execute
import de.steamwar.db.useDb
import java.io.File
class ResetCommand: CliktCommand() {
class ResetCommand : CliktCommand() {
val db by requireObject<Database>()
override fun run() = useDb {
val schemaFile = File("/var/Schema.sql")
if (!schemaFile.exists()) {
throw CliktError("Schema file not found!")
override fun run() =
useDb {
val schemaFile = File("/var/Schema.sql")
if (!schemaFile.exists()) {
throw CliktError("Schema file not found!")
}
val schema = schemaFile.readText()
val tables = execute("SHOW TABLES;") { it.getString(1) }
for (table in tables) {
execute("DROP TABLE IF EXISTS $table;") { }
}
execute(schema) { }
echo(TextColors.brightGreen(TextStyles.bold("Database reset!")))
}
val schema = schemaFile.readText()
val tables = execute("SHOW TABLES;") { it.getString(1) }
for (table in tables) {
execute("DROP TABLE IF EXISTS $table;") { }
}
execute(schema) { }
echo(TextColors.brightGreen(TextStyles.bold("Database reset!")))
}
}