Commit a5cc03ee authored by Dominik Charousset's avatar Dominik Charousset

Only exclude CAF options from --help output

parent 7d2cbd0e
......@@ -6,6 +6,13 @@ is based on [Keep a Changelog](https://keepachangelog.com).
## [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
- Fix build errors with exceptions disabled.
......
......@@ -158,7 +158,7 @@ public:
config_option_set& add(config_option opt);
/// 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.
void clear() {
......
......@@ -47,7 +47,8 @@ actor_system_config::actor_system_config()
using string_list = std::vector<string>;
opt_group{custom_options_, "global"}
.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<string>("config-file", "sets a path to a configuration file");
opt_group{custom_options_, "caf.scheduler"}
......
......@@ -43,7 +43,7 @@ config_option_set& config_option_set::add(config_option opt) {
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 --->
// (-w|--write) <string> : output file
auto build_argument = [](const config_option& x) {
......@@ -68,6 +68,10 @@ std::string config_option_set::help_text(bool global_only) const {
sb << "<" << x.type_name() << '>';
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.
using pair = std::pair<std::string, option_pointer>;
std::set<std::string_view> categories;
......@@ -75,12 +79,12 @@ std::string config_option_set::help_text(bool global_only) const {
size_t max_arg_size = 0;
for (auto& opt : opts_) {
// 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);
max_arg_size = std::max(max_arg_size, arg.size());
std::string_view category = "global";
if (!opt.has_flat_cli_name())
category = opt.category();
if (!hide_caf_options || !is_caf_option(category)) {
max_arg_size = std::max(max_arg_size, arg.size());
categories.emplace(category);
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