Skip to content

Commit bba90fe

Browse files
committed
fix: Do not print patch description if null
1 parent 1717cc6 commit bba90fe

File tree

1 file changed

+43
-46
lines changed

1 file changed

+43
-46
lines changed

src/main/kotlin/app/revanced/cli/command/ListPatchesCommand.kt

Lines changed: 43 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -85,58 +85,55 @@ internal object ListPatchesCommand : Runnable {
8585
}
8686
}
8787

88-
fun PatchOption<*>.buildString() =
88+
fun PatchOption<*>.buildString() = buildString {
89+
appendLine("Title: $title")
90+
description?.let { appendLine("Description: $it") }
91+
appendLine("Required: $required")
92+
default?.let {
93+
appendLine("Key: $key")
94+
append("Default: $it")
95+
} ?: append("Key: $key")
96+
97+
values?.let { values ->
98+
appendLine("\nPossible values:")
99+
append(values.map { "${it.value} (${it.key})" }.joinToString("\n").prependIndent("\t"))
100+
}
101+
102+
append("\nType: $type")
103+
}
104+
105+
fun IndexedValue<Patch<*>>.buildString() = let { (index, patch) ->
89106
buildString {
90-
appendLine("Title: $title")
91-
description?.let { appendLine("Description: $it") }
92-
appendLine("Required: $required")
93-
default?.let {
94-
appendLine("Key: $key")
95-
append("Default: $it")
96-
} ?: append("Key: $key")
97-
98-
values?.let { values ->
99-
appendLine("\nPossible values:")
100-
append(values.map { "${it.value} (${it.key})" }.joinToString("\n").prependIndent("\t"))
101-
}
107+
if (withIndex) appendLine("Index: $index")
102108

103-
append("\nType: $type")
104-
}
109+
append("Name: ${patch.name}")
105110

106-
fun IndexedValue<Patch<*>>.buildString() =
107-
let { (index, patch) ->
108-
buildString {
109-
if (withIndex) appendLine("Index: $index")
110-
111-
append("Name: ${patch.name}")
112-
113-
if (withDescriptions) append("\nDescription: ${patch.description}")
114-
115-
append("\nEnabled: ${patch.use}")
116-
117-
if (withOptions && patch.options.isNotEmpty()) {
118-
appendLine("\nOptions:")
119-
append(
120-
patch.options.values.joinToString("\n\n") { option ->
121-
option.buildString()
122-
}.prependIndent("\t"),
123-
)
124-
}
125-
126-
if (withPackages && patch.compatiblePackages != null) {
127-
appendLine("\nCompatible packages:")
128-
append(
129-
patch.compatiblePackages!!.joinToString("\n") {
130-
it.buildString()
131-
}.prependIndent("\t"),
132-
)
133-
}
111+
if (withDescriptions) patch.description?.let { append("\nDescription: $it") }
112+
113+
append("\nEnabled: ${patch.use}")
114+
115+
if (withOptions && patch.options.isNotEmpty()) {
116+
appendLine("\nOptions:")
117+
append(
118+
patch.options.values.joinToString("\n\n") { option ->
119+
option.buildString()
120+
}.prependIndent("\t"),
121+
)
122+
}
123+
124+
if (withPackages && patch.compatiblePackages != null) {
125+
appendLine("\nCompatible packages:")
126+
append(
127+
patch.compatiblePackages!!.joinToString("\n") {
128+
it.buildString()
129+
}.prependIndent("\t"),
130+
)
134131
}
135132
}
133+
}
136134

137-
fun Patch<*>.filterCompatiblePackages(name: String) =
138-
compatiblePackages?.any { (compatiblePackageName, _) -> compatiblePackageName == name }
139-
?: withUniversalPatches
135+
fun Patch<*>.filterCompatiblePackages(name: String) = compatiblePackages?.any { (compatiblePackageName, _) -> compatiblePackageName == name }
136+
?: withUniversalPatches
140137

141138
val patches = loadPatchesFromJar(patchesFiles).withIndex().toList()
142139

0 commit comments

Comments
 (0)