clikt / com.github.ajalt.clikt.core / Context


class Context

A object used to control command line parsing and pass data between commands.

A new Context instance is created for each command each time the command line is parsed.


Name Summary
Builder class Builder


Name Summary
<init> A object used to control command line parsing and pass data between commands.Context(parent:Context?, command:CliktCommand, allowInterspersedArgs:Boolean, autoEnvvarPrefix:String?, printExtraMessages:Boolean, helpOptionNames:Set<String>, helpOptionMessage:String, helpFormatter:HelpFormatter, tokenTransformer:Context.(String) ->String, console:CliktConsole, expandArgumentFiles:Boolean, readEnvvarBeforeValueSource:Boolean, valueSource:ValueSource?, correctionSuggestor:TypoSuggestor)


Name Summary
allowInterspersedArgs If false, options and arguments cannot be mixed; the first time an argument is encountered, all remaining tokens are parsed as arguments.val allowInterspersedArgs:Boolean
autoEnvvarPrefix The prefix to add to inferred envvar names. If null, the prefix is based on the parent’s prefix, if there is one. If no command specifies, a prefix, envvar lookup is disabled.val autoEnvvarPrefix:String?
command The command that this context associated with.val command:CliktCommand
console The console to use to print messages.val console:CliktConsole
correctionSuggestor A callback called when the command line contains an invalid option or subcommand name. It takes the entered name and a list of all registered names option/subcommand names and filters the list down to values to suggest to the user.val correctionSuggestor:TypoSuggestor
expandArgumentFiles If true, arguments starting with @ will be expanded as argument files. If false, they will be treated as normal arguments.val expandArgumentFiles:Boolean
helpFormatter The help formatter for this command.val helpFormatter:HelpFormatter
helpOptionMessage The description of the help option.val helpOptionMessage:String
helpOptionNames The names to use for the help option. If any names in the set conflict with other options, the conflicting name will not be used for the help option. If the set is empty, or contains no unique names, no help option will be added.val helpOptionNames:Set<String>
invokedSubcommand var invokedSubcommand:CliktCommand?
obj var obj:Any?
parent If this context is the child of another command, parent is the parent command’s context.val parent:Context?
printExtraMessages Set this to false to prevent extra messages from being printed automatically. You can still access them at CliktCommand.messages inside of printExtraMessages:Boolean
readEnvvarBeforeValueSource val readEnvvarBeforeValueSource:Boolean
tokenTransformer An optional transformation function that is called to transform command line tokens (options and commands) before parsing. This can be used to implement e.g. case insensitive behavior.val tokenTransformer:Context.(String) ->String
valueSource val valueSource:ValueSource?


Name Summary
commandNameWithParents Return a list of command names, starting with the topmost command and ending with this Context’s commandNameWithParents():List<String>
fail Throw a UsageError with the given messagefun fail(message:String= ""):Nothing
findObject Find the closest object of type Tfun <T :Any> findObject(): T?``fun <T :Any> ~~findObject~~(defaultValue: () -> T): T
findOrSetObject Find the closest object of type T, setting this.obj if one is not <T :Any> findOrSetObject(defaultValue: () -> T): T
findRoot Find the outermost contextfun findRoot():Context
parentNames Return a list of command names, starting with the topmost command and ending with this Context’s parentNames():List<String>

Companion Object Functions

Name Summary
build fun build(command:CliktCommand, parent:Context? = null, block: Builder.() ->Unit):Context