25#ifndef HARNESS_ARG_HANDLER_INCLUDED
26#define HARNESS_ARG_HANDLER_INCLUDED
34#include "harness_export.h"
55 using ActionFunc = std::function<void(
const std::string &)>;
149 bool ignore_unknown_arguments_ =
false)
150 : allow_rest_arguments(allow_rest_arguments_),
151 ignore_unknown_arguments(ignore_unknown_arguments_) {}
223 void add_option(
const CmdOption &other)
noexcept;
244 void process(
const std::vector<std::string> &arguments);
283 bool is_valid_option_name(
const std::string &
name)
const noexcept;
297 OptionContainer::const_iterator find_option(
298 const std::string &
name)
const noexcept;
301 std::function<std::pair<bool, CmdOption>(
const CmdOption &)>;
329 const std::string &rest_metavar,
330 size_t width)
const noexcept {
331 return usage_lines_if(
332 prefix, rest_metavar, width,
333 [](
const CmdOption &opt) -> std::pair<bool, CmdOption> {
338 std::vector<std::string> usage_lines_if(
339 const std::string &prefix,
const std::string &rest_metavar,
size_t width,
340 UsagePredicate predicate)
const noexcept;
367 std::vector<std::string> option_descriptions(
368 const size_t width,
const size_t indent)
const noexcept;
376 OptionContainer::const_iterator
begin() {
return options_.begin(); }
384 OptionContainer::const_iterator
end() {
return options_.end(); }
413 return rest_arguments_;
426 std::map<std::string, std::string>>;
428 return config_overwrites_;
std::vector< CmdOption > OptionContainer
Definition of a vector holding unique pointers to CmdOption objects.
Definition: arg_handler.h:83
CmdOptionValueReq
Definition: arg_handler.h:43
Handles command line arguments.
Definition: arg_handler.h:140
ConfigOverwrites config_overwrites_
Keeps configuration options overwrites.
Definition: arg_handler.h:437
std::vector< std::string > rest_arguments_
Vector with arguments as strings not processed as options.
Definition: arg_handler.h:435
const std::vector< std::string > & get_rest_arguments() const noexcept
Returns the rest arguments.
Definition: arg_handler.h:412
std::map< std::pair< std::string, std::string >, std::map< std::string, std::string > > ConfigOverwrites
The key is a section identificator (section name and optional section key), the value is a map of all...
Definition: arg_handler.h:426
std::vector< CmdOption > options_
Vector with registered options.
Definition: arg_handler.h:433
void clear_options()
Clears registered options.
Definition: arg_handler.h:391
const ConfigOverwrites & get_config_overwrites() const noexcept
Definition: arg_handler.h:427
OptionContainer::const_iterator begin()
Returns an iterator to first option.
Definition: arg_handler.h:376
bool allow_rest_arguments
Whether to allow rest arguments or not.
Definition: arg_handler.h:417
CmdArgHandler(bool allow_rest_arguments_, bool ignore_unknown_arguments_=false)
Constructor.
Definition: arg_handler.h:148
OptionContainer::const_iterator end()
Returns an iterator to end of the option container.
Definition: arg_handler.h:384
const std::vector< CmdOption > & get_options() const noexcept
Gets all registered options.
Definition: arg_handler.h:399
bool ignore_unknown_arguments
Whether to ignore unknown arguments.
Definition: arg_handler.h:420
std::vector< std::string > usage_lines(const std::string &prefix, const std::string &rest_metavar, size_t width) const noexcept
Produces lines of text suitable to show usage.
Definition: arg_handler.h:328
CmdArgHandler()
Default constructor.
Definition: arg_handler.h:158
std::function< std::pair< bool, CmdOption >(const CmdOption &)> UsagePredicate
Definition: arg_handler.h:301
repeated Action action
Definition: replication_group_member_actions.proto:42
case opt name
Definition: sslopt-case.h:32
CmdOption stores information about command line options.
Definition: arg_handler.h:54
std::function< void(const std::string &)> AtEndActionFunc
Definition: arg_handler.h:56
std::string metavar
Definition: arg_handler.h:63
CmdOptionValueReq value_req
Definition: arg_handler.h:61
CmdOption(OptionNames names_, std::string description_, CmdOptionValueReq value_req_, const std::string metavar_, ActionFunc action_, AtEndActionFunc at_end_action_=[](const std::string &) {})
Definition: arg_handler.h:68
std::function< void(const std::string &)> ActionFunc
Definition: arg_handler.h:55
std::string description
Definition: arg_handler.h:60
std::string value
Definition: arg_handler.h:62
bool required
Definition: arg_handler.h:66
OptionNames names
Definition: arg_handler.h:59
ActionFunc action
Definition: arg_handler.h:64
std::vector< std::string > OptionNames
Definition: arg_handler.h:57
AtEndActionFunc at_end_action
Definition: arg_handler.h:65