- Publish
iosArm64
andiosX64
targets. - Added
NoSuchArgument
exception that is thrown when too many arguments were given on the command line. Previously, a less specificUsageError
was thrown instead. - Added
CommandLineParser.tokenize
that splits a string into argv tokens. - Added
CommandLineParser
that provides functions for parsing and finalizing commands manually for more control. - Added
Context.invokedSubcommands
that contains all subcommands of the current command that are going to be invoked whenallowMultipleSubcommands
istrue
. - Added
SuspendingCliktCommand
that has asuspend fun run
method, allowing you to use coroutines in your commands. - Added
ChainedCliktCommand
that allows you to return a value from yourrun
method and pass it to the next command in the chain. - Added
Context.data
as an alternative toobj
that allows you to store more than one object in the context. - Added
Context.echoer
to customize howecho
messages are printed. - Added
CompletionGenerator
to manually generate completions for a command. - Added
Context.exitProcess
which 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.test
to 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)
-
In a subcommand with
argument().multiple()
, 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
andCliktCommand.parse
are now extension functions rather than methods. -
Breaking Change:
Context.obj
andContext.terminal
, andOptionTransformContext.terminal
are now extension functions rather than properties. -
Breaking Change: The
RenderedSection
andDefinitionRow
classes have moved toAbstractHelpFormatter
. -
Updated Kotlin to 2.0.0
- Fixed excess arguments not being reported when
allowMultipleSubcommands=true
and a subcommand has excess arguments followed by another subcommand. - Commands with
printHelpOnEmptyArgs=true
will no longer print help if an option has a value from an environment variable or value source. (#382)
- 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.data
map. - Deprecated
Context.expandArgumentFiles
. UseContext.argumentFileReader
instead. - Renamed the following
Context
fields 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 previously deprecated experimental annotations.
- Removed
MordantHelpFormatter.graphemeLength
- Removed
TermUi
- Publish
linuxArm64
andwasmJs
targets.
- Added
limit
parameter 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.registerClosable
andContext.callOnClose
to allow you to register cleanup actions that will be called when the command exits. (#395)
- 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)
- 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)
- Added
toString
implementations to options and arguments. (#434) - Added
CliktCommand.test
overload that takes a vararg ofString
s as the command line arguments. Thanks to @sschuberth for the contribution (#451)
- Update Mordant dependency to fix crashes on native targets and GraalVM (#447)
- Added
requireConfirmation
parameter tooption().prompt()
(#426) - Added
CliktCommand.terminal
extension for accessing the terminal from a command. - Added
includeSystemEnvvars
,ansiLevel
,width
, andheight
parameters to allCliktCommand.test
overloads.
- Deprecated
CliktCommand.prompt
, useCliktCommand.terminal.prompt
orPrompt
instead. - Deprecated
CliktCommand.confirm
, useYesNoPrompt
instead.
- Fixed incorrect error message when a
defaultLazy
option referenced arequired
option. (#430)
- 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 likeoptionalValue()
but the default value is computed lazily. (#381)
- Updated Kotlin to 1.9.0
PrintMessage
,PrintHelpMessage
andPrintCompletionMessage
now default to exiting with a status code 0, which is the behavior they had in 3.x. (#419)
- Added
Context.errorEncountered
which 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.
Option.optionHelp
andArgument.argumentHelp
,CliktCommand.commandHelp
, andCliktCommand.commandHelpEpilog
are now methods that take the context as an argument, and thehelp
parameter tocopy
is now ahelpGetter
lambda.CliktCommand.shortHelp
now takes the context as an argument.- The
message
method onTransformContext
interfaces is now an extension.
- Deprecated
CliktCommand.commandHelp
andcommandHelpEpilog
properties in favor of the methods with the same name.
- 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
obj
setter 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.test
extension for testing your commands and their output - Clikt will now report multiple errors if they occur via the new
MultiUsageError
exception, 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.argumentFileReader
which allows custom loading of argument files - Added
Context.allowGroupedShortOptions
which can disable parsing-abc
as-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=1
and not--option 1
- Added
CliktCommand.test()
that captures the output of a command and does not exit the process.
- Removed
CliktConsole
. Mordant is now used for all input and output. If you were defining a custom console, instead define a mordantTerminalInterface
and 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
. UseMordantHelpFormatter
instead. - Removed
FlagOption
andEagerOption
classes. All options are now implemented as transformations onOptionWithValues
.FlagOption
is nowOptionWithValues<Boolean, Boolean, Boolean>
.
prompt
andconfirm
are now implemented with mordant's prompt functionality, and the method parameters have changed to match mordant's- When using
treatUnknownOptionsAsArgs
, grouped short options like-abc
will 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
trimIndent
on strings passed tohelp
. CalltrimIndent
ortrimMargin
yourself if necessary. Context.Builder.helpOptionNames
now accepts any iterable rather than just a set.CliktCommand.echo
andprompt
are 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.helpFormatter
is 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
. CliktError
now includesstatusCode
andprintError
properties.- The constructor of
UsageError
and its subclasses no longer takes acontext
parameter. The context is now inferred automatically. UsageError.formatUsage
now takes the localization and formatter as arguments
- 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
treatUnknownOptionsAsArgs
is true, grouped unknown short options will now be treated as arguments rather than reporting an error.
- Revert jvm jars to target Java 8
- Updated Kotlin to 1.8.22
- 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.
- Updated Kotlin to 1.8.10
- Fix
CliktCommand.prompt
on NodeJS targets that would hang due to KT-55817 (#387)
- Updated Kotlin to 1.7.20
- Support unicode in environment variable values on Native Windows. (#362)
- Support environment variables for options in a mutually exclusive options group. (#384)
- Added
hidden
parameter toCliktCommand
, which will prevent the command from being displayed as a subcommand in help output (#353) - Publish artifacts for the
macosArm64
target. Note that this target is not tested on CI. (#352)
- Default values for arguments will now be included in help output when
showDefaultValues=true
is set on your help formatter (#357)
- Fix flags and other options with defaults not being usable in
mutuallyExclusiveOptions
(#349) - Fix
CompletionCommand
generating completion for itself (#355)
TermUi.echo
,TermUi.prompt
, andTermUi.confirm
. Use the equivalent methods onCliktCommand
instead. (#344)
- Added
obj
setter to context builder as an alternative tocurrentContext.obj
- Added
option().boolean()
andargument().boolean()
uint()
andulong()
parameter type conversions.CliktCommand.test
extension for testing your commands and their output
- Updated Kotlin to 1.6.20
unique()
now works with any option with a list type, not justmultiple()
options (#332)- Updated Kotlin to 1.6.10
- Fixed co-occurring option groups returning null when all options in the group are defined in environment variables (#330)
- Added
default
parameter toargument().multiple()
(#305) Context.originalArgv
that 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)
defaultLazy
values can now reference other parameters, as long the referenced parameters do not also reference other parameters- You can now call
CliktCommand.context
multiple times on the same command, and all builder blocks will be applied - Validate values entered to a
prompt
option, and show another prompt if the validation fails (#288) - Updated kotlin to 1.5.31
- Report error when excess arguments are given to a command with
allowMultipleSubcommands=true
(#303)
InputStream.isCliktParameterDefaultStdin
andOutputStream.isCliktParameterDefaultStdout
to check if the streams returned frominputStream
/outputStream
options are proxying stdin/stdout (#272)
- Make parameters of
mutuallyExclusiveOptions
covariant to allow validation without explicit type annotations. (#265) - Updated kotlin to 1.5.0
- Reading from an option or argument property on a command that hasn't been invoked will now always throw an
IllegalStateException
- Added
required()
anddefaultLazy()
for nullable flag options likeswitch()
. (#240) - Added support for generating autocomplete scripts for Fish shells (#189)
- Added
CompletionCommand
andCliktCommand.completionOption()
that will print an autocomplete script when invoked, as an alternative to using environment variables.
- Updated Kotlin to 1.4.21
@argfiles
now 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)
- Deprecated calling
echo
witherr
orlineSeparator
but nomessage
.
- 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
defaultForHelp
argument, 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
valueSourceKey
parameter tooption
- Added
check()
extensions to options and arguments as an alternative tovalidate()
- Added
prompt
andconfirm
functions toCliktCommand
that call theTermUi
equivalents 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
Localization
interface on your context with your translations. (#227)
- 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)
- Updated Kotlin to 1.4.0
Argument.help
andOption.help
properties have been renamed toargumentHelp
andoptionHelp
, respectively. Thehelp
parameter names tooption()
andargument()
are unchanged.commandHelp
andcommandHelpEpilog
properties onCliktCommand
are nowopen
, so you can choose to override them instead of passinghelp
andepilog
to the constructor.- Replaced
MapValueSource.defaultKey
withValueSource.getKey()
, which is more customizable. Option.metavar
,Option.parameterHelp
,OptionGroup.parameterHelp
andArgument.parameterHelp
properties are now functions.- Changed constructor parameters of
CliktHelpFormatter
. Addedlocalization
and removedusageTitle
,optionsTitle
,argumentsTitle
,commandsTitle
,optionsMetavar
, andcommandMetavar
. Those strings are now defined on equivalently named functions onLocalization
.
- Removed
envvarSplit
parameter 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
. MissingParameter
exception replaced withMissingOption
andMissingArgument
- Removed
Context.helpOptionMessage
. OverrideLocalization.helpOptionMessage
and set it on your context instead.
@ExperimentalCompletionCandidates
and@ExperimentalValueSourceApi
annotations. These APIs no longer require an opt-in.
- Added
error
parameter toPrintMessage
andPrintHelpMessage
. Whentrue
,CliktCommand.main
will exit with status code 1. (#187)
- When
printHelpOnEmptyArgs
istrue
and no arguments are present, or wheninvokeWithoutSubcommand
isfalse
and no subcommand is present,CliktCommand.main
will now exit with status code 1 rather than 0. restrictTo
now works with anyComparable
value, not justNumber
.CliktCommand.main
now acceptsArray<out String>
, not justArray<String>
. (#196)
- Fixed option values being reset when calling multiple subcommands with
allowMultipleSubcommands=true
(#190)
- Fixed NPE thrown in some cases when using
defaultByName
(#179)
- Ability to use custom program exit status codes via
ProgramResult
. inputStream
andoutputStream
conversions for options and arguments. (#157 and #159)splitPair
,toMap
, andassociate
extensions onoption
. (#166)treatUnknownOptionsAsArgs
parameter toCliktCommand
. (#152)defaultByName
function forgroupChoice
andgroupSwitch
options. (#171)
- Update Kotlin to 1.3.71
- Improved command name inference. Now, a class like
MyAppCommand
will infer itscommandName
asmy-app
rather thanmyappcommand
. You can still specify the name manually as before. (#168)
- Correctly parse short options with attached values that contain
=
registeredSubcommands
,registeredOptions
,registeredArguments
, andregisteredParameterGroups
methods 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
json
sample for an example of reading from other formats. allowMultipleSubcommands
parameter toCliktCommand
that 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
- Update Kotlin to 1.3.70
convert
can be called more than once on the same option or argument, including after calls to conversion functions likeint
andfile
.CliktCommand.toString
now 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()
wrapValue
is now deprecated, sinceconvert
can be used in its place instead.
- 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
groupName
when creating them. canBeSymlink
parameter tofile()
andpath()
conversions that can be used to disallow symlinksCliktCommand.eagerOption
to simplify creating custom eager options
- 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.
- The
CliktCommand.context
property has been deprecated in favor of the new name,currentContext
, to avoid confusion with theCliktCommand.context{}
method. NoRunCliktCommand
was renamed toNoOpCliktCommand
. The existing class is deprecated. (#130)
file()
andpath()
conversions will now properly expand leading~
in paths to the home directory formustExist
,canBeFile
, andcanBeDir
checks. The property value is unchanged, and can still begin with a~
. (#131)
CompletionCandidates.Fixed
now has a secondary convenience constructor that take avararg
ofString
sCompletionCadidates.Custom
, which allows you to call other binaries or write a script to generate completions. This class is currently experimental. (#79)Option.wrapValue
andArgument.wrapValue
to make it easier to reuse existing conversion functions.ignoreCase
parameter tochoice()
andenum()
conversion functions.
option()
andargument()
now take optionalcompletionCandidates
parameters to override how completion is generated. The constructor andcopy
functions ofOptionsWithValues
andProcessedArgument
have 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 = false
toenum()
(#115)
groupChoice
help 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)
option().groupSwitch()
, which works likegroupChoice()
, but uses aswitch()
option rather than achoice()
option.UsageError
now has astatusCode
parameter (which defaults to 1). If you're usingClicktCommand.main
, the value ofstatusCode
will be passed toexitProcess
.
- Shell completion code is now printed by throwing a
PrintCompletionMessage
(a subclass ofPrintMessage
) rather than callingecho
directly.
- Added
enum()
conversion for options and arguments. (#84)
- There are now several ways of preventing @-file expansion
- Help output missing items when no help text is specified. (#85)
- Help output not grouping options in groups passed to
groupChoice
. (#88)
- Ability to prevent rewrapping individual paragraphs in help output.
- Added parameter
required
toOption.multiple()
to require at least one instance of the option on the command line.
CliktCommand.toString()
now includes the names and values of all parameters and subcommands.
- Create subcommand context when
helpOptionNames
is empty. (#64)
- Bash autocomplete script generation. A property named
completionCandidates
has been added toArgument
andOption
interfaces, and corresponding parameters have been added to the various implementation constructors, as well as theconvert
functions. 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
envvarSplit
parameter ofoption()
- Option groups, mutually exclusive groups, co-occurring groups, and choice options with groups
- Support for Command line argument files a.k.a. "@-files"
- 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
PlaintextHelpFormatter
has 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
OptionWithValues
andProcessedArgument
have changed. - The
OptionDelegate
interface has changed, andGroupableOption
andParameterHolder
interfaces 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
validate
may reference other parameters.
printHelpOnEmptyArgs
parameter toCliktCommand
constructor. (#41)
- 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)
.multiple().unique()
modifier for options and arguments.
- Support multi-line input when redirecting stdin
- Ability to use alternate output streams rather than stdin and stdout by setting
Context.console
or by passing a console toTermUI
functions.
path()
type for parameter values
- Clikt now targets JVM 8 bytecode
- Responses to
TermUi.confirm()
are now case-insensitive
defaultLazy
extension for options and arguments
main
now prints messages to stderr instead of stdout
- Parameter help messages are now wrapped more consistently
- Default parameter to
option().default()
- Treat tokens with unknown prefixes as arguments (this makes it easier
to pass in file paths without using
--
).
List<String>
overloads toCliktCommand.parse
andmain
err
parameter toTermUi.echo
error
property toAbort