Skip to content

Commit cfcbc4b

Browse files
committed
Only hide the option values
1 parent aa8b452 commit cfcbc4b

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

src/main/kotlin/org/openrewrite/RecipeDescriptorExtensions.kt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ private fun escape(string: String): String = string
2222
.replace(">", ">")
2323
.replace("\"", """)
2424

25-
fun RecipeDescriptor.asYaml(hideOptions: Boolean): String {
25+
fun RecipeDescriptor.asYaml(hideOptionValues: Boolean): String {
2626
val s = StringBuilder()
2727
s.appendLine("""
2828
---
@@ -52,31 +52,33 @@ description: |
5252
}
5353

5454
s.append(" - ${subRecipe.name}")
55-
if (subRecipe.options.isEmpty() || subRecipe.options.all { it.value == null } || hideOptions) {
55+
if (subRecipe.options.isEmpty() || subRecipe.options.all { it.value == null }) {
5656
s.appendLine()
5757
} else {
5858
s.appendLine(":")
5959
for (subOption in subRecipe.options) {
60-
s.append(subOption.asYaml(3))
60+
s.append(subOption.asYaml(3, hideOptionValues))
6161
}
6262
}
6363
}
6464
}
6565
return s.toString()
6666
}
6767

68-
fun OptionDescriptor.asYaml(indentation: Int = 0): String {
68+
private fun OptionDescriptor.asYaml(indentation: Int = 0, hideOptionValues: Boolean = false): String {
6969
if (value == null) {
7070
return ""
7171
}
7272
val prefixBuilder = StringBuilder()
73-
(0 until indentation).forEach { _ ->
73+
(0 until indentation).forEach { _ ->
7474
prefixBuilder.append(" ")
7575
}
7676

7777
val prefix = prefixBuilder.toString()
78-
val formattedValue = if (value is Array<*>) {
79-
val asArray = value as Array<*>
78+
val formattedValue = if (hideOptionValues) {
79+
"redacted"
80+
} else if (value is Array<*>) {
81+
val asArray = value as Array<*>
8082
"[${asArray.joinToString(", ")}]"
8183
} else if (value == "*") {
8284
"\"*\""

src/main/kotlin/org/openrewrite/RecipeMarkdownWriter.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ import TabItem from '@theme/TabItem';
530530
}
531531
}
532532

533-
private fun BufferedWriter.writeDefinition(recipeDescriptor: RecipeDescriptor, hideOptions: Boolean) {
533+
private fun BufferedWriter.writeDefinition(recipeDescriptor: RecipeDescriptor, hideOptionValues: Boolean) {
534534
if (recipeDescriptor.recipeList.isNotEmpty()) {
535535
//language=markdown
536536
writeln(
@@ -573,13 +573,13 @@ import TabItem from '@theme/TabItem';
573573
)
574574
}
575575

576-
if (recipe.options.isNotEmpty() && !hideOptions) {
576+
if (recipe.options.isNotEmpty()) {
577577
for (option in recipe.options) {
578578
if (option.value != null) {
579-
val formattedOptionString = printValue(option.value!!)
579+
val formattedOptionString = if (hideOptionValues) "redacted" else
580+
printValue(option.value!!)
580581
.replace("<p>", "< p >")
581582
.replace("\n", " ")
582-
583583
writeln(" * " + option.name + ": `" + formattedOptionString + "`")
584584
}
585585
}
@@ -596,7 +596,7 @@ import TabItem from '@theme/TabItem';
596596
```yaml
597597
""".trimIndent()
598598
)
599-
writeln(recipeDescriptor.asYaml(hideOptions))
599+
writeln(recipeDescriptor.asYaml(hideOptionValues))
600600
//language=markdown
601601
writeln(
602602
"""

0 commit comments

Comments
 (0)