From 594f2d6222b4111dfd4d46303fec185069a08963 Mon Sep 17 00:00:00 2001 From: Matt Witherspoon <32485495+spoonincode@users.noreply.github.com> Date: Thu, 20 Sep 2018 19:40:46 -0400 Subject: [PATCH] Error on missing plugin before unknown option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change appbase to error out when seeing an unknown plugin before erroring out on an unknown option. Otherwise it’s a little confusing that the reason the option isn’t recognized is because the plugin simply doesn’t even exist. To accomplish this, have to make two passes through config.ini. First pass just parses the plugin= statements and then makes sure those are all valid, second pass parses all options. Keep in mind this doesn’t change behavior where you can set a plugin option and not activate said plugin. For example I can still put bnet-threads in my config.ini but this will not be an error even I forgot to activate eosio::bnet_plugin --- application.cpp | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/application.cpp b/application.cpp index 852a055a5..e689a5075 100644 --- a/application.cpp +++ b/application.cpp @@ -18,10 +18,11 @@ using std::cout; class application_impl { public: - application_impl():_app_options("Application Options"){ + application_impl():_app_options("Application Options"), _app_cfg_opts("Application Config Options"){ } options_description _app_options; options_description _cfg_options; + options_description _app_cfg_opts; bfs::path _data_dir{"data-dir"}; bfs::path _config_dir{"config-dir"}; @@ -92,9 +93,8 @@ void application::set_program_options() my->_app_options.add(plugin_cli_opts); } - options_description app_cfg_opts( "Application Config Options" ); options_description app_cli_opts( "Application Command Line Options" ); - app_cfg_opts.add_options() + my->_app_cfg_opts.add_options() ("plugin", bpo::value< vector >()->composing(), "Plugin(s) to enable, may be specified multiple times"); app_cli_opts.add_options() @@ -106,8 +106,8 @@ void application::set_program_options() ("config,c", bpo::value()->default_value( "config.ini" ), "Configuration file name relative to config-dir") ("logconf,l", bpo::value()->default_value( "logging.json" ), "Logging configuration file name/path for library users"); - my->_cfg_options.add(app_cfg_opts); - my->_app_options.add(app_cfg_opts); + my->_cfg_options.add(my->_app_cfg_opts); + my->_app_options.add(my->_app_cfg_opts); my->_app_options.add(app_cli_opts); } @@ -172,20 +172,30 @@ bool application::initialize_impl(int argc, char** argv, vector f) { + if(options.count("plugin") > 0) { + auto plugins = options.at("plugin").as>(); + for(auto& arg : plugins) { + vector names; + boost::split(names, arg, boost::is_any_of(" \t,")); + for(const std::string& name : names) + f(get_plugin(name)); + } + } + }; + + bpo::store(bpo::parse_config_file(config_file_name.make_preferred().string().c_str(), + my->_app_cfg_opts, true), options); + + for_each_plugin([](auto& p){}); + bpo::store(bpo::parse_config_file(config_file_name.make_preferred().string().c_str(), my->_cfg_options, false), options); - if(options.count("plugin") > 0) - { - auto plugins = options.at("plugin").as>(); - for(auto& arg : plugins) - { - vector names; - boost::split(names, arg, boost::is_any_of(" \t,")); - for(const std::string& name : names) - get_plugin(name).initialize(options); - } - } + for_each_plugin([&](auto& p){ + p.initialize(options); + }); + try { for (auto plugin : autostart_plugins) if (plugin != nullptr && plugin->get_state() == abstract_plugin::registered)