Manuscript Documentation
v2026.12.0

@std/cli/command.ms#

Import each required symbol with import Name from "@std/cli/command.ms".

Arg Type#

A positional argument, bound in declaration order.

Manuscript
type Arg {
    name String
    help String = ""
    required Bool = true
    rest Bool = false
    kind FlagKind = FlagKind.String
}

Arg.help#

One line shown in help.

Manuscript
help String = ""

Arg.kind#

What the argument accepts: String (the default), Int or Float. An Int or Float argument fills a record field of that type and fails the run when the word does not parse. Bool and List are not positional kinds, and a rest argument is always List[String].

Manuscript
kind FlagKind = FlagKind.String

Arg.name#

The key Matches reads it by.

Manuscript
name String

Arg.required#

Absence is an error. A required argument may not follow an optional one.

Manuscript
required Bool = true

Arg.rest#

Takes every remaining word as a list; only the last argument may be rest.

Manuscript
rest Bool = false

Command Type#

A command or command group: its schema, subcommands and handler.

A group is a Command with children. Build a leaf with command[T], then call execute(arguments()) from main. Start with the complete CLI recipe ; use exec directly when you need Matches.

Manuscript
type Command {
    name String
    about String = ""
    flags List[Flag] = []
    args List[Arg] = []
    children List[Command] = []
    exec fn(Matches) Result[Int, Error] = m => ok(0)
}

Command.about#

One line shown in help.

Manuscript
about String = ""

Command.args#

Positional arguments in order.

Manuscript
args List[Arg] = []

Command.children#

Subcommands in help order; their names must be unique, nonempty and not help.

Manuscript
children List[Command] = []

Command.exec#

Runs after a successful parse; the returned Int is the exit status.

Manuscript
exec fn(Matches) Result[Int, Error] = m => ok(0)

Command.flags#

Flags declared here; persistent ones also apply below.

Manuscript
flags List[Flag] = []

Command.name#

The word that selects this node; the program name for the root.

Manuscript
name String

Command.child#

Returns the child named word, or null; the result reads the child in place.

Manuscript
fn child(word String) Command?

Command.execute#

Parses argv, writes help to stdout or the error plus a usage hint to stderr, and runs the handler. Returns the handler’s status, 0 after help, 1 when the handler fails and 2 for a usage error.

Manuscript
fn execute(argv List[String]) Int

Command.help#

Returns the help text for the command reached by following path from this node, or null for an unknown path.

Manuscript
fn help(path List[String] = []) String?

Command.parse#

Checks the command tree, resolves the subcommand chain, and validates flags and arguments. Returns Help for -h, --help, a leading help word, or a group invoked without a subcommand; an invalid schema or usage error returns EINVAL.

Manuscript
fn parse(argv List[String]) Result[Parsed, Error]

Command.run#

Runs the handler of the command matches.path names, as parse resolved it, and returns its exit status. The path starts at this node’s name; an unknown path is an EINVAL error.

Manuscript
fn run(matches Matches) Result[Int, Error]

Flag Type#

A named option such as --port 8080 or -p 8080.

Manuscript
type Flag {
    name String
    kind FlagKind = FlagKind.String
    short String = ""
    default String? = null
    help String = ""
    required Bool = false
    persistent Bool = false
    choices List[String] = []
}

Flag.choices#

When not empty, every value must be one of these texts; use with String and List flags.

Manuscript
choices List[String] = []

Flag.default#

Text used when the flag is absent; null for no default. A Bool defaults to false.

Manuscript
default String? = null

Flag.help#

One line shown in help.

Manuscript
help String = ""

Flag.kind#

What the flag accepts, and so the type of the record field; defaults to String.

Manuscript
kind FlagKind = FlagKind.String

Flag.name#

The long name without dashes; also the key Matches reads it by.

Manuscript
name String

Flag.persistent#

Also accepted by every subcommand below the command that declares it.

Manuscript
persistent Bool = false

Flag.required#

Absence is an error when there is no default. A Bool or List flag is never absent (false or empty), so required has no effect on it.

Manuscript
required Bool = false

Flag.short#

One-letter alias used as -p; empty for none. A value follows as -p 8080 or -p=8080; short flags do not combine (-vd) or attach a value (-p8080).

Manuscript
short String = ""

FlagKind Enum#

What a flag accepts. Each case fills the record field of the same language type.

Manuscript
enum FlagKind {
    Bool
    String
    Int
    Float
    List
}

FlagKind.Bool#

Bool field. Present or absent; --name, --name=false and --no-name are accepted.

Manuscript
Bool

FlagKind.Float#

Float field. A finite decimal number that parses as Float; other text, including NaN and infinities, returns an Error with kind "EINVAL".

Manuscript
Float

FlagKind.Int#

Int field. A whole number that fits in Int; other text returns an Error with kind "EINVAL".

Manuscript
Int

FlagKind.List#

List[String] field. The flag may repeat; every occurrence is kept in order.

Manuscript
List

FlagKind.String#

String field. Any text. The value may begin with a dash (--name=-x or --name -x).

Manuscript
String

Matches Type#

The values one invocation produced.

Reading a name the schema does not declare, or reading it as the wrong kind, is a programmer error and faults. A flag with a default or required, and a required argument, always has a value.

Manuscript
type Matches {
    values Map[String, List[String]] = Map[String, List[String]]()
    path List[String] = []
    fields Map[String, String] = Map[String, String]()
}

Matches.fields#

The JSON literal for each supplied value by field name (dashes in names become underscores); decoded by command.

Manuscript
fields Map[String, String] = Map[String, String]()

Matches.path#

The command names walked from the root, root included.

Manuscript
path List[String] = []

Matches.values#

Text values by flag or argument name; a List flag or rest argument holds several.

Manuscript
values Map[String, List[String]] = Map[String, List[String]]()

Matches.bool#

Returns a Bool flag value; absent is false.

Manuscript
fn bool(name String) Bool

Matches.float#

Returns a Float flag or argument value.

Manuscript
fn float(name String) Float

Matches.float_or_null#

Returns a Float value, or null when absent.

Manuscript
fn float_or_null(name String) Float?

Matches.int#

Returns an Int flag or argument value.

Manuscript
fn int(name String) Int

Matches.int_or_null#

Returns an Int value, or null when absent.

Manuscript
fn int_or_null(name String) Int?

Matches.list#

Returns every value of a List flag or rest argument, in order; empty when absent.

Manuscript
fn list(name String) List[String]

Matches.string#

Returns the text of a flag or argument.

Manuscript
fn string(name String) String

Matches.string_or_null#

Returns the text, or null for an optional argument or flag that was not supplied.

Manuscript
fn string_or_null(name String) String?

Parsed Enum#

The outcome of parsing: help text to show, or a node ready to run.

Manuscript
enum Parsed {
    Help(text String)
    Run(matches Matches)
}

Parsed.Help#

-h, --help, a leading help word, or a group invoked without a subcommand.

Manuscript
Help(text String)

Parsed.Run#

A leaf to run: Command.run passes the values to the handler at matches.path.

Manuscript
Run(matches Matches)

Parsed.Help.text#

The rendered help ending in a newline, ready to write to stdout.

Manuscript
text String

Parsed.Run.matches#

The values to pass the handler; path names the command reached from the root.

Manuscript
matches Matches

command Function#

Builds a leaf command whose handler receives the options record T.

Each field of T is filled from the flag or argument with its name, dashes written as underscores, and has the type its kind names:

declaredfield type
FlagKind.BoolBool (absent is false)
FlagKind.StringString
FlagKind.IntInt
FlagKind.FloatFloat
FlagKind.List, and a rest argumentList[String] (absent is empty)
Arg with kind Int or FloatInt or Float
any other ArgString

A flag with neither a default nor required, and an optional Arg, needs an ...? field, which is null when absent. A field with no matching value, or of the wrong type, fails the run with an Error with kind "EINVAL". The handler returns the exit status.

Manuscript
fn command[T Data](move name String, move run fn(T) Result[Int, Error], move about String = "", move flags List[Flag] = [], move args List[Arg] = []) Command { ... }