Package-level declarations

Types

Link copied to clipboard
class ArgotConversionException(message: String, cause: Throwable? = null) : Exception

Thrown by a Converter when a raw string cannot be converted to the target type.

Link copied to clipboard

Parses an argument list against a CommandSpec.

Link copied to clipboard

Base type for all user-input parsing failures. The cli wrapper prints usage and the message to stderr and exits 2.

Link copied to clipboard

Builds a positional argument, named after the property it is assigned to. The call you end with decides the property's type:

Link copied to clipboard

A trailing list argument, reached via ArgumentBuilder.multiple. Resolves to an empty list when no positionals remain, unless required is set.

Link copied to clipboard
abstract class Arguments(val programName: String = "program", val description: String = "", val version: String? = null)

Base class for declaring a command line with by delegates.

Link copied to clipboard
class ArgumentSpec(val name: String, val converter: Converter<*>, val help: String = "", val required: Boolean = true, val multiple: Boolean = false) : ParamSpec

A positional parameter, consumed left to right from the non-option arguments.

Link copied to clipboard

Accepts, case-insensitively, true/false, 1/0, yes/no, y/n, and on/off.

Link copied to clipboard
class CommandSpec(val programName: String, val description: String = "", val params: List<ParamSpec>, val version: String? = null)

Describes a command: its name, description, optional version, and parameters.

Link copied to clipboard
interface Converter<out T>

Converts a raw command-line string into a typed value. Implement this to support a type beyond the built-ins.

Link copied to clipboard
Link copied to clipboard
class EnumConverter<out E : Enum<*>>(entries: List<E>, val typeName: String) : Converter<E>

Matches a raw value against enum constant names, case-insensitively.

Link copied to clipboard

Builds a boolean flag. A flag name means true, a negation name means false, and absence means default.

Link copied to clipboard
class FlagSpec(val names: List<String>, val help: String = "", val negationNames: List<String> = emptyList(), val default: Boolean = false) : ParamSpec

A named boolean parameter whose presence means true.

Link copied to clipboard

Thrown when --help or -h is present. Not an error: cli prints rendered and exits 0.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

An optional positional argument, reached via ArgumentBuilder.optional. Resolves to null when absent.

Link copied to clipboard

Builds a value-bearing option. The call you end with decides the property's type:

Link copied to clipboard

A repeatable option, reached via OptionBuilder.multiple. Resolves to an empty list when the option never appears, unless required is set.

Link copied to clipboard
class OptionSpec(val names: List<String>, val converter: Converter<*>, val help: String = "", val required: Boolean = false, val default: Any? = null, val multiple: Boolean = false) : ParamSpec

A named parameter that takes a value, for example --count 3, --count=3, or -c 3.

Link copied to clipboard
sealed class ParamSpec

A declared command-line parameter: an OptionSpec, FlagSpec, or ArgumentSpec.

Link copied to clipboard

The typed result of a successful parse, keyed by each parameter's canonical name.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Thrown when --version is present and CommandSpec.version is set. cli prints rendered and exits 0.

Functions

Link copied to clipboard
fun <T> cli(block: () -> T): T

Runs block and turns Argot's outcomes into the usual command-line behaviour:

Link copied to clipboard
inline fun <E : Enum<E>> enumConverter(): EnumConverter<E>
Link copied to clipboard
fun <T : Arguments> T.parse(argv: Array<String>): T

Parses argv into this instance and returns it, without printing or exiting.

Link copied to clipboard
fun <T : Arguments> T.parsed(argv: Array<String>): T

Parses argv into this instance via cli, printing help or errors and exiting as appropriate.