Skip to content

Command

1 min read

Import system.cli. See the CLI guide for examples.

Command

Declarative CLI definition. Parsing consumes arguments without an executable name and never exits.

public class Command

constructor

Creates a command; invalid names or conflicting definitions return errors from parse.

public constructor(name: string)

version

Sets version output and enables --version/-V for this command and its descendants.

public fun version(value: string): Command

description

Sets text included in automatically generated help.

public fun description(value: string): Command

require_subcommand

Requires one of the declared subcommands; --help and --version still return normal outcomes.

public fun require_subcommand(required: bool = true): Command

positional

Adds an ordered string positional; only the last positional can collect multiple arguments.

public fun positional(
    name: string,
    required: bool = false,
    multiple: bool = false,
    description: string = ""
): Command

string_option

Adds a string option. Optional values default to empty; repeated occurrences are collected, with the last returned by get_string.

public fun string_option(
    name: string,
    short: string = "",
    default_value: string = "",
    required: bool = false,
    description: string = ""
): Command

int_option

Adds a decimal 32-bit integer option. Optional values default to zero; required options ignore defaults.

public fun int_option(
    name: string,
    short: string = "",
    default_value: int = 0,
    required: bool = false,
    description: string = ""
): Command

flag

Adds a boolean option defaulting to false; repeated occurrences remain true.

public fun flag(name: string, short: string = "", description: string = ""): Command

choices

Restricts a previously declared string, positional, or integer argument to these exact values.

public fun choices(name: string, values: string[]): Command

subcommand

Snapshots a child definition. Later edits to the child do not mutate its attached copy.

public fun subcommand(command: Command): Command

parse

Parses explicit arguments; pass System.args to parse the process arguments. Returns errors for invalid definitions, arguments, or conversions. Does not exit the process.

@native
public fun parse(arguments: string[]): Result<ParsedArguments, CliError>