Commit 6de24d09 authored by Dominik Charousset's avatar Dominik Charousset

Allow to suppress help generation in extract_opts

parent 579b6fa2
......@@ -227,13 +227,16 @@ public:
/// }
/// ~~~
/// @param xs List of argument descriptors.
/// @param f Optional factory function to generate help text
/// (overrides the default generator).
/// @param help_generator Optional factory function to generate help text
/// (overrides the default generator).
/// @param suppress_help Suppress generation of default-generated help option.
/// @returns A struct containing remainder
/// (i.e. unmatched elements), a set containing the names of all
/// used arguments, and the generated help text.
/// @throws std::invalid_argument if no name or more than one long name is set
cli_res extract_opts(std::vector<cli_arg> xs, help_factory f = nullptr) const;
cli_res extract_opts(std::vector<cli_arg> xs,
help_factory help_generator = nullptr,
bool suppress_help = false) const;
/// Queries whether the element at position `p` is of type `T`.
template <class T>
......
......@@ -85,9 +85,9 @@ public:
/// @copydoc message::extract_opts
inline message::cli_res extract_opts(std::vector<message::cli_arg> xs,
message::help_factory f
= nullptr) const {
return to_message().extract_opts(std::move(xs), std::move(f));
message::help_factory f = nullptr,
bool no_help = false) const {
return to_message().extract_opts(std::move(xs), std::move(f), no_help);
}
/// @copydoc message::apply
......
......@@ -175,7 +175,7 @@ message message::extract(message_handler handler) const {
}
message::cli_res message::extract_opts(std::vector<cli_arg> xs,
help_factory f) const {
help_factory f, bool no_help) const {
std::string helpstr;
auto make_error = [&](std::string err) -> cli_res {
return {*this, std::set<std::string>{}, std::move(helpstr), std::move(err)};
......@@ -192,7 +192,7 @@ message::cli_res message::extract_opts(std::vector<cli_arg> xs,
return s[0] == "help"
|| std::find_if(s.begin() + 1, s.end(), has_short_help) != s.end();
};
if (std::none_of(xs.begin(), xs.end(), pred)) {
if (! no_help && std::none_of(xs.begin(), xs.end(), pred)) {
xs.push_back(cli_arg{"help,h,?", "print this text"});
}
std::map<std::string, cli_arg*> shorts;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment