Args module

parse

procedureextensionSource

Parses the process's arguments. --help and --version print and exit 0; a bad command line prints the error with a usage hint to stderr and exits 2.

Example↗
Args :: #import "Extensions/Args";

Cli :: struct { name: string = "world"; @short=n }
HELP :: Args.Help(Cli).{ about = "Greets.", name = "Who to greet" };

cli, set := Args.parse(Cli, HELP);
print("hello, %\n", cli.name);

This one is only checked to compile, not run.

parse :: ($T: Type, $help: Help(T)) -> (T, Is_Set(T))

Parses the process's arguments. --help and --version print and exit 0; a bad command line prints the error with a usage hint to stderr and exits 2.

Parameters

$T: Type
the struct whose fields are the options.
$help: Help(T)
the help strings for T.

Returns

T
Example↗
Args :: #import "Extensions/Args";

Cli :: struct { name: string = "world"; @short=n }
HELP :: Args.Help(Cli).{ about = "Greets.", name = "Who to greet" };

cli, set := Args.parse(Cli, HELP);
print("hello, %\n", cli.name);

This one is only checked to compile, not run.

See also