std.cli
flags, options, positionals and help text from one command description
CliError
Section titled “CliError”pub CliError :: errors { unknown_option, missing_value, unexpected_value, missing_argument, too_many_arguments, invalid_number,}unknown_option: an option the command does not havemissing_value: an option that takes a value, at the endunexpected_value: a value given to a flag (--verbose=yes)missing_argument: too few positional argumentstoo_many_arguments: more than it takesinvalid_number:int_optionof a value that is no integer
Command
Section titled “Command”pub Command :: struct { region: *Arena, name: []const u8, about: []const u8, specs: Vec(Spec), places: Vec(PosSpec), message: []const u8,}Command.flag
Section titled “Command.flag”pub flag :: fn(self: *Self, long: []const u8, short: u8, about: []const u8)short 0 = none
Command.option
Section titled “Command.option”pub option :: fn(self: *Self, long: []const u8, short: u8, value_name: []const u8, about: []const u8)takes a value; short 0 = none; value_name shows in help (FILE, N)
Command.positional
Section titled “Command.positional”pub positional :: fn(self: *Self, name: []const u8, about: []const u8)required; positionals match in declaration order
Command.optional
Section titled “Command.optional”pub optional :: fn(self: *Self, name: []const u8, about: []const u8)may be omitted; goes after the required ones
Command.rest
Section titled “Command.rest”pub rest :: fn(self: *Self, name: []const u8, about: []const u8)any number after the others (files…)
Command.parse
Section titled “Command.parse”pub parse :: fn(self: *Self, args: []const []const u8) -> Parsed ! CliErrorskips args[0]; –x V, –x=V, -o V, -oV, -vq; -- ends options; -h skips checks
Command.help
Section titled “Command.help”pub help :: fn(self: *Self, a: *Arena) -> []const u8usage and options text, in a
Parsed
Section titled “Parsed”pub Parsed :: struct { given: Vec(Given), positionals: Vec([]const u8), help: bool,}Parsed.flag
Section titled “Parsed.flag”pub flag :: fn(self: *Self, long: []const u8) -> boolflag or option given at all
Parsed.count
Section titled “Parsed.count”pub count :: fn(self: *Self, long: []const u8) -> usizetimes given (-vvv is 3)
Parsed.option
Section titled “Parsed.option”pub option :: fn(self: *Self, long: []const u8) -> ?[]const u8last value if repeated; null if not given
Parsed.all
Section titled “Parsed.all”pub all :: fn(self: *Self, a: *Arena, long: []const u8) -> []const []const u8all values in order (-I a -I b), in a
Parsed.int_option
Section titled “Parsed.int_option”pub int_option :: fn(self: *Self, long: []const u8) -> ?i64 ! CliErrornull if not given; .invalid_number if not an integer
Parsed.positional
Section titled “Parsed.positional”pub positional :: fn(self: *Self, i: usize) -> ?[]const u8Parsed.positionals_all
Section titled “Parsed.positionals_all”pub positionals_all :: fn(self: *Self) -> []const []const u8command
Section titled “command”pub command :: fn(a: *Arena, name: []const u8, about: []const u8) -> Commandname as help shows it; everything lives in a