Specification v0.1.0

Source
Declaring a command: its flags, valued options, positional arguments, subcommands and version.

OptionSpec

pub struct OptionSpec {
    pub name: char8[..];
    pub short: char32;
    pub value: char8[..];
    pub help: char8[..];
}

One option a command accepts, such as --output FILE or -v. Copy; the text it holds is borrowed and must outlive the specification.

Source

Fields

NameTypeDescription
namechar8[..]The long name without its dashes, such as output for --output. Never empty.
shortchar32The short name, such as o for -o, or '\0' for none. An ASCII letter or digit.
valuechar8[..]What the help text calls the option's value, such as FILE, or empty for a flag that takes no value.
helpchar8[..]One line saying what the option does.

PositionalKind

pub enum PositionalKind {
    Required,
    Optional,
    Remaining
}

How a positional argument may be given. Copy, carrying no payload.

Source

Cases

NameDescription
RequiredExactly once; parsing fails without it.
OptionalAt most once.
RemainingAny number of times, taking every remaining positional argument. Only the last positional may be this kind.

PositionalSpec

pub struct PositionalSpec {
    pub name: char8[..];
    pub kind: PositionalKind;
    pub help: char8[..];
}

One positional argument a command accepts, such as <input>. Copy; the text it holds is borrowed and must outlive the specification.

Source

Fields

NameTypeDescription
namechar8[..]The name queries and the help text use, such as input. Never empty.
kindPositionalKindHow the argument may be given.
helpchar8[..]One line saying what the argument is.

CommandSpec

pub struct CommandSpec {
    pub name: char8[..];
    pub summary: char8[..];
    pub version: char8[..];
    pub options: OptionSpec[..];
    pub positionals: PositionalSpec[..];
    pub commands: CommandSpec[..];
}

A command: what it is called, what it accepts, and the subcommands under it. Copy; every slice and text it holds is borrowed and must outlive it and every parse made from it. A command with subcommands takes the first positional argument as the subcommand's name, so it should declare no positionals of its own.

Source

Fields

NameTypeDescription
namechar8[..]The command's name: the program's name at the top, and the word that selects it below.
summarychar8[..]One line saying what the command does.
versionchar8[..]The version --version reports, or empty when the command has none.
optionsOptionSpec[..]The options, in the order the help text lists them.
positionalsPositionalSpec[..]The positional arguments, in the order they are given.
commandsCommandSpec[..]The subcommands, in the order the help text lists them.

Methods

WithVersion

pub func WithVersion(
    self: &CommandSpec,
    version: char8[..]
) -> CommandSpec

This command with version, which --version then reports.

NameTypeDescription
versionchar8[..]the version text, such as 1.4.2

Returns: the changed copy

Source

WithOptions

pub func WithOptions(
    self: &CommandSpec,
    options: OptionSpec[..]
) -> CommandSpec

This command with options, which must outlive it.

NameTypeDescription
optionsOptionSpec[..]the options, in the order the help text lists them

Returns: the changed copy

Source

WithPositionals

pub func WithPositionals(
    self: &CommandSpec,
    positionals: PositionalSpec[..]
) -> CommandSpec

This command with positionals, which must outlive it.

NameTypeDescription
positionalsPositionalSpec[..]the positional arguments, in the order they are given

Returns: the changed copy

Source

WithCommands

pub func WithCommands(
    self: &CommandSpec,
    commands: CommandSpec[..]
) -> CommandSpec

This command with commands, which must outlive it.

NameTypeDescription
commandsCommandSpec[..]the subcommands, in the order the help text lists them

Returns: the changed copy

Source

Flag

pub func Flag(
    name: char8[..],
    short: char32,
    help: char8[..]
) -> OptionSpec

An option that is present or absent and takes no value, such as --verbose.

Source

Parameters

NameTypeDescription
namechar8[..]the long name without its dashes
shortchar32the short name, or '\0' for none
helpchar8[..]one line saying what the option does

Returns: the option's specification

ValueOption

pub func ValueOption(
    name: char8[..],
    short: char32,
    value: char8[..],
    help: char8[..]
) -> OptionSpec

An option that takes a value, such as --output FILE. The value may follow the option as the next argument, after = in the long form, or directly after the short letter, so --output a.txt, --output=a.txt, -o a.txt and -oa.txt all give a.txt.

Source

Parameters

NameTypeDescription
namechar8[..]the long name without its dashes
shortchar32the short name, or '\0' for none
valuechar8[..]what the help text calls the value, such as FILE; never empty
helpchar8[..]one line saying what the option does

Returns: the option's specification

Required

pub func Required(
    name: char8[..],
    help: char8[..]
) -> PositionalSpec

A positional argument that must be given.

Source

Parameters

NameTypeDescription
namechar8[..]the name queries and the help text use
helpchar8[..]one line saying what the argument is

Returns: the positional's specification

Optional

pub func Optional(
    name: char8[..],
    help: char8[..]
) -> PositionalSpec

A positional argument that may be left out.

Source

Parameters

NameTypeDescription
namechar8[..]the name queries and the help text use
helpchar8[..]one line saying what the argument is

Returns: the positional's specification

Remaining

pub func Remaining(
    name: char8[..],
    help: char8[..]
) -> PositionalSpec

A positional argument that takes every positional argument left, which may be none.

Source

Parameters

NameTypeDescription
namechar8[..]the name queries and the help text use
helpchar8[..]one line saying what the arguments are

Returns: the positional's specification

Command

pub func Command(
    name: char8[..],
    summary: char8[..]
) -> CommandSpec

A command with a name and a summary, and as yet no version, options, positionals or subcommands. The With methods fill in the rest, each returning the changed copy.

Source

Parameters

NameTypeDescription
namechar8[..]the program's name, or the word that selects a subcommand
summarychar8[..]one line saying what the command does

Returns: the command's specification