diff --git a/CHANGELOG.md b/CHANGELOG.md index e3813e754..a392fae1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ ### Changed - Updated Kotlin to 1.9.0 +- `PrintMessage` and `PrintCompletionMessage` now default to exiting with a status code 0, which is the behavior they had in 3.x. ([#419](https://github.com/ajalt/clikt/issues/419)) ## 4.0.0 ### Added diff --git a/clikt/src/commonMain/kotlin/com/github/ajalt/clikt/core/exceptions.kt b/clikt/src/commonMain/kotlin/com/github/ajalt/clikt/core/exceptions.kt index 17d946a8c..39cc65b2c 100644 --- a/clikt/src/commonMain/kotlin/com/github/ajalt/clikt/core/exceptions.kt +++ b/clikt/src/commonMain/kotlin/com/github/ajalt/clikt/core/exceptions.kt @@ -56,8 +56,18 @@ class PrintHelpMessage( * Execution should be immediately halted. */ open class PrintMessage( + /** The message to print */ message: String, - statusCode: Int = 1, + /** + * The value to use as the exit code for the process. + * + * If you use [CliktCommand.main], it will pass this value to `exitProcess` after printing + * [message]. Defaults to 0. + */ + statusCode: Int = 0, + /** + * If true, the error message should be printed to stderr. + */ printError: Boolean = false, ) : CliktError(message, statusCode = statusCode, printError = printError) @@ -76,7 +86,7 @@ class Abort : ProgramResult(statusCode = 1) * * Execution should be immediately halted without an error. */ -class PrintCompletionMessage(message: String) : PrintMessage(message) +class PrintCompletionMessage(message: String) : PrintMessage(message, statusCode = 0) /** An exception that signals a user error. */ open class UsageError(