Skip to content

Commit b0a12bc

Browse files
authored
Default to exit code 0 for PrintMessage (#423)
1 parent 9eb6683 commit b0a12bc

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
### Changed
99
- Updated Kotlin to 1.9.0
10+
- `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))
1011

1112
## 4.0.0
1213
### Added

clikt/src/commonMain/kotlin/com/github/ajalt/clikt/core/exceptions.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,18 @@ class PrintHelpMessage(
5656
* Execution should be immediately halted.
5757
*/
5858
open class PrintMessage(
59+
/** The message to print */
5960
message: String,
60-
statusCode: Int = 1,
61+
/**
62+
* The value to use as the exit code for the process.
63+
*
64+
* If you use [CliktCommand.main], it will pass this value to `exitProcess` after printing
65+
* [message]. Defaults to 0.
66+
*/
67+
statusCode: Int = 0,
68+
/**
69+
* If true, the error message should be printed to stderr.
70+
*/
6171
printError: Boolean = false,
6272
) : CliktError(message, statusCode = statusCode, printError = printError)
6373

@@ -76,7 +86,7 @@ class Abort : ProgramResult(statusCode = 1)
7686
*
7787
* Execution should be immediately halted without an error.
7888
*/
79-
class PrintCompletionMessage(message: String) : PrintMessage(message)
89+
class PrintCompletionMessage(message: String) : PrintMessage(message, statusCode = 0)
8090

8191
/** An exception that signals a user error. */
8292
open class UsageError(

0 commit comments

Comments
 (0)