From ad0b1232b2d52b66ef0436696979814a10801331 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Wed, 13 Dec 2023 13:02:39 +0100 Subject: [PATCH] Show recipe option example values --- .../org/openrewrite/RecipeMarkdownGenerator.kt | 10 +++++----- src/main/kotlin/org/openrewrite/RecipeOption.kt | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/kotlin/org/openrewrite/RecipeMarkdownGenerator.kt b/src/main/kotlin/org/openrewrite/RecipeMarkdownGenerator.kt index a91232b..c2ebeef 100644 --- a/src/main/kotlin/org/openrewrite/RecipeMarkdownGenerator.kt +++ b/src/main/kotlin/org/openrewrite/RecipeMarkdownGenerator.kt @@ -151,7 +151,7 @@ class RecipeMarkdownGenerator : Runnable { val recipeOptions = TreeSet() for (recipeOption in recipeDescriptor.options) { val name = recipeOption.name as String - val ro = RecipeOption(name, recipeOption.type, recipeOption.isRequired) + val ro = RecipeOption(name, recipeOption.type, recipeOption.example, recipeOption.isRequired) recipeOptions.add(ro) } @@ -610,7 +610,7 @@ class RecipeMarkdownGenerator : Runnable { } else { // Some nested recipes have a `github` path which gets converted into `Github` when it should be `GitHub`. if (displayName == "Github") { - displayName = "GitHub"; + displayName = "GitHub" } result.appendLine("$indent* [$displayName](reference/recipes/$path/README.md)") @@ -816,8 +816,8 @@ class RecipeMarkdownGenerator : Runnable { """ ## Options - | Type | Name | Description | - | -- | -- | -- | + | Type | Name | Description | Example | + | -- | -- | -- | -- | """.trimIndent() ) for (option in recipeDescriptor.options) { @@ -837,7 +837,7 @@ class RecipeMarkdownGenerator : Runnable { } writeln( """ - | `${option.type}` | ${option.name} | $description | + | `${option.type}` | ${option.name} | $description | `${option.example}` | """.trimIndent() ) } diff --git a/src/main/kotlin/org/openrewrite/RecipeOption.kt b/src/main/kotlin/org/openrewrite/RecipeOption.kt index e2b15ce..a3200d9 100644 --- a/src/main/kotlin/org/openrewrite/RecipeOption.kt +++ b/src/main/kotlin/org/openrewrite/RecipeOption.kt @@ -3,14 +3,14 @@ package org.openrewrite data class RecipeOption( val name: String, val type: String, + val example: String?, val required: Boolean ): Comparable { override fun compareTo(other: RecipeOption): Int { - if (this.name != other.name) return this.name.compareTo(other.name) - if (this.type != other.type) return this.type.compareTo(other.type) - if (this.required && !other.required) return 1 - if (!this.required && other.required) return -1 - - return 0 + return compareBy(RecipeOption::name) + .then(compareBy(RecipeOption::type)) + .then(compareBy(RecipeOption::example)) + .then(compareBy(RecipeOption::required)) + .compare(this, other) } } \ No newline at end of file