Unverified Commit 23cb4188 authored by Dominik Charousset's avatar Dominik Charousset Committed by GitHub

Merge pull request #1442

Only exclude CAF options from --help output
parents 7d2cbd0e a5cc03ee
...@@ -6,6 +6,13 @@ is based on [Keep a Changelog](https://keepachangelog.com). ...@@ -6,6 +6,13 @@ is based on [Keep a Changelog](https://keepachangelog.com).
## [Unreleased] ## [Unreleased]
### Changed
- When using CAF to parse CLI arguments, the output of `--help` now includes all
user-defined options. Previously, only options in the global category or
options with a short name were included. Only CAF options are now excluded
from the output. They will still be included in the output of `--long-help`.
### Fixed ### Fixed
- Fix build errors with exceptions disabled. - Fix build errors with exceptions disabled.
......
...@@ -158,7 +158,7 @@ public: ...@@ -158,7 +158,7 @@ public:
config_option_set& add(config_option opt); config_option_set& add(config_option opt);
/// Generates human-readable help text for all options. /// Generates human-readable help text for all options.
std::string help_text(bool global_only = true) const; std::string help_text(bool hide_caf_options = true) const;
/// Drops all options. /// Drops all options.
void clear() { void clear() {
......
...@@ -47,7 +47,8 @@ actor_system_config::actor_system_config() ...@@ -47,7 +47,8 @@ actor_system_config::actor_system_config()
using string_list = std::vector<string>; using string_list = std::vector<string>;
opt_group{custom_options_, "global"} opt_group{custom_options_, "global"}
.add<bool>("help,h?", "print help text to STDERR and exit") .add<bool>("help,h?", "print help text to STDERR and exit")
.add<bool>("long-help", "print long help text to STDERR and exit") .add<bool>("long-help",
"same as --help but list options that are omitted by default")
.add<bool>("dump-config", "print configuration to STDERR and exit") .add<bool>("dump-config", "print configuration to STDERR and exit")
.add<string>("config-file", "sets a path to a configuration file"); .add<string>("config-file", "sets a path to a configuration file");
opt_group{custom_options_, "caf.scheduler"} opt_group{custom_options_, "caf.scheduler"}
......
...@@ -43,7 +43,7 @@ config_option_set& config_option_set::add(config_option opt) { ...@@ -43,7 +43,7 @@ config_option_set& config_option_set::add(config_option opt) {
return *this; return *this;
} }
std::string config_option_set::help_text(bool global_only) const { std::string config_option_set::help_text(bool hide_caf_options) const {
// <--- argument --------> <---- description ---> // <--- argument --------> <---- description --->
// (-w|--write) <string> : output file // (-w|--write) <string> : output file
auto build_argument = [](const config_option& x) { auto build_argument = [](const config_option& x) {
...@@ -68,6 +68,10 @@ std::string config_option_set::help_text(bool global_only) const { ...@@ -68,6 +68,10 @@ std::string config_option_set::help_text(bool global_only) const {
sb << "<" << x.type_name() << '>'; sb << "<" << x.type_name() << '>';
return std::move(sb.result); return std::move(sb.result);
}; };
// Utility function for checking whether a category is a CAF option.
auto is_caf_option = [](std::string_view category) {
return category == "caf" || starts_with(category, "caf.");
};
// Sort argument + description by category. // Sort argument + description by category.
using pair = std::pair<std::string, option_pointer>; using pair = std::pair<std::string, option_pointer>;
std::set<std::string_view> categories; std::set<std::string_view> categories;
...@@ -75,12 +79,12 @@ std::string config_option_set::help_text(bool global_only) const { ...@@ -75,12 +79,12 @@ std::string config_option_set::help_text(bool global_only) const {
size_t max_arg_size = 0; size_t max_arg_size = 0;
for (auto& opt : opts_) { for (auto& opt : opts_) {
// We treat all options with flat name as-if the category was 'global'. // We treat all options with flat name as-if the category was 'global'.
if (!global_only || opt.has_flat_cli_name()) {
auto arg = build_argument(opt); auto arg = build_argument(opt);
max_arg_size = std::max(max_arg_size, arg.size());
std::string_view category = "global"; std::string_view category = "global";
if (!opt.has_flat_cli_name()) if (!opt.has_flat_cli_name())
category = opt.category(); category = opt.category();
if (!hide_caf_options || !is_caf_option(category)) {
max_arg_size = std::max(max_arg_size, arg.size());
categories.emplace(category); categories.emplace(category);
args.emplace(category, std::make_pair(std::move(arg), &opt)); args.emplace(category, std::make_pair(std::move(arg), &opt));
} }
......
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