From 867f02f96a1423cd3a33362323269bec1cb35a95 Mon Sep 17 00:00:00 2001 From: P-A Loizeau <p.-a.loizeau@gsi.de> Date: Wed, 4 Oct 2023 12:19:43 +0200 Subject: [PATCH] Improve handling of required options in histserv_nofairmq + cleanup --- services/histserv/app/ProgramOptions.cxx | 31 ++++++++++-------------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/services/histserv/app/ProgramOptions.cxx b/services/histserv/app/ProgramOptions.cxx index cfe378e94a..e8b4e545ec 100644 --- a/services/histserv/app/ProgramOptions.cxx +++ b/services/histserv/app/ProgramOptions.cxx @@ -22,38 +22,34 @@ namespace cbm::services::histserv { // --- Define generic options - po::options_description generic("Generic options"); + po::options_description generic(" Generic options"); auto generic_add = generic.add_options(); generic_add("help,h", "display this help and exit"); - // --- Build default config file path - //string defconfig = std::getenv("VMCWORKDIR"); - //defconfig.append("/"); - //defconfig.append(DEFAULT_CONFIG); + // --- Define configuration options: Mandatory + po::options_description config_req(" Configuration (required)"); + auto config_req_add = config_req.add_options(); + config_req_add("input,i", po::value<string>(&fsChanHistosIn)->required()->value_name("<protocol://xxxxxx>"), + "name or host:port or whatever is needed for input channel (histos/canvases config and data), " + "cf http://api.zeromq.org/2-1:zmq-bind"); - // --- Define configuration options - po::options_description config("Configuration"); + // --- Define configuration options: Optional + po::options_description config(" Configuration (optional or with default)"); auto config_add = config.add_options(); - config_add("input,i", po::value<string>(&fsChanHistosIn)->value_name("<protocol://xxxxxx>"), - "name or host:port or whatever is needed for input channel (histos/canvases config and data), " - " cf http://api.zeromq.org/2-1:zmq-bind"); config_add("port,p", po::value<uint32_t>(&fuHttpServerPort)->default_value(8080), - "port on which the http ROOT server (JSroot) will be available"); + "port on which the http ROOT server (JSroot) will be available (mind default value!)"); config_add("output,o", po::value<string>(&fsHistoFileName)->value_name("<file name>"), "name of the output ROOT file with histograms backup"); - // config_add("config,c", po::value<string>(&fConfig)->value_name("<file name>")->default_value(defconfig), - // "name of a YAML file describing the configuration of reconstruction"); config_add("overwrite,w", po::bool_switch(&fOverwrite)->default_value(false), "allow to overwite an existing output file"); // --- Allowed options po::options_description cmdline_options("Allowed options"); - cmdline_options.add(generic).add(config); + cmdline_options.add(generic).add(config_req).add(config); // --- Parse command line po::variables_map vars; po::store(po::parse_command_line(argc, argv, cmdline_options), vars); - po::notify(vars); // --- Help: print help information and exit program if (vars.count("help") != 0u) { @@ -61,9 +57,8 @@ namespace cbm::services::histserv exit(EXIT_SUCCESS); } - // --- Catch mandatory parameters not being specified - if (vars.count("input") == 0u) { throw std::runtime_error("no input channel specified"); } - if (vars.count("port") == 0u) { throw std::runtime_error("no http port specified"); } + // --- Run notify after processing the help to avoid it being blocked by missing arguments + po::notify(vars); } // -------------------------------------------------------------------------- -- GitLab