Optional and required arguments
Arguments can be marked as required or optional by adding .Required or .Optional to UDA. If required argument is not present in command line, argparse will error out. All missed required arguments are reported at once, together with their description:
Error: The following arguments are required:
--input INPUT File to read the data from
destination Where to upload the result
By default, positional arguments are required and named arguments are optional.
Example:
import argparse;
struct T
{
@(PositionalArgument(0, "a").Optional)
string a = "not set";
@(NamedArgument.Required)
int b;
}
T t;
assert(CLI!T.parseArgs(t, ["-b", "4"]));
assert(t == T("not set", 4));
Last modified: 11 September 2026