Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -v into the default version options #485

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ inline fun <T : CliktCommand> T.versionOption(
version: String,
/** The help message for the option */
help: String = "Show the version and exit",
/** The names of this option. Defaults to --version */
names: Set<String> = setOf("--version"),
/** The names of this option. Defaults to -v or --version */
names: Set<String> = setOf("-v", "--version"),
/** A block that returns the message to print. The [version] is passed as a parameter */
crossinline message: (String) -> String = { "$commandName version $it" },
): T = eagerOption(names, help) { throw PrintMessage(message(version)) }
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,19 @@ class EagerOptionsTest {
}
}

val exception = shouldThrow<PrintMessage> {
shouldThrow<PrintMessage> {
C().parse("--version")
}.let { e ->
e.formattedMessage shouldBe "prog version 1.2.3"
e.statusCode shouldBe 0
}

shouldThrow<PrintMessage> {
C().parse("-v")
}.let { e ->
e.formattedMessage shouldBe "prog version 1.2.3"
e.statusCode shouldBe 0
}
exception.formattedMessage shouldBe "prog version 1.2.3"
exception.statusCode shouldBe 0
}

@Test
Expand Down
Loading