Context

class Context

An 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.

Types

Link copied to clipboard
class Builder(command: BaseCliktCommand<*>, val parent: Context? = null)
Link copied to clipboard
object Companion

Properties

Link copied to clipboard

If true, short options can be grouped after a single - prefix.

Link copied to clipboard

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 argumentFileReader: (filename: String) -> String?
Link copied to clipboard

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

The command that this context associated with.

Link copied to clipboard
Link copied to clipboard

A map holding arbitrary data on the context.

Link copied to clipboard

The callable to call to echo output.

Link copied to clipboard

If true, an error was previously encountered while parsing the command line, but parsing is continuing to collect any more errors into a MultiUsageError.

Link copied to clipboard
val exitProcess: (status: Int) -> Unit

The function to call to exit the process with a status code.

Link copied to clipboard

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

Link copied to clipboard

The help formatter for this command.

Link copied to clipboard

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

If this command has subcommands and one of them was invoked, this is the subcommand that will be run first.

Link copied to clipboard

All invoked subcommands, in the order they were invoked.

Link copied to clipboard

Localized strings to use for help output and error reporting.

Link copied to clipboard

Set an arbitrary object on the context.

Link copied to clipboard

The original command line arguments.

Link copied to clipboard

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

Link copied to clipboard

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

Link copied to clipboard
var readArgumentFile: (filename: String) -> String?

A block that returns the content of an argument file for a given filename.

Link copied to clipboard

A function called by Clikt to get a parameter value from a given environment variable

Link copied to clipboard

If false,the valueSource is searched before environment variables.

Link copied to clipboard

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

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

The source that will attempt to read values for options that aren't present on the command line.

Functions

Link copied to clipboard
fun callOnClose(closeable: () -> Unit)

Register a callback to be called when this command and all its subcommands have finished.

Link copied to clipboard
fun close()

Close all registered closeables in the reverse order they were registered.

Link copied to clipboard

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(key: String = DEFAULT_OBJ_KEY): T?

Find the closest object with key of type T

Link copied to clipboard
inline fun <T : Any> findOrSetObject(key: String = DEFAULT_OBJ_KEY, defaultValue: () -> T): T

Find the closest object with key of type T, setting it on this if one is not found.

Link copied to clipboard

Find the outermost context

Link copied to clipboard

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

Link copied to clipboard

Register an AutoCloseable to be closed when this command and all its subcommands have finished running.

Link copied to clipboard

Register an AutoCloseable to be closed when this command and all its subcommands have finished running.

Link copied to clipboard
open override fun toString(): String