Context

class 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)

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

Context
Link copied to clipboard
common
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)

Types

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

Functions

commandNameWithParents
Link copied to clipboard
common
fun commandNameWithParents(): List<String>
Return a list of command names, starting with the topmost command and ending with this Context's command.
fail
Link copied to clipboard
common
fun fail(message: String = ""): Nothing
Throw a UsageError with the given message
findObject
Link copied to clipboard
common
inline fun <T : Any> findObject(): T?
Find the closest object of type T
findOrSetObject
Link copied to clipboard
common
inline fun <T : Any> findOrSetObject(defaultValue: () -> T): T
Find the closest object of type T, setting this.obj if one is not found.
findRoot
Link copied to clipboard
common
fun findRoot(): Context
Find the outermost context
parentNames
Link copied to clipboard
common
fun parentNames(): List<String>
Return a list of command names, starting with the topmost command and ending with this Context's parent.

Properties

allowInterspersedArgs
Link copied to clipboard
common
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.
autoEnvvarPrefix
Link copied to clipboard
common
val autoEnvvarPrefix: String?
The prefix to add to inferred envvar names.
command
Link copied to clipboard
common
val command: CliktCommand
The command that this context associated with.
console
Link copied to clipboard
common
val console: CliktConsole
The console to use to print messages.
correctionSuggestor
Link copied to clipboard
common
val correctionSuggestor: TypoSuggestor
A callback called when the command line contains an invalid option or subcommand name.
expandArgumentFiles
Link copied to clipboard
common
val expandArgumentFiles: Boolean
If true, arguments starting with @ will be expanded as argument files.
helpFormatter
Link copied to clipboard
common
val helpFormatter: HelpFormatter
The help formatter for this command.
helpOptionNames
Link copied to clipboard
common
val helpOptionNames: Set<String>
The names to use for the help option.
invokedSubcommand
Link copied to clipboard
common
var invokedSubcommand: CliktCommand? = null
localization
Link copied to clipboard
common
val localization: Localization
obj
Link copied to clipboard
common
var obj: Any? = null
parent
Link copied to clipboard
common
val parent: Context?
If this context is the child of another command, parent is the parent command's context.
printExtraMessages
Link copied to clipboard
common
val printExtraMessages: Boolean
Set this to false to prevent extra messages from being printed automatically.
readEnvvarBeforeValueSource
Link copied to clipboard
common
val readEnvvarBeforeValueSource: Boolean
tokenTransformer
Link copied to clipboard
common
val tokenTransformer: Context.(String) -> String
An optional transformation function that is called to transform command line tokens (options and commands) before parsing.
valueSource
Link copied to clipboard
common
val valueSource: ValueSource?