Clikt Versions Save

Multiplatform command line interface parsing for Kotlin

4.4.0

3 weeks ago

This release adds support for linuxArm64 and wasmJs targets.

4.3.0

1 month ago

Added

  • Added limit parameter to option().counted() to limit the number of times the option can be used. You can either clamp the value to the limit, or throw an error if the limit is exceeded. (#483)
  • Added Context.registerClosable and Context.callOnClose to allow you to register cleanup actions that will be called when the command exits. (#395)

Fixed

  • Fixed unrecognized modifier 'i' that happened on tab-completion when using sub command aliases. Thanks to @hick209 for the contribution. (#500)
  • Make sure auto complete script works on zsh, fixing the error complete:13: command not found: compdef. Thanks to @hick209 for the contribution. (#499)

4.2.2

4 months ago

Changed

  • Options and arguments can now reference option groups in their defaultLazy and other finalization blocks. They can also freely reference each other, including though chains of references. (#473)
  • Updated Kotlin to 1.9.21 (#472)

4.2.1

7 months ago

Added

  • Added toString implementations to options and arguments. (#434)
  • Added CliktCommand.test overload that takes a vararg of Strings as the command line arguments. Thanks to @sschuberth for the contribution (#451)

Fixed

  • Update Mordant dependency to fix crashes on native targets and GraalVM (#447)

4.2.0

9 months ago

Added

  • Added requireConfirmation parameter to option().prompt() (#426)
  • Added CliktCommand.terminal extension for accessing the terminal from a command.
  • Added includeSystemEnvvars, ansiLevel, width, and height parameters to all CliktCommand.test overloads.

Deprecated

  • Deprecated CliktCommand.prompt, use CliktCommand.terminal.prompt or Prompt instead.
  • Deprecated CliktCommand.confirm, use YesNoPrompt instead.

4.1.0

10 months ago

Added

  • Added MordantHelpFormatter.renderAttachedOptionValue that you can override to change how option values are shown, e.g. if you want option to show as --option <value> instead of --option=<value>. (#416)
  • Added option().optionalValueLazy{}, which work like optionalValue() but the default value is computed lazily. (#381)

Changed

  • Updated Kotlin to 1.9.0
  • PrintMessage, PrintHelpMessage and PrintCompletionMessage now default to exiting with a status code 0, which is the behavior they had in 3.x. (#419)

4.0.0

10 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    │
└───────────┴────────┴──────┴────────┘

There are new lazy extensions for setting paramter help that you can use to add color to parameter help text:

option().help { theme.info("this text will use the theme color") }

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)
    }
}

4.0.0-RC

10 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)
    }
}

3.5.4

10 months ago

Fixed

  • Revert JVM jars to compile with Java 8 bytecode

3.5.3

10 months ago

Changed

  • Updated Kotlin to 1.8.22

Fixed

  • Context is now set properly on NoSuchOption exceptions when thrown from subcommands. (#399)
  • When treatUnknownOptionsAsArgs is true, grouped unknown short options will now be treated as arguments rather than reporting an error.