Skip to content

Commit

Permalink
feat(cli): Add threshold filters for booking amounts
Browse files Browse the repository at this point in the history
  • Loading branch information
sschuberth committed Sep 30, 2024
1 parent ecf510f commit 5066e29
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions cli/src/main/kotlin/FilterCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ class FilterCommand : CliktCommand("filter") {
help = "Remove all booking item whose info matches the given regular expression."
)

private val lessOrEqual by option(
"--less-or-equal",
help = "Only include bookings that are less or equal to the given amount."
)

private val greaterOrEqual by option(
"--greater-or-equal",
help = "Only include bookings that are greater or equal to the given amount."
)

private val statements by requireObject<Set<Statement>>()

override fun run() {
Expand All @@ -62,6 +72,8 @@ class FilterCommand : CliktCommand("filter") {
.filterNot { typeNot == it.type }
.filter { filterRegex?.containsMatchIn(it.info.joinInfo()) != false }
.filterNot { filterNotRegex?.containsMatchIn(it.info.joinInfo()) == true }
.filter { lessOrEqual?.toFloat()?.let { threshold -> it.amount <= threshold } != false }
.filter { greaterOrEqual?.toFloat()?.let { threshold -> it.amount >= threshold } != false }

filteredBookings.forEach {
println("${it.valueDate} : ${it.type} : ${"%.2f".format(it.amount)}")
Expand Down

0 comments on commit 5066e29

Please sign in to comment.