aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/ledger/QueryCommand.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/moe/nea/ledger/QueryCommand.kt')
-rw-r--r--src/main/kotlin/moe/nea/ledger/QueryCommand.kt28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/main/kotlin/moe/nea/ledger/QueryCommand.kt b/src/main/kotlin/moe/nea/ledger/QueryCommand.kt
index 71a57e1..9967a4a 100644
--- a/src/main/kotlin/moe/nea/ledger/QueryCommand.kt
+++ b/src/main/kotlin/moe/nea/ledger/QueryCommand.kt
@@ -9,6 +9,7 @@ import moe.nea.ledger.database.Database
import moe.nea.ledger.utils.di.Inject
import net.minecraft.command.CommandBase
import net.minecraft.command.ICommandSender
+import net.minecraft.util.BlockPos
import net.minecraft.util.ChatComponentText
import net.minecraft.util.ChatStyle
import net.minecraft.util.EnumChatFormatting
@@ -68,6 +69,18 @@ class QueryCommand : CommandBase() {
}
}
+ override fun addTabCompletionOptions(
+ sender: ICommandSender,
+ args: Array<out String>,
+ pos: BlockPos
+ ): MutableList<String>? {
+ when (val p = parseArgs(args)) {
+ is ParseResult.MissingArg -> return null
+ is ParseResult.Success -> return p.lastFilterM.tabComplete(args.last())
+ is ParseResult.UnknownFilter -> return getListOfStringsMatchingLastWord(args, mFilters.keys)
+ }
+ }
+
@Inject
lateinit var database: Database
private fun executeQuery(parse: ParseResult.Success) {
@@ -148,20 +161,35 @@ class QueryCommand : CommandBase() {
val preparedText = "%" + text.trim('%') + "%"
return Clause { column(DBLogEntry.type) like preparedText }
}
+
+ override fun tabComplete(partialArg: String): MutableList<String> {
+ return TransactionType.entries.asSequence().map { it.name }.filter { partialArg in it }.toMutableList()
+ }
}
object ItemFilter : FilterM {
override val name: String
get() = "withitem"
+ private val itemIdProvider = Ledger.di.provide<ItemIdProvider>() // TODO: close this escape hatch
override fun getFilter(text: String): BooleanExpression {
return Clause { column(DBItemEntry.itemId) like text }
}
+
+ override fun tabComplete(partialArg: String): MutableList<String>? {
+ return itemIdProvider.getKnownItemIds()
+ .asSequence()
+ .map { it.string }
+ .filter { partialArg in it }
+ .take(100)
+ .toMutableList()
+ }
}
interface FilterM {
val name: String
fun getFilter(text: String): BooleanExpression
+ fun tabComplete(partialArg: String): MutableList<String>?
// fun tabCompleteFilter() TODO
}