diff --git a/include/seastar/core/app-template.hh b/include/seastar/core/app-template.hh index 8c5a15c8c2..47aef9c0f4 100644 --- a/include/seastar/core/app-template.hh +++ b/include/seastar/core/app-template.hh @@ -129,6 +129,7 @@ private: std::shared_ptr _smp; seastar_options _opts; boost::program_options::options_description _app_opts; + boost::program_options::options_description* _app_visible_opts_for_help = nullptr; boost::program_options::options_description _seastar_opts; boost::program_options::options_description _opts_conf_file; boost::program_options::positional_options_description _pos_opts; @@ -136,6 +137,7 @@ private: configuration_reader _conf_reader; configuration_reader get_default_configuration_reader(); + void add_extra_options(boost::program_options::options_description& opts); public: struct positional_option { const char* name; @@ -153,6 +155,7 @@ public: boost::program_options::options_description& get_options_description(); boost::program_options::options_description& get_conf_file_options_description(); boost::program_options::options_description_easy_init add_options(); + void set_app_visible_options_for_help(boost::program_options::options_description* opts); void add_positional_options(std::initializer_list options); boost::program_options::variables_map& configuration(); int run_deprecated(int ac, char ** av, std::function&& func) noexcept; diff --git a/src/core/app-template.cc b/src/core/app-template.cc index af76bda372..5dcba0058b 100644 --- a/src/core/app-template.cc +++ b/src/core/app-template.cc @@ -85,16 +85,7 @@ app_template::app_template(app_template::seastar_options opts) if (!alien::internal::default_instance) { alien::internal::default_instance = _alien.get(); } - _app_opts.add_options() - ("help,h", "show help message") - ; - _app_opts.add_options() - ("help-seastar", "show help message about seastar options") - ; - _app_opts.add_options() - ("help-loggers", "print a list of logger names and exit") - ; - + add_extra_options(_app_opts); { program_options::options_description_building_visitor visitor; _opts.describe(visitor); @@ -109,12 +100,33 @@ app_template::app_template(app_template::config cfg) { } +void +app_template::add_extra_options(boost::program_options::options_description& opts) { + opts.add_options() + ("help,h", "show help message") + ; + opts.add_options() + ("help-seastar", "show help message about seastar options") + ; + opts.add_options() + ("help-loggers", "print a list of logger names and exit") + ; +} + app_template::~app_template() = default; const app_template::seastar_options& app_template::options() const { return _opts; } +void +app_template::set_app_visible_options_for_help(boost::program_options::options_description* opts) { + _app_visible_opts_for_help = opts; + if (_app_visible_opts_for_help) { + add_extra_options(*_app_visible_opts_for_help); + } +} + app_template::configuration_reader app_template::get_default_configuration_reader() { return [this] (bpo::variables_map& configuration) { auto home = std::getenv("HOME"); @@ -211,7 +223,8 @@ app_template::run_deprecated(int ac, char ** av, std::function&& func) if (!_opts.description.empty()) { std::cout << _opts.description << "\n"; } - std::cout << _app_opts << "\n"; + auto& which_opts = _app_visible_opts_for_help ? *_app_visible_opts_for_help : _app_opts; + std::cout << which_opts << "\n"; return 0; } if (configuration.count("help-seastar")) {