Skip to content
package

org.draftcode.argot

Classes

  • ArgotConversionExceptionThrown by a Converter when a raw string cannot be converted to the target type.
  • ArgotParseExceptionBase type for all user-input parsing failures.
  • ArgumentBuilderBuilds a positional argument, named after the property it is assigned to.
  • ArgumentListBuilderA trailing list argument, reached via ArgumentBuilder.
  • ArgumentsBase class for declaring a command line with by delegates.
  • ArgumentSpecA positional parameter, consumed left to right from the non-option arguments.
  • CommandSpecDescribes a command: its name, description, optional version, and parameters.
  • EnumConverterMatches a raw value against enum constant names, case-insensitively.
  • FlagBuilderBuilds a boolean flag.
  • FlagSpecA named boolean parameter whose presence means true.
  • HelpRequestedThrown when --help or -h is present.
  • OptionalArgumentBuilderAn optional positional argument, reached via ArgumentBuilder.
  • OptionBuilderBuilds a value-bearing option.
  • OptionListBuilderA repeatable option, reached via OptionBuilder.
  • OptionSpecA named parameter that takes a value, for example --count 3, --count=3, or -c 3.
  • ParamSpecA declared command-line parameter: an OptionSpec, FlagSpec, or ArgumentSpec.
  • ParsedValuesThe typed result of a successful parse, keyed by each parameter's canonical name.
  • RequiredOptionBuilderAn option that always resolves to a value, reached via OptionBuilder.
  • VersionRequestedThrown when --version is present and CommandSpec.

Interfaces

  • ConverterConverts a raw command-line string into a typed value.

Objects

Top-level declarations

cli

fun <T> cli(block: () -> T): T

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

  • success returns the parsed value;

  • --help and --version print to stdout and exit 0;

  • invalid input prints the usage line and error: … to stderr and exits 2.

fun main(argv: Array<String>) {
    val args = cli { parseServeArgs(argv) }   // generated parser, or ServerArgs().parse(argv)
    runServer(args)
}
Cli.kt

enumConverter

inline fun <E> enumConverter(): EnumConverter<E>
Converters.kt

parse

fun <T> T.parse(argv: Array<String>): T

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

ThrowsHelpRequested

if --help or -h is present.

ThrowsVersionRequested

if --version is present and a version is configured.

ThrowsArgotParseException

if the input is invalid.

Arguments.kt

parsed

fun <T> T.parsed(argv: Array<String>): T

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

Arguments.kt

Released under the Apache License 2.0.