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