diff --git a/fairmq/options/FairMQProgOptions.cxx b/fairmq/options/FairMQProgOptions.cxx index eba64648..b7810f3e 100644 --- a/fairmq/options/FairMQProgOptions.cxx +++ b/fairmq/options/FairMQProgOptions.cxx @@ -68,6 +68,18 @@ void FairMQProgOptions::ParseAll(const int argc, char** argv, bool allowUnregist } } + if (fVarMap.count("print-options")) + { + PrintOptionsRaw(); + exit(EXIT_SUCCESS); + } + + if (fVarMap.count("id") == 0) + { + LOG(ERROR) << "Device id not provided, provide with --id"; + exit(EXIT_FAILURE); + } + string verbosity = GetValue("verbosity"); string logFile = GetValue("log-to-file"); bool color = GetValue("log-color"); @@ -183,7 +195,6 @@ void FairMQProgOptions::ParseAll(const int argc, char** argv, bool allowUnregist LOG(DEBUG) << "channel-config: Parsing channel configuration"; UserParser(fVarMap, id); } - } FairProgOptions::PrintOptions(); @@ -312,7 +323,7 @@ void FairMQProgOptions::InitOptionDescription() ; fMQOptionsInCfg.add_options() - ("id", po::value()->required(), "Device ID (required argument).") + ("id", po::value(), "Device ID (required argument).") ("io-threads", po::value()->default_value(1), "Number of I/O threads.") ("transport", po::value()->default_value("zeromq"), "Transport ('zeromq'/'nanomsg').") ("config", po::value()->default_value("static"), "Config source ('static'/).") @@ -331,7 +342,7 @@ void FairMQProgOptions::InitOptionDescription() else { fMQOptionsInCmd.add_options() - ("id", po::value()->required(), "Device ID (required argument)") + ("id", po::value(), "Device ID (required argument)") ("io-threads", po::value()->default_value(1), "Number of I/O threads") ("transport", po::value()->default_value("zeromq"), "Transport ('zeromq'/'nanomsg').") ("config", po::value()->default_value("static"), "Config source ('static'/).") diff --git a/fairmq/options/FairProgOptions.cxx b/fairmq/options/FairProgOptions.cxx index d7beb432..c88f0778 100644 --- a/fairmq/options/FairProgOptions.cxx +++ b/fairmq/options/FairProgOptions.cxx @@ -37,27 +37,18 @@ FairProgOptions::FairProgOptions() : fGenericDesc.add_options() ("help,h", "produce help") ("version,v", "print version") - ("verbosity", po::value(&fVerbosityLevel)->default_value("DEBUG"), "Verbosity level : \n" - " TRACE \n" - " DEBUG \n" - " RESULTS \n" - " INFO \n" - " WARN \n" - " ERROR \n" - " STATE \n" - " NOLOG" - ) + ("verbosity", po::value(&fVerbosityLevel)->default_value("DEBUG"), "Verbosity level : TRACE, DEBUG, RESULTS, INFO, WARN, ERROR, STATE, NOLOG") ("log-color", po::value()->default_value(true), "logger color: true or false") - ; + ("print-options", po::value()->implicit_value(true), "print options in machine-readable format"); - fSeverityMap["TRACE"] = FairMQ::severity_level::TRACE; - fSeverityMap["DEBUG"] = FairMQ::severity_level::DEBUG; - fSeverityMap["RESULTS"] = FairMQ::severity_level::RESULTS; - fSeverityMap["INFO"] = FairMQ::severity_level::INFO; - fSeverityMap["WARN"] = FairMQ::severity_level::WARN; - fSeverityMap["ERROR"] = FairMQ::severity_level::ERROR; - fSeverityMap["STATE"] = FairMQ::severity_level::STATE; - fSeverityMap["NOLOG"] = FairMQ::severity_level::NOLOG; + fSeverityMap["TRACE"] = FairMQ::severity_level::TRACE; + fSeverityMap["DEBUG"] = FairMQ::severity_level::DEBUG; + fSeverityMap["RESULTS"] = FairMQ::severity_level::RESULTS; + fSeverityMap["INFO"] = FairMQ::severity_level::INFO; + fSeverityMap["WARN"] = FairMQ::severity_level::WARN; + fSeverityMap["ERROR"] = FairMQ::severity_level::ERROR; + fSeverityMap["STATE"] = FairMQ::severity_level::STATE; + fSeverityMap["NOLOG"] = FairMQ::severity_level::NOLOG; } /// Destructor @@ -241,6 +232,31 @@ int FairProgOptions::PrintHelp() const return 0; } +int FairProgOptions::PrintOptionsRaw() +{ + MapVarValInfo_t mapInfo; + + for (const auto& m : fVarMap) + { + mapInfo[m.first] = GetVariableValueInfo(m.second); + } + + for (const auto& p : mapInfo) + { + string keyStr; + string valueStr; + string typeInfoStr; + string defaultStr; + string emptyStr; + keyStr = p.first; + tie(valueStr, typeInfoStr, defaultStr, emptyStr) = p.second; + auto option = fCmdLineOptions.find_nothrow(keyStr, false); + cout << keyStr << ":" << valueStr << ":" << typeInfoStr << ":" << (option ? option->description() : "") << endl; + } + + return 0; +} + int FairProgOptions::PrintOptions() { // ////////////////////////////////// diff --git a/fairmq/options/FairProgOptions.h b/fairmq/options/FairProgOptions.h index 37c45a52..21c6d125 100644 --- a/fairmq/options/FairProgOptions.h +++ b/fairmq/options/FairProgOptions.h @@ -135,6 +135,7 @@ class FairProgOptions virtual void ParseAll(const int argc, char** argv, bool allowUnregistered = false) = 0;// TODO change return type to bool and propagate to executable virtual int PrintOptions(); + virtual int PrintOptionsRaw(); int PrintHelp() const; protected: @@ -176,7 +177,7 @@ class FairProgOptions private: // Methods below are helper functions used in the PrintOptions method - typedef std::tuple VarValInfo_t; + typedef std::tuple VarValInfo_t; typedef std::map MapVarValInfo_t; VarValInfo_t GetVariableValueInfo(const po::variable_value& varValue); diff --git a/fairmq/options/FairProgOptionsHelper.h b/fairmq/options/FairProgOptionsHelper.h index 1576515d..7ef2f417 100644 --- a/fairmq/options/FairProgOptionsHelper.h +++ b/fairmq/options/FairProgOptionsHelper.h @@ -155,72 +155,76 @@ struct ConvertVariableValue : T //////////////////////////////// std types // std::string albeit useless here if (is_this_type(varValue)) - return T::template Value(varValue, std::string(" "), defaultedValue, emptyValue); + return T::template Value(varValue, std::string(""), defaultedValue, emptyValue); // std::vector if (is_this_type>(varValue)) - return T::template Value>(varValue, std::string(" >"), defaultedValue, emptyValue); + return T::template Value>(varValue, std::string(">"), defaultedValue, emptyValue); // int if (is_this_type(varValue)) - return T::template Value(varValue, std::string(" "), defaultedValue, emptyValue); + return T::template Value(varValue, std::string(""), defaultedValue, emptyValue); // std::vector if (is_this_type>(varValue)) - return T::template Value>(varValue, std::string(" >"), defaultedValue, emptyValue); + return T::template Value>(varValue, std::string(">"), defaultedValue, emptyValue); // float if (is_this_type(varValue)) - return T::template Value(varValue, std::string(" "), defaultedValue, emptyValue); + return T::template Value(varValue, std::string(""), defaultedValue, emptyValue); // std::vector float if (is_this_type>(varValue)) - return T::template Value>(varValue, std::string(" >"), defaultedValue, emptyValue); + return T::template Value>(varValue, std::string(">"), defaultedValue, emptyValue); // double if (is_this_type(varValue)) - return T::template Value(varValue, std::string(" "), defaultedValue, emptyValue); + return T::template Value(varValue, std::string(""), defaultedValue, emptyValue); // std::vector double if (is_this_type>(varValue)) - return T::template Value>(varValue, std::string(" >"), defaultedValue, emptyValue); + return T::template Value>(varValue, std::string(">"), defaultedValue, emptyValue); // short if (is_this_type(varValue)) - return T::template Value(varValue, std::string(" "), defaultedValue, emptyValue); + return T::template Value(varValue, std::string(""), defaultedValue, emptyValue); // std::vector short if (is_this_type>(varValue)) - return T::template Value>(varValue, std::string(" >"), defaultedValue, emptyValue); + return T::template Value>(varValue, std::string(">"), defaultedValue, emptyValue); // long if (is_this_type(varValue)) - return T::template Value(varValue, std::string(" "), defaultedValue, emptyValue); + return T::template Value(varValue, std::string(""), defaultedValue, emptyValue); // std::vector short if (is_this_type>(varValue)) - return T::template Value>(varValue, std::string(" >"), defaultedValue, emptyValue); + return T::template Value>(varValue, std::string(">"), defaultedValue, emptyValue); // size_t if (is_this_type(varValue)) - return T::template Value(varValue, std::string(" "), defaultedValue, emptyValue); + return T::template Value(varValue, std::string(""), defaultedValue, emptyValue); + + // uint64_t + if (is_this_type(varValue)) + return T::template Value(varValue, std::string(""), defaultedValue, emptyValue); // std::vector size_t if (is_this_type>(varValue)) - return T::template Value>(varValue, std::string(" >"), defaultedValue, emptyValue); + return T::template Value>(varValue, std::string(">"), defaultedValue, emptyValue); // bool if (is_this_type(varValue)) - return T::template Value(varValue, std::string(" "), defaultedValue, emptyValue); + return T::template Value(varValue, std::string(""), defaultedValue, emptyValue); // std::vector bool if (is_this_type>(varValue)) - return T::template Value>(varValue, std::string(" >"), defaultedValue, emptyValue); + return T::template Value>(varValue, std::string(">"), defaultedValue, emptyValue); //////////////////////////////// boost types // boost::filesystem::path if (is_this_type(varValue)) - return T::template Value(varValue, std::string(" "), defaultedValue, emptyValue); + return T::template Value(varValue, std::string(""), defaultedValue, emptyValue); // if we get here, the type is not supported return unknown info return T::DefaultValue(defaultedValue, emptyValue);