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)


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
expandArgumentFiles If true, arguments starting with @ will be expanded as argument files. If false, they will be treated as normal arguments.var 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
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


Name Summary
fail Throw a UsageError with the given messagefun fail(message:String= ""):Nothing
findObject Find the closest object of type Tfun <T> findObject(): T?``fun <T> ~~findObject~~(defaultValue: () -> T): T
findOrSetObject Find the closest object of type T, setting this.obj if one is not <T> findOrSetObject(defaultValue: () -> T): T
findRoot Find the outermost contextfun findRoot():Context

Companion Object Functions

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