Context

class Context constructor(parent: Context?, command: CliktCommand, allowInterspersedArgs: Boolean, autoEnvvarPrefix: String?, printExtraMessages: Boolean, helpOptionNames: Set<String>, helpFormatter: HelpFormatter, tokenTransformer: Context.(String) -> String, console: CliktConsole, expandArgumentFiles: Boolean, readEnvvarBeforeValueSource: Boolean, valueSource: ValueSource?, correctionSuggestor: TypoSuggestor, localization: Localization, readEnvvar: (String) -> String?, originalArgv: List<String>)

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.

Constructors

Link copied to clipboard
fun Context(parent: Context?, command: CliktCommand, allowInterspersedArgs: Boolean, autoEnvvarPrefix: String?, printExtraMessages: Boolean, helpOptionNames: Set<String>, helpFormatter: HelpFormatter, tokenTransformer: Context.(String) -> String, console: CliktConsole, expandArgumentFiles: Boolean, readEnvvarBeforeValueSource: Boolean, valueSource: ValueSource?, correctionSuggestor: TypoSuggestor, localization: Localization, readEnvvar: (String) -> String? = ::readEnvvar, originalArgv: List<String> = emptyList())

Types

Link copied to clipboard
class Builder(command: CliktCommand, parent: Context?)
Link copied to clipboard
object Companion

Functions

Link copied to clipboard
fun commandNameWithParents(): List<String>

Return a list of command names, starting with the topmost command and ending with this Context's command.

Link copied to clipboard
fun fail(message: String = ""): Nothing

Throw a UsageError with the given message

Link copied to clipboard
inline fun <T : Any> findObject(): T?

Find the closest object of type T

Link copied to clipboard
inline fun <T : Any> findOrSetObject(defaultValue: () -> T): T

Find the closest object of type T, setting this.obj if one is not found.

Link copied to clipboard
fun findRoot(): Context

Find the outermost context

Link copied to clipboard
fun parentNames(): List<String>

Return a list of command names, starting with the topmost command and ending with this Context's parent.

Properties

Link copied to clipboard
val allowInterspersedArgs: Boolean

If false, options and arguments cannot be mixed; the first time an argument is encountered, all remaining tokens are parsed as arguments.

Link copied to clipboard
val autoEnvvarPrefix: String?

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.

Link copied to clipboard
val command: CliktCommand

The command that this context associated with.

Link copied to clipboard
val console: CliktConsole

The console to use to print messages.

Link copied to clipboard
val correctionSuggestor: TypoSuggestor

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.

Link copied to clipboard
val expandArgumentFiles: Boolean

If true, arguments starting with @ will be expanded as argument files. If false, they will be treated as normal arguments.

Link copied to clipboard
val helpFormatter: HelpFormatter

The help formatter for this command.

Link copied to clipboard
val helpOptionNames: Set<String>

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.

Link copied to clipboard
var invokedSubcommand: CliktCommand? = null
Link copied to clipboard
val localization: Localization
Link copied to clipboard
var obj: Any? = null
Link copied to clipboard
val originalArgv: List<String>
Link copied to clipboard
val parent: Context?

If this context is the child of another command, parent is the parent command's context.

Link copied to clipboard
val printExtraMessages: Boolean

Set this to false to prevent extra messages from being printed automatically. You can still access them at CliktCommand.messages inside of CliktCommand.run.

Link copied to clipboard
val readEnvvar: (String) -> String?
Link copied to clipboard
val readEnvvarBeforeValueSource: Boolean
Link copied to clipboard
val tokenTransformer: Context.(String) -> String

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.

Link copied to clipboard
val valueSource: ValueSource?