26#ifndef HARNESS_ARG_HANDLER_INCLUDED
27#define HARNESS_ARG_HANDLER_INCLUDED
35#include "harness_export.h"
56 using ActionFunc = std::function<void(
const std::string &)>;
150 bool ignore_unknown_arguments_ =
false)
151 : allow_rest_arguments(allow_rest_arguments_),
152 ignore_unknown_arguments(ignore_unknown_arguments_) {}
224 void add_option(
const CmdOption &other)
noexcept;
245 void process(
const std::vector<std::string> &arguments);
284 bool is_valid_option_name(
const std::string &
name)
const noexcept;
298 OptionContainer::const_iterator find_option(
299 const std::string &
name)
const noexcept;
302 std::function<std::pair<bool, CmdOption>(
const CmdOption &)>;
330 const std::string &rest_metavar,
331 size_t width)
const noexcept {
332 return usage_lines_if(
333 prefix, rest_metavar, width,
334 [](
const CmdOption &opt) -> std::pair<bool, CmdOption> {
339 std::vector<std::string> usage_lines_if(
340 const std::string &prefix,
const std::string &rest_metavar,
size_t width,
341 UsagePredicate predicate)
const noexcept;
368 std::vector<std::string> option_descriptions(
369 const size_t width,
const size_t indent)
const noexcept;
377 OptionContainer::const_iterator
begin() {
return options_.begin(); }
385 OptionContainer::const_iterator
end() {
return options_.end(); }
414 return rest_arguments_;
427 std::map<std::string, std::string>>;
429 return config_overwrites_;
std::vector< CmdOption > OptionContainer
Definition of a vector holding unique pointers to CmdOption objects.
Definition: arg_handler.h:84
CmdOptionValueReq
Definition: arg_handler.h:44
Handles command line arguments.
Definition: arg_handler.h:141
ConfigOverwrites config_overwrites_
Keeps configuration options overwrites.
Definition: arg_handler.h:438
std::vector< std::string > rest_arguments_
Vector with arguments as strings not processed as options.
Definition: arg_handler.h:436
const std::vector< std::string > & get_rest_arguments() const noexcept
Returns the rest arguments.
Definition: arg_handler.h:413
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:427
std::vector< CmdOption > options_
Vector with registered options.
Definition: arg_handler.h:434
void clear_options()
Clears registered options.
Definition: arg_handler.h:392
const ConfigOverwrites & get_config_overwrites() const noexcept
Definition: arg_handler.h:428
OptionContainer::const_iterator begin()
Returns an iterator to first option.
Definition: arg_handler.h:377
bool allow_rest_arguments
Whether to allow rest arguments or not.
Definition: arg_handler.h:418
CmdArgHandler(bool allow_rest_arguments_, bool ignore_unknown_arguments_=false)
Constructor.
Definition: arg_handler.h:149
OptionContainer::const_iterator end()
Returns an iterator to end of the option container.
Definition: arg_handler.h:385
const std::vector< CmdOption > & get_options() const noexcept
Gets all registered options.
Definition: arg_handler.h:400
bool ignore_unknown_arguments
Whether to ignore unknown arguments.
Definition: arg_handler.h:421
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:329
CmdArgHandler()
Default constructor.
Definition: arg_handler.h:159
std::function< std::pair< bool, CmdOption >(const CmdOption &)> UsagePredicate
Definition: arg_handler.h:302
repeated Action action
Definition: replication_group_member_actions.proto:43
case opt name
Definition: sslopt-case.h:29
CmdOption stores information about command line options.
Definition: arg_handler.h:55
std::function< void(const std::string &)> AtEndActionFunc
Definition: arg_handler.h:57
std::string metavar
Definition: arg_handler.h:64
CmdOptionValueReq value_req
Definition: arg_handler.h:62
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:69
std::function< void(const std::string &)> ActionFunc
Definition: arg_handler.h:56
std::string description
Definition: arg_handler.h:61
std::string value
Definition: arg_handler.h:63
bool required
Definition: arg_handler.h:67
OptionNames names
Definition: arg_handler.h:60
ActionFunc action
Definition: arg_handler.h:65
std::vector< std::string > OptionNames
Definition: arg_handler.h:58
AtEndActionFunc at_end_action
Definition: arg_handler.h:66