← index

[CLI]Spec

inherits Object · defined at core/14-cli.qn:44

The declarative spec. Builder methods return self, so a whole tool declares in one chain; parse / parseFrom: do the work.

var cli = [CLI]Spec.new:'greet' about:'says hello'
cli.flag:'shout' short:'s' help:'LOUDLY'
cli.positional:'name' help:'whom to greet'
var args = cli.parseFrom:#( '-s' 'quoin' )
#( (args.at:'name') (args.flag?:'shout') )    "* -> #(quoin true)

Class methods

new:String

A spec for the tool name (the usage line's first word).

core/14-cli.qn:47

new:String about:String

A spec with a one-line description for the help text.

core/14-cli.qn:50

Instance methods

applyDefaults:

Flags default false, options to their default; a missing required: option is a UsageError.

core/14-cli.qn:293

command: spec:

A subcommand: the block configures its own sub-spec (options, positionals, rest — not further commands). The first positional token picks the command; after it, option lookups try the sub-spec first, then this one.

core/14-cli.qn:146

command: spec: help:

See command:spec:.

core/14-cli.qn:148

findLong: sub:

core/14-cli.qn:309

findShort: sub:

core/14-cli.qn:317

flag:

A boolean flag: absent -> false, --name (or its short) -> true.

core/14-cli.qn:68

flag: help:

See flag:.

core/14-cli.qn:70

flag: short: help:

See flag:.

core/14-cli.qn:72

helpText

The generated help: a usage line, the about text, and aligned tables of commands, options, and positionals (from their help: strings). What -h/--help prints.

core/14-cli.qn:344

init

Internal: the collections default empty (new:{} populated the scalars).

core/14-cli.qn:59

knownNames

Every name at: may read on a result from this spec.

core/14-cli.qn:331

longOpt:

core/14-cli.qn:325

option:

An option taking a value: --name value or --name=value. Absent -> its default: (nil without one), unless required:true.

core/14-cli.qn:79

option: default: help:

See option:.

core/14-cli.qn:89

option: help:

See option:.

core/14-cli.qn:81

option: required: help:

An option that must be given (absence is a UsageError).

core/14-cli.qn:102

option: short: default: help:

See option:.

core/14-cli.qn:93

option: short: default: required: values: help:

The kitchen sink — every option property, nil where unused.

core/14-cli.qn:114

option: short: help:

See option:.

core/14-cli.qn:85

option: short: required: help:

See option:required:help:.

core/14-cli.qn:106

option: short: values: help:

See option:values:help:.

core/14-cli.qn:110

option: values: help:

An option whose value must be one of values: (anything else is a UsageError naming the choices).

core/14-cli.qn:98

parse

Parse Runtime.arguments — the production entry: -h/--help prints the help and exits 0; misuse prints the message + usage to stderr and exits 2.

core/14-cli.qn:162

parseFrom:

Parse an explicit token List, throwing UsageError on misuse — the testable seam. -h/--help short-circuits: the result answers help? and nothing else is validated.

core/14-cli.qn:181

positional:

A required positional argument (assigned in declaration order).

core/14-cli.qn:123

positional: help:

See positional:.

core/14-cli.qn:125

positionals

core/14-cli.qn:327

rest:

The trailing splat: every positional after the declared ones, as a List (possibly empty). Without one, extras are a UsageError.

core/14-cli.qn:135

restName

core/14-cli.qn:328

shortOpt:

core/14-cli.qn:326

take: inline: from: at: into:

Record one option token; answers the index after any consumed value.

core/14-cli.qn:266