Struct Option

Struct Documentation

struct Option

Specifies a command-line option’s parameters.

Todo:

  • Allow positional arguments

  • Allow nargs to be “arbitrary”

Note

An open struct is used for this to enable keyword construction (e.g., Option opt{.name = {"--arg", "-a"}, .help = "Option description"}; ). See CliArgs.

Public Members

std::array<std::string, 2> name

Key(s) by which to refer to this Option.

This is the only field that must be explicitly initialized. It expects 1 or 2 elements. The first element must exist and must be the long-hand form, --name (must have exactly two hyphens). The second element is optional but must be the short-hand form, -n (that is, only one -).

std::string help = {}

Help description to be printed on request. Can be multiple lines.

bool required = {false}

Arguments are optional be default. This makes an argument required.

ArgType type = {ArgType::Unspecified}

The expected type to which a value should parse.

bool flag = {false}

This indicates that the option is a flag, and not followed by a value.

Flag options are automatically configured to be false by default and flip to true if parsed.

std::size_t nargs = {1}

The number of values that can be provided with an option.

ArgVector defaults = {}

Default value(s)