argparse documentation Help

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.

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: 09 November 2024