Change Log
5.0.1¶
Added¶
- Added completion commands for suspending and chained commands. (#553)
- Added no-op suspending commands. (#554)
Changed¶
- Unknown option errors and missing argument errors that occur at the same time will now both be reported. (#553)
5.0.0¶
Added¶
- Publish
iosArm64andiosX64targets. - Added
NoSuchArgumentexception that is thrown when too many arguments were given on the command line. Previously, a less specificUsageErrorwas thrown instead. - Added
CommandLineParser.tokenizethat splits a string into argv tokens. - Added
CommandLineParserthat provides functions for parsing and finalizing commands manually for more control. - Added
Context.invokedSubcommandsthat contains all subcommands of the current command that are going to be invoked whenallowMultipleSubcommandsistrue. - Added
SuspendingCliktCommandthat has asuspend fun runmethod, allowing you to use coroutines in your commands. - Added
ChainedCliktCommandthat allows you to return a value from yourrunmethod and pass it to the next command in the chain. - Added
Context.dataas an alternative toobjthat allows you to store more than one object in the context. - Added
Context.echoerto customize howechomessages are printed. - Added
CompletionGeneratorto manually generate completions for a command. - Added
Context.exitProcesswhich you can use to prevent the process from exiting during tests. - Added core module that supports watchOS, tvOS, and wasmWasi targets and has no dependencies.
- Added more options to
CliktCommand.testto control the terminal interactivity. (#517) - Added
associate{},associateBy{}, andassociateWith{}transforms for options that allow you to convert the keys and values of the map. (#529) - Added support for aliasing options to other options. (#535)
- Added
limitandignoreCaseparameters tooption().split(). (#541) - Support calling
--helpon subcommands when parents have required parameters.
Changed¶
- In a subcommand with and an
argument()withmultiple()oroptional(), the behavior is now the same regardless of the value ofallowMultipleSubcommands: if a token matches a subcommand name, it’s now treated as a subcommand rather than a positional argument. - Due to changes to the internal parsing algorithm, the exact details of error messages when multiple usage errors occur have changed in some cases.
- Breaking Change: Moved the following parameters from
CliktCommand’s constructor; override the corresponding properties instead:
| removed parameter | replacement property |
|---|---|
help |
fun help |
epilog |
fun helpEpilog |
invokeWithoutSubcommand |
val invokeWithoutSubcommand |
printHelpOnEmptyArgs |
val printHelpOnEmptyArgs |
helpTags |
val helpTags |
autoCompleteEnvvar |
val autoCompleteEnvvar |
allowMultipleSubcommands |
val allowMultipleSubcommands |
treatUnknownOptionsAsArgs |
val treatUnknownOptionsAsArgs |
hidden |
val hiddenFromHelp |
- The following methods on CliktCommand have been renamed: commandHelp -> help, commandHelpEpilog -> epilog. The old names are deprecated. |
|
- Breaking Change: CliktCommand.main and CliktCommand.parse are now extension functions rather than methods. |
|
- Breaking Change: Context.obj and Context.terminal, and OptionTransformContext.terminal are now extension functions rather than properties. |
|
- Breaking Change: The RenderedSection and DefinitionRow classes have moved to AbstractHelpFormatter. |
|
- Markdown support in the help formatter is no longer included by default. To enable it, include the :clikt-markdown dependency and call yourCommand.installMordantMarkdown() before parsing. |
|
| - Updated Kotlin to 2.0.0 |
Fixed¶
- Fixed excess arguments not being reported when
allowMultipleSubcommands=trueand a subcommand has excess arguments followed by another subcommand. - Commands with
printHelpOnEmptyArgs=truewill no longer print help if an option has a value from an environment variable or value source. (#382)
Deprecated¶
- Deprecated
Context.originalArgv. It will now always return an empty list. If your commands need an argv, you can pass it to them before you run them, or set in on the newContext.datamap. - Deprecated
Context.expandArgumentFiles. UseContext.argumentFileReaderinstead. - Renamed the following
Contextfields to be more consistent. The old names are deprecated.
| old name | new name |
|---|---|
Context.envvarReader |
Context.readEnvvar |
Context.correctionSuggestor |
Context.suggestTypoCorrection |
Context.argumentFileReader |
Context.readArgumentFile |
Context.tokenTransformer |
Context.transformToken |
Removed¶
- Removed previously deprecated experimental annotations.
- Removed
MordantHelpFormatter.graphemeLength - Removed
TermUi
4.4.0¶
Added¶
- Publish
linuxArm64andwasmJstargets.
4.3.0¶
Added¶
- Added
limitparameter tooption().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.registerClosableandContext.callOnCloseto 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¶
Changed¶
- Options and arguments can now reference option groups in their
defaultLazyand 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¶
Added¶
- Added
toStringimplementations to options and arguments. (#434) - Added
CliktCommand.testoverload that takes a vararg ofStrings 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¶
Added¶
- Added
requireConfirmationparameter tooption().prompt()(#426) - Added
CliktCommand.terminalextension for accessing the terminal from a command. - Added
includeSystemEnvvars,ansiLevel,width, andheightparameters to allCliktCommand.testoverloads.
Deprecated¶
- Deprecated
CliktCommand.prompt, useCliktCommand.terminal.promptorPromptinstead. - Deprecated
CliktCommand.confirm, useYesNoPromptinstead.
Fixed¶
- Fixed incorrect error message when a
defaultLazyoption referenced arequiredoption. (#430)
4.1.0¶
Added¶
- Added
MordantHelpFormatter.renderAttachedOptionValuethat 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 likeoptionalValue()but the default value is computed lazily. (#381)
Changed¶
- Updated Kotlin to 1.9.0
PrintMessage,PrintHelpMessageandPrintCompletionMessagenow default to exiting with a status code 0, which is the behavior they had in 3.x. (#419)
4.0.0¶
Added¶
- Added
Context.errorEncounteredwhich is true if parsing has continued after an error was encountered. option().help{""}andargument().help{""}extensions that set the parameter’s help text lazily, with access to the current context so that you can add colors.
Changed¶
Option.optionHelpandArgument.argumentHelp,CliktCommand.commandHelp, andCliktCommand.commandHelpEpilogare now methods that take the context as an argument, and thehelpparameter tocopyis now ahelpGetterlambda.CliktCommand.shortHelpnow takes the context as an argument.- The
messagemethod onTransformContextinterfaces is now an extension.
Deprecated¶
- Deprecated
CliktCommand.commandHelpandcommandHelpEpilogproperties in favor of the methods with the same name.
4.0.0-RC¶
Added¶
- You can now use markdown in your help strings, including tables and lists. Clikt uses the Mordant library for rendering.
- Help output and error messages now include colors by default. You can disable this or customize the styling by configuring the
context.terminal - Added
Option.varargValues()to create an option that accepts a variable number of values - Added
Option.optionalValue()to create an option whose value is optional. - Added
objsetter to context builder as an alternative tocurrentContext.obj - Added
boolean()parameter type conversions. - Added
uint()andulong()parameter type conversions. - Added
nullableFlag()parameter transformation. - Added
CliktCommand.testextension for testing your commands and their output - Clikt will now report multiple errors if they occur via the new
MultiUsageErrorexception, rather than just reporting the first error. (#367) - Added
CliktCommand.allHelpParams(), which can be overridden to change which parameters are displayed in help output - Added
Context.argumentFileReaderwhich allows custom loading of argument files - Added
Context.allowGroupedShortOptionswhich can disable parsing-abcas-a -b -c - Options named
-?or/?are now supported - Added
option(eager=true)to create an eager option that takes values - Added
option(acceptsUnattachedValue=false)to force the option to only accept values like--option=1and not--option 1 - Added
CliktCommand.test()that captures the output of a command and does not exit the process.
Removed¶
- Removed
CliktConsole. Mordant is now used for all input and output. If you were defining a custom console, instead define a mordantTerminalInterfaceand set it on your context’sTerminal. - Removed
TermUi.echo,TermUi.prompt, andTermUi.confirm. Use the equivalent methods on yourCliktCommand, or use mordant’s prompts directly. - Removed legacy JS publications. Now only the JS/IR artifacts are published.
- Removed
CliktHelpFormatter. UseMordantHelpFormatterinstead. - Removed
FlagOptionandEagerOptionclasses. All options are now implemented as transformations onOptionWithValues.FlagOptionis nowOptionWithValues<Boolean, Boolean, Boolean>.
Changed¶
promptandconfirmare now implemented with mordant’s prompt functionality, and the method parameters have changed to match mordant’s- When using
treatUnknownOptionsAsArgs, grouped short options like-abcwill be treated as an argument rather than reporting an error as long as they don’t match any short options in the command. (#340) - Clikt no longer automatically calls
trimIndenton strings passed tohelp. CalltrimIndentortrimMarginyourself if necessary. Context.Builder.helpOptionNamesnow accepts any iterable rather than just a set.CliktCommand.echoandpromptare now public. (#407)- Internally, all options are implemented transformations on
OptionWithValues, rather than using separate classes for each option type. - Some Localization strings have changed, removed
Localization.aborted(), addedLocalization.argumentsMetavar() Context.Builder.helpFormatteris now a lambda that takes the current context as an argument- Exceptions have been reworked so that all exceptions thrown by Clikt are subclasses of
CliktError. CliktErrornow includesstatusCodeandprintErrorproperties.- The constructor of
UsageErrorand its subclasses no longer takes acontextparameter. The context is now inferred automatically. UsageError.formatUsagenow takes the localization and formatter as arguments
Fixed¶
- When parsing a command line with more than one error, Clikt will now always report the error that occurs earliest if it can’t report them all (#361)
- When
treatUnknownOptionsAsArgsis true, grouped unknown short options will now be treated as arguments rather than reporting an error.
3.5.4¶
Fixed¶
- Revert jvm jars to target Java 8
3.5.3¶
Changed¶
- Updated Kotlin to 1.8.22
Fixed¶
- Context is now set properly on NoSuchOption exceptions when thrown from subcommands. (#399)
- When
treatUnknownOptionsAsArgsis true, grouped unknown short options will now be treated as arguments rather than reporting an error.
3.5.2¶
Changed¶
- Updated Kotlin to 1.8.10
Fixed¶
- Fix
CliktCommand.prompton NodeJS targets that would hang due to KT-55817 (#387)
3.5.1¶
Changed¶
- Updated Kotlin to 1.7.20
Fixed¶
- Support unicode in environment variable values on Native Windows. (#362)
- Support environment variables for options in a mutually exclusive options group. (#384)
3.5.0¶
Added¶
- Added
hiddenparameter toCliktCommand, which will prevent the command from being displayed as a subcommand in help output (#353) - Publish artifacts for the
macosArm64target. Note that this target is not tested on CI. (#352)
Changed¶
- Default values for arguments will now be included in help output when
showDefaultValues=trueis set on your help formatter (#357)
Fixed¶
- Fix flags and other options with defaults not being usable in
mutuallyExclusiveOptions(#349) - Fix
CompletionCommandgenerating completion for itself (#355)
3.4.2¶
Deprecated¶
TermUi.echo,TermUi.prompt, andTermUi.confirm. Use the equivalent methods onCliktCommandinstead. (#344)
3.4.1¶
Added¶
- Added
objsetter to context builder as an alternative tocurrentContext.obj - Added
option().boolean()andargument().boolean() uint()andulong()parameter type conversions.CliktCommand.testextension for testing your commands and their output
Changed¶
- Updated Kotlin to 1.6.20
3.4.0¶
Changed¶
unique()now works with any option with a list type, not justmultiple()options (#332)- Updated Kotlin to 1.6.10
Fixed¶
- Fixed co-occurring option groups returning null when all options in the group are defined in environment variables (#330)
3.3.0¶
Added¶
- Added
defaultparameter toargument().multiple()(#305) Context.originalArgvthat allows you to read the command line arguments from within a command’srun(#290)context { envarReader = {...} }to set a custom function to read from environment variables (#299)
Changed¶
defaultLazyvalues can now reference other parameters, as long the referenced parameters do not also reference other parameters- You can now call
CliktCommand.contextmultiple times on the same command, and all builder blocks will be applied - Validate values entered to a
promptoption, and show another prompt if the validation fails (#288) - Updated kotlin to 1.5.31
Fixed¶
- Report error when excess arguments are given to a command with
allowMultipleSubcommands=true(#303)
3.2.0¶
Added¶
InputStream.isCliktParameterDefaultStdinandOutputStream.isCliktParameterDefaultStdoutto check if the streams returned frominputStream/outputStreamoptions are proxying stdin/stdout (#272)
Changed¶
- Make parameters of
mutuallyExclusiveOptionscovariant to allow validation without explicit type annotations. (#265) - Updated kotlin to 1.5.0
Fixed¶
- Reading from an option or argument property on a command that hasn’t been invoked will now always throw an
IllegalStateException
3.1.0¶
Added¶
- Added
required()anddefaultLazy()for nullable flag options likeswitch(). (#240) - Added support for generating autocomplete scripts for Fish shells (#189)
- Added
CompletionCommandandCliktCommand.completionOption()that will print an autocomplete script when invoked, as an alternative to using environment variables.
Changed¶
- Updated Kotlin to 1.4.21
@argfilesnow allow line breaks in quoted values, which are included in the value verbatim. You can now end lines with\to concatenate them with the following line. (#248)
3.0.1¶
Deprecated¶
- Deprecated calling
echowitherrorlineSeparatorbut nomessage.
3.0.0¶
Added¶
- Clikt’s JS target now supports both NodeJS and Browsers. (#198)
- Default values for switch options are now shown in the help. Help text can be customized using the
defaultForHelpargument, similar to normal options. (#205) - Added
FlagOption.convert(#208) - Added ability to use unicode NEL character (
\u0085) to manually break lines in help output (#214) - Added
help("")extension to options and arguments as an alternative to passing the help as an argument (#207) - Added
valueSourceKeyparameter tooption - Added
check()extensions to options and arguments as an alternative tovalidate() - Added
promptandconfirmfunctions toCliktCommandthat call theTermUiequivalents with the current console. - Added
echo()overload with no parameters to CliktCommand that prints a newline by itself. - Added localization support. You can set an implementation of the
Localizationinterface on your context with your translations. (#227)
Fixed¶
- Hidden options will no longer be suggested as possible typo corrections. (#202)
- Options and Arguments with
multiple(required=true)will now show as required in help output. (#212) - Multiple short lines in a help text paragraph no longer appear dedented (#215)
Changed¶
- Updated Kotlin to 1.4.0
Argument.helpandOption.helpproperties have been renamed toargumentHelpandoptionHelp, respectively. Thehelpparameter names tooption()andargument()are unchanged.commandHelpandcommandHelpEpilogproperties onCliktCommandare nowopen, so you can choose to override them instead of passinghelpandepilogto the constructor.- Replaced
MapValueSource.defaultKeywithValueSource.getKey(), which is more customizable. Option.metavar,Option.parameterHelp,OptionGroup.parameterHelpandArgument.parameterHelpproperties are now functions.- Changed constructor parameters of
CliktHelpFormatter. Addedlocalizationand removedusageTitle,optionsTitle,argumentsTitle,commandsTitle,optionsMetavar, andcommandMetavar. Those strings are now defined on equivalently named functions onLocalization.
Removed¶
- Removed
envvarSplitparameter fromoption()andconvert(). Option values from environment variables are no longer split automatically. (#177) - Removed public constructors from the following classes:
ProcessedArgument,OptionWithValues,FlagOption,CoOccurringOptionGroup,ChoiceGroup,MutuallyExclusiveOptions. MissingParameterexception replaced withMissingOptionandMissingArgument- Removed
Context.helpOptionMessage. OverrideLocalization.helpOptionMessageand set it on your context instead.
Deprecated¶
@ExperimentalCompletionCandidatesand@ExperimentalValueSourceApiannotations. These APIs no longer require an opt-in.
2.8.0¶
Added¶
- Added
errorparameter toPrintMessageandPrintHelpMessage. Whentrue,CliktCommand.mainwill exit with status code 1. (#187)
Changed¶
- When
printHelpOnEmptyArgsistrueand no arguments are present, or wheninvokeWithoutSubcommandisfalseand no subcommand is present,CliktCommand.mainwill now exit with status code 1 rather than 0. restrictTonow works with anyComparablevalue, not justNumber.CliktCommand.mainnow acceptsArray<out String>, not justArray<String>. (#196)
Fixed¶
- Fixed option values being reset when calling multiple subcommands with
allowMultipleSubcommands=true(#190)
2.7.1¶
Fixed¶
- Fixed NPE thrown in some cases when using
defaultByName(#179)
2.7.0¶
Added¶
- Ability to use custom program exit status codes via
ProgramResult. inputStreamandoutputStreamconversions for options and arguments. (#157 and #159)splitPair,toMap, andassociateextensions onoption. (#166)treatUnknownOptionsAsArgsparameter toCliktCommand. (#152)defaultByNamefunction forgroupChoiceandgroupSwitchoptions. (#171)
Changed¶
- Update Kotlin to 1.3.71
- Improved command name inference. Now, a class like
MyAppCommandwill infer itscommandNameasmy-apprather thanmyappcommand. You can still specify the name manually as before. (#168)
Fixed¶
- Correctly parse short options with attached values that contain
=
2.6.0¶
Added¶
registeredSubcommands,registeredOptions,registeredArguments, andregisteredParameterGroupsmethods onCliktCommand.- Ability to read default option values from configuration files and other sources. Support for Java property files is built in on JVM, see the
jsonsample for an example of reading from other formats. allowMultipleSubcommandsparameter toCliktCommandthat allows you to pass multiple subcommands in the same call. (docs)- Errors from typos in subcommand names will now include suggested corrections. Corrections for options and subcommands are now based on a Jaro-Winkler similarity metric, and can be customized with
Context.correctionSuggestor
Changed¶
- Update Kotlin to 1.3.70
convertcan be called more than once on the same option or argument, including after calls to conversion functions likeintandfile.CliktCommand.toStringnow includes the class name- Reverted automatic
~expansion infile()andpath()introduced in 2.5.0. If you need this behavior, you can implement it with code likeconvert { /* expand tidle */ }.file()
Deprecated¶
wrapValueis now deprecated, sinceconvertcan be used in its place instead.
2.5.0¶
Added¶
- Clikt is now available as a Kotlin Multiplatform Project, supporting JVM, NodeJS, and native Windows, Linux, and macOS.
eagerOption {}function to more easily register eager options.- Eager options can now be added to option groups in help out by passing a value for
groupNamewhen creating them. canBeSymlinkparameter tofile()andpath()conversions that can be used to disallow symlinksCliktCommand.eagerOptionto simplify creating custom eager options
Changed¶
- The parameter names of
file()andpath()conversions have changed. The existing names are deprecated, and can be converted to the new usages with an IntelliJ inspection. Note that if you are calling these functions with unnamed arguments (e.g.file(true, false)), you’ll need to add argument names in order to remove the deprecation warning.
Deprecated¶
- The
CliktCommand.contextproperty has been deprecated in favor of the new name,currentContext, to avoid confusion with theCliktCommand.context{}method. NoRunCliktCommandwas renamed toNoOpCliktCommand. The existing class is deprecated. (#130)
Fixed¶
file()andpath()conversions will now properly expand leading~in paths to the home directory formustExist,canBeFile, andcanBeDirchecks. The property value is unchanged, and can still begin with a~. (#131)
2.4.0¶
Added¶
CompletionCandidates.Fixednow has a secondary convenience constructor that take avarargofStringsCompletionCadidates.Custom, which allows you to call other binaries or write a script to generate completions. This class is currently experimental. (#79)Option.wrapValueandArgument.wrapValueto make it easier to reuse existing conversion functions.ignoreCaseparameter tochoice()andenum()conversion functions.
Changed¶
option()andargument()now take optionalcompletionCandidatesparameters to override how completion is generated. The constructor andcopyfunctions ofOptionsWithValuesandProcessedArgumenthave changed to support default values.- The overloads of
findObject(1 2) that take a default value have been renamedfindOrSetObject. The existing names are marked with@Deprecated, and IntelliJ can convert your call sites automatically. (#110) enum()parameters now accept case-insensitive values by default. You change this behavior by passingignoreCase = falsetoenum()(#115)
Fixed¶
groupChoicehelp output now includes the choices in the help output metavarTermUi.edit*functions could freeze on certain editors (#99, thanks @iampravikant and @sebokopter)- Shell completion can now handle command names with dashes. (#104)
- Arguments with
=in them could be incorrectly interpreted as options (#106)
2.3.0¶
Added¶
option().groupSwitch(), which works likegroupChoice(), but uses aswitch()option rather than achoice()option.UsageErrornow has astatusCodeparameter (which defaults to 1). If you’re usingClicktCommand.main, the value ofstatusCodewill be passed toexitProcess.
Changed¶
- Shell completion code is now printed by throwing a
PrintCompletionMessage(a subclass ofPrintMessage) rather than callingechodirectly.
2.2.0¶
Added¶
- Added
enum()conversion for options and arguments. (#84)
Changed¶
- There are now several ways of preventing @-file expansion
Fixed¶
- Help output missing items when no help text is specified. (#85)
- Help output not grouping options in groups passed to
groupChoice. (#88)
2.1.0¶
Added¶
- Ability to prevent rewrapping individual paragraphs in help output.
- Added parameter
requiredtoOption.multiple()to require at least one instance of the option on the command line.
Changed¶
CliktCommand.toString()now includes the names and values of all parameters and subcommands.
Fixed¶
- Create subcommand context when
helpOptionNamesis empty. (#64)
2.0.0¶
Added¶
- Bash autocomplete script generation. A property named
completionCandidateshas been added toArgumentandOptioninterfaces, and corresponding parameters have been added to the various implementation constructors, as well as theconvertfunctions. You can use this to control the values autocomplete that will be suggested. option().split(), and the correspondingOptionWithValues.valueSplit.- Marking options as deprecated with
option().deprecated() - You can manually set the pattern to split envvars on by passing a pattern to the
envvarSplitparameter ofoption() - Option groups, mutually exclusive groups, co-occurring groups, and choice options with groups
- Support for Command line argument files a.k.a. “@-files”
Changed¶
- If multiple
--tokens are present on the command line, all subsequent occurrences after the first are now parsed as positional arguments. Previously, subsequent--tokens were skipped. - The
PlaintextHelpFormatterhas been replaced withCliktHelpFormatter, which is more customizable. See the docs for more info, or the new sample for an example of customizing help output to use ANSI colors. - Some of the properties and constructor parameters for
OptionWithValuesandProcessedArgumenthave changed. - The
OptionDelegateinterface has changed, andGroupableOptionandParameterHolderinterfaces have been added to work with option groups. - Parameter validation now occurs after all parameter delegates have set their values, so the lambdas passed to
validatemay reference other parameters.
1.7.0¶
Added¶
printHelpOnEmptyArgsparameter toCliktCommandconstructor. (#41)
Fixed¶
- Usage errors now correctly print subcommand names. (#47)
- Arguments with
multiple(required=true)now report an error if no argument is given on the command line. (#36)
1.6.0¶
Added¶
.multiple().unique()modifier for options and arguments.
Fixed¶
- Support multi-line input when redirecting stdin
1.5.0¶
Added¶
- Ability to use alternate output streams rather than stdin and stdout by setting
Context.consoleor by passing a console toTermUIfunctions.
1.4.0¶
Added¶
path()type for parameter values
Changed¶
- Clikt now targets JVM 8 bytecode
- Responses to
TermUi.confirm()are now case-insensitive
1.3.0¶
Added¶
defaultLazyextension for options and arguments
Changed¶
mainnow prints messages to stderr instead of stdout
Fixed¶
- Parameter help messages are now wrapped more consistently
1.2.0¶
Added¶
- Default parameter to
option().default()
Changed¶
- Treat tokens with unknown prefixes as arguments (this makes it easier
to pass in file paths without using
--).
1.1.0¶
Added¶
List<String>overloads toCliktCommand.parseandmainerrparameter toTermUi.echoerrorproperty toAbort