Skip to content

Commit 4cf0d61

Browse files
committed
markdown support in cli help
1 parent db7805a commit 4cf0d61

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

docs/modules/pkl-cli/pages/index.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,7 @@ Commands are defined by creating a module that extends `pkl:Command`:
919919
.my-tool.pkl
920920
----
921921
/// This doc comment becomes part of the command's CLI help!
922+
/// Markdown formatting is **allowed!**
922923
extends "pkl:Command"
923924
924925
options: Options
@@ -951,6 +952,7 @@ If additional functionality is desired, xref:language-reference:index.adoc#exter
951952
Each property of the class of a command's `options` property becomes a command line option.
952953
Properties with the `local`, `hidden`, `fixed`, and/or `const` modifiers are not parsed as options
953954
A property's doc comment, if present, becomes the corresponding option's CLI help description.
955+
Doc comments are interpreted as Markdown text and formatted nicely when displayed to users.
954956
Properties must have xref:language-reference:index.adoc#type-annotations[type annotations] to determine how they are parsed.
955957

956958
Properties may be xref:language-reference:index.adoc#annotations[annotated] to influence how they behave:

pkl-cli/src/main/kotlin/org/pkl/cli/CliCommandRunner.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import kotlin.io.path.writeBytes
2929
import org.pkl.commons.cli.CliBaseOptions
3030
import org.pkl.commons.cli.CliCommand
3131
import org.pkl.commons.cli.CliException
32+
import org.pkl.commons.cli.commands.installCommonOptions
3233
import org.pkl.commons.currentWorkingDir
3334
import org.pkl.core.Closeables
3435
import org.pkl.core.CommandSpec
@@ -65,6 +66,7 @@ constructor(
6566
evaluator.evaluateCommand(uri(normalizedSourceModule)) { spec ->
6667
try {
6768
val root = SynthesizedRunCommand(spec, this, options.sourceModules.first().toString())
69+
root.installCommonOptions(includeVersion = false)
6870
root.subcommands(
6971
CompletionCommand(
7072
name = "shell-completion",

pkl-cli/src/test/kotlin/org/pkl/cli/CliCommandRunnerTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package org.pkl.cli
1717

1818
import com.github.ajalt.clikt.core.CliktError
1919
import com.github.ajalt.clikt.core.MissingOption
20+
import com.github.ajalt.clikt.core.PrintHelpMessage
2021
import com.github.tomakehurst.wiremock.junit5.WireMockTest
2122
import java.io.ByteArrayOutputStream
2223
import java.net.URI

pkl-commons-cli/src/main/kotlin/org/pkl/commons/cli/commands/extensions.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,16 @@ import org.pkl.core.Release
2727

2828
private val theme = Theme { styles["markdown.code.span"] = TextStyle(bold = true) }
2929

30-
fun <T : BaseCliktCommand<T>> T.installCommonOptions() {
30+
fun <T : BaseCliktCommand<T>> T.installCommonOptions(includeVersion: Boolean = true) {
3131
installMordantMarkdown()
3232

33-
versionOption(
34-
Release.current().versionInfo,
35-
names = setOf("-v", "--version"),
36-
message = { if (commandName == "pkl") it else it.replaceFirst("Pkl", commandName) },
37-
)
33+
if (includeVersion) {
34+
versionOption(
35+
Release.current().versionInfo,
36+
names = setOf("-v", "--version"),
37+
message = { if (commandName == "pkl") it else it.replaceFirst("Pkl", commandName) },
38+
)
39+
}
3840

3941
context { terminal = Terminal(theme = theme) }
4042
}

0 commit comments

Comments
 (0)