ark::core::OptionRule

Defined in header “ark/core/argument_parser.hh”.


Represents an option rule. These are the rules that the command line options are parsed from, and are normally instantiated and managed by the ArgumentParser itself.

Methods

  • OptionRule(std::string name)
    Constructor. Initializes a new option rule with the given name.

  • ~OptionRule()
    Virtual destructor, for cleanup.

  • OptionRule & add_name(std::string name)
    Adds a new name to the list of supported names in this rule. This name can be a short name (single character), or a long name (full string). Short names are used with a single dash, long names with a double dash.

    In other words, ‘-o’ is a short name, ‘output’ is a long name.

  • OptionRule & requires_argument(std::string argument_type)
    Set if this option consumes a value or not. Options can consume either no values (the default), one value (if this parameter is given), or all values until the next option (if consume_arguments_until_next is provided).

  • OptionRule & consume_arguments_until_next_option()
    Set if this option consume arguments until the next option is encountered.

  • OptionRule & allow_multiple_uses()
    Set this if you want to allow this argument to be specified multiple times. Otherwise, the parser will throw an error if this is specified more than once.

  • OptionRule & required()
    Indicates this option is required to be specified.

  • OptionRule & help(std::string text)
    Sets help text for this item.

  • OptionRule & default_value(std::string value)
    Sets a default value. If this is set, and the option isn’t specified, the default value will be implied.

  • OptionRule & environment_variable(std::string name)
    Sets an environment variable to pull from. If the environment variable is set, and the option isn’t provided on the command line, the option will be “defaulted” to the environment variable.

  • bool has_name(const std::string_view & name)
    Returns true if this rule has the given name.

  • bool is_required()
    Returns true if this rule is required.

  • std::optional< std::string > default_value()
    Returns the default value of this option. This will either contain the environment variable contents if that is set and the variable exists, or the default value if that is set, or be an empty optional.