Skip to content

Commit

Permalink
Add --recipe-option to Moderne CLI snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek committed Nov 29, 2024
1 parent f5ba0ea commit cb38ec0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ A few important things to note:

* The snapshot descriptors are not updated when a full release is run. You should make sure to run the snapshot code when you do a full release so that it can be kept up-to-date.
* When doing snapshot releases, you generally don't want to copy over all of the files to the rewrite-docs (as it will show snapshot versions instead of full versions). Rather, please only copy over the exact files you need.
* When copying over the files from the previous step, make sure you update the `SUMMARY.md`. If you don't, those new files won't appear.

### Diff log

Expand Down
18 changes: 11 additions & 7 deletions src/main/kotlin/org/openrewrite/RecipeMarkdownGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,7 @@ import TabItem from '@theme/TabItem';
""".trimIndent()
)
var cliOptions = ""
for (option in recipeDescriptor.options) {
if (!option.isRequired && option.example == null) {
continue
Expand All @@ -1330,36 +1331,39 @@ import TabItem from '@theme/TabItem';
} else {
option.example
}
cliOptions += " --recipe-option \"${option.name}=$ex\""
writeln(" ${option.name}: $ex")
}
writeln("```")
newLine()

val cliSnippet = getCliSnippet(recipeDescriptor.name, cliOptions, origin)
if (requiresDependency) {
writeSnippetsWithConfigurationWithDependency(
exampleRecipeName,
origin,
suppressMaven,
suppressGradle,
getCliSnippet(exampleRecipeName, origin),
cliSnippet,
dataTableSnippet,
)
} else {
writeSnippetsWithConfigurationWithoutDependency(
exampleRecipeName,
suppressMaven,
suppressGradle,
getCliSnippet(exampleRecipeName, origin),
cliSnippet,
dataTableSnippet,
)
}
} else {
val cliSnippet = getCliSnippet(recipeDescriptor.name, "", origin)
if (origin.isFromCoreLibrary()) {
writeSnippetsFromCoreLibrary(
recipeDescriptor,
suppressMaven,
suppressGradle,
getCliSnippet(recipeDescriptor.name, origin),
cliSnippet,
dataTableSnippet,
dataTableCommandLineSnippet,
)
Expand All @@ -1369,7 +1373,7 @@ import TabItem from '@theme/TabItem';
recipeDescriptor,
suppressMaven,
suppressGradle,
getCliSnippet(recipeDescriptor.name, origin),
cliSnippet,
dataTableSnippet,
dataTableCommandLineSnippet,
)
Expand Down Expand Up @@ -1540,7 +1544,7 @@ import TabItem from '@theme/TabItem';
return diffContent.toString()
}

private fun getCliSnippet(name: String, origin: RecipeOrigin): String {
private fun getCliSnippet(name: String, cliOptions: String, origin: RecipeOrigin): String {
val trimmedRecipeName = name.substring(name.lastIndexOf('.') + 1)
val versionPlaceholderKey = "{{VERSION_${origin.artifactId.uppercase().replace('-', '_')}}}"
//language=markdown
Expand All @@ -1550,12 +1554,12 @@ import TabItem from '@theme/TabItem';
You will need to have configured the [Moderne CLI](https://docs.moderne.io/user-documentation/moderne-cli/getting-started/cli-intro) on your machine before you can run the following command.
```shell title="shell"
mod run . --recipe $trimmedRecipeName
mod run . --recipe ${trimmedRecipeName}${cliOptions}
```
If the recipe is not available locally, then you can install it using:
```shell
mod config recipes jar install ${origin.groupId}:${origin.artifactId}:$versionPlaceholderKey
mod config recipes jar install ${origin.groupId}:${origin.artifactId}:${versionPlaceholderKey}
```
</TabItem>
""".trimIndent()
Expand Down

0 comments on commit cb38ec0

Please sign in to comment.