Skip to content

Commit

Permalink
Format help with Color/Markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
kdubb committed Oct 27, 2024
1 parent 2f950de commit 1e6e388
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
35 changes: 24 additions & 11 deletions cli/src/main/kotlin/io/outfoxx/sunday/generator/Version.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,34 @@
package io.outfoxx.sunday.generator

import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.parameters.options.versionOption
import com.github.ajalt.clikt.core.PrintMessage
import com.github.ajalt.clikt.parameters.options.eagerOption
import com.github.ajalt.clikt.parameters.transform.theme

fun CliktCommand.versionOption() = apply {
versionOption(
versionString,
message = {
fun CliktCommand.versionOption() =
eagerOption(setOf("--version"), help = "Show version information and exit") {
throw PrintMessage(
"""
Sunday - Generator ver. $versionString
${theme.style("warning")("Sunday")} ${theme.style("info")("- Generator")} ver. ${
theme.style("danger")(
versionString
)
}
Supports: Kotlin (Sunday & JAX-RS), Swift (Sunday), TypeScript (Sunday)
""".trimIndent()
},
)
}
${theme.style("warning")("Supports")}:
* ${theme.style("warning")("Kotlin")}
JAX-RS ${theme.style("muted")("Client, Server")}
* ${theme.style("warning")("Swift")}
Sunday ${theme.style("muted")("Client")}
* ${theme.style("warning")("TypeScript")}
Sunday ${theme.style("muted")("Client")}
""".trimIndent(),
)
}

val versionString: String
get() = GenerateCommand::class.java.`package`.implementationVersion ?: "unknown"
4 changes: 3 additions & 1 deletion cli/src/test/kotlin/io/outfoxx/sunday/generator/CLITest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ class CLITest {

val command = GenerateCommandTest()
val result = assertDoesNotThrow { command.versionOption().test(arrayOf("--version", *requiredOptions)) }
assertThat(result.stdout, containsString("Sunday - Generator ver. unknown"))
assertThat(result.stdout, containsString("Sunday - Generator"))
assertThat(result.stdout, containsString("ver. unknown"))
assertThat(result.stdout, containsString("Supports:"))
}

@Test
Expand Down

0 comments on commit 1e6e388

Please sign in to comment.