ark::core::ArgumentParser
Defined in header “ark/core/argument_parser.hh”.
An argument parser is a class that can consume command line arguments (typically from an int main()) routine, and parse them into a list of configuration options.
This generally follows the GNU-style rules, with short and long options, and a double dash to terminate argument parsing.
Methods
-
ArgumentParser()
Constructor. Initializes a default argument parser. -
std::string help()
Returns help text for this parser. This lists all of the options/positionals, along with any other descriptive text that is present. -
void set_description(std::string text)
Sets the overall description of this tool. This is just helpful text that is printed to the user if they ask for help. -
void set_exit_on_error(bool enabled)
Set this to enable or disable automatic output when there is an error processing arguments. If this is an error, the errors will be printed out, and then the help() text, and then std::exit() will be invoked. -
ArgumentParserOptionGroup & add_option_group(std::string name)
Adds a new option group this is a grouping of options that makes it easier for users to parse the list of command line options.Otherwise, it has no effect on rules you cannot have duplicate names between groups. The returned reference from this routine is only valid until you call add_option_group again.
-
OptionRule & add_option(std::string name)
Adds a new rule. The name is a single name, and can be a short name or a long name. All of these options are added to the “general” option group.Returns a reference to the rule, which you can use for further configuration.
-
PositionalRule & add_positional(std::string name)
Adds a new rule. This is a positional argument. These are consumed, in the order that you add them here, when someone specifies something that is not an option (ie, does not start with a dash). -
ArgumentParseResult parse(const std::vector< std::string > & arguments)
Parses the given command line arguments with this parser, returning a result structure containing the results of the parse. -
void require_mutually_exclusive_options(const std::vector< std::string > & options)
Register a mutually exclusive group of command line arguments. These options must have been added to either an option group, or this parser. At least one of these options must be provided. -
ArgumentParseResult parse(int argc, const char ** argv)
Parses the given command line arguments with this parser, returning a result structure containing the results of the parse.This is mostly a convenience API, it simply calls parse() with argc/argv values translated into a vector.