github ajalt/clikt 4.0.0-RC

latest releases: 5.0.3, 5.0.2, 5.0.1...
pre-release20 months ago

Clikt 4.0 is a major release that uses the Mordant library for help formatting. If you aren't
customizing help output, this upgrade will probably be source compatible.

Highlights

Here are some of the highlights of this release. See CHANGELOG.md for a detailed list of changes.

Colors and Markdown in help output

All help strings now support markdown, including tables and lists. On terminals that support it,
help and error messages will be colored.

class Command : CliktCommand(
    help="""
    ## This command uses markdown for its help text
    
    - You can use lists
    - You can use **bold** and *italic* text
    - You can even use [links](https://example.com) on terminals that support them
    
    | You       | can    | use  | tables |
    |-----------|--------|------|--------|
    | and       | they   | will | be     |
    | formatted | nicely | for  | you    |
    """.trimIndent()
)
$ ./command --help
Usage: command [<options>]

───── This command uses markdown for its help text ─────

 • You can use lists
 • You can use bold and italic text
 • You can even use links on terminals that support them

┌───────────┬────────┬──────┬────────┐
│ You       │ can    │ use  │ tables │
╞═══════════╪════════╪══════╪════════╡
│ and       │ they   │ will │ be     │
├───────────┼────────┼──────┼────────┤
│ formatted │ nicely │ for  │ you    │
└───────────┴────────┴──────┴────────┘

Optional and vararg values for options

You can now use optionalValue() to create an option that can be used as a flag or with a value

val log by option().optionalValue("verbose").default("none")
> ./tool --log=debug
log level == debug

> ./tool --log
log level == verbose

> ./tool
log level == none

You can also use varargValues() to create an option that accepts a variable number of values.

Streamlined error handling

Clikt's exceptions now all inherit from CliktError, and the CliktCommand.getFormattedHelp
method renders them into strings for you. This makes customizing main much easier. The default
implementation is now just:

fun main(argv: List<String>) {
    try {
        parse(argv)
    } catch (e: CliktError) {
        echoFormattedHelp(e)
        exitProcess(e.statusCode)
    }
}

Don't miss a new clikt release

NewReleases is sending notifications on new releases.