mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-13 08:41:16 +00:00
add --print-options
to print available options in short format
This commit is contained in:
parent
cae3fd6aa3
commit
1d38a2350f
|
@ -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<string>("verbosity");
|
||||
string logFile = GetValue<string>("log-to-file");
|
||||
bool color = GetValue<bool>("log-color");
|
||||
|
@ -183,7 +195,6 @@ void FairMQProgOptions::ParseAll(const int argc, char** argv, bool allowUnregist
|
|||
LOG(DEBUG) << "channel-config: Parsing channel configuration";
|
||||
UserParser<FairMQParser::SUBOPT>(fVarMap, id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
FairProgOptions::PrintOptions();
|
||||
|
@ -312,7 +323,7 @@ void FairMQProgOptions::InitOptionDescription()
|
|||
;
|
||||
|
||||
fMQOptionsInCfg.add_options()
|
||||
("id", po::value<string>()->required(), "Device ID (required argument).")
|
||||
("id", po::value<string>(), "Device ID (required argument).")
|
||||
("io-threads", po::value<int >()->default_value(1), "Number of I/O threads.")
|
||||
("transport", po::value<string>()->default_value("zeromq"), "Transport ('zeromq'/'nanomsg').")
|
||||
("config", po::value<string>()->default_value("static"), "Config source ('static'/<config library filename>).")
|
||||
|
@ -331,7 +342,7 @@ void FairMQProgOptions::InitOptionDescription()
|
|||
else
|
||||
{
|
||||
fMQOptionsInCmd.add_options()
|
||||
("id", po::value<string>()->required(), "Device ID (required argument)")
|
||||
("id", po::value<string>(), "Device ID (required argument)")
|
||||
("io-threads", po::value<int >()->default_value(1), "Number of I/O threads")
|
||||
("transport", po::value<string>()->default_value("zeromq"), "Transport ('zeromq'/'nanomsg').")
|
||||
("config", po::value<string>()->default_value("static"), "Config source ('static'/<config library filename>).")
|
||||
|
|
|
@ -37,27 +37,18 @@ FairProgOptions::FairProgOptions() :
|
|||
fGenericDesc.add_options()
|
||||
("help,h", "produce help")
|
||||
("version,v", "print version")
|
||||
("verbosity", po::value<std::string>(&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<std::string>(&fVerbosityLevel)->default_value("DEBUG"), "Verbosity level : TRACE, DEBUG, RESULTS, INFO, WARN, ERROR, STATE, NOLOG")
|
||||
("log-color", po::value<bool>()->default_value(true), "logger color: true or false")
|
||||
;
|
||||
("print-options", po::value<bool>()->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() : "<not found>") << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int FairProgOptions::PrintOptions()
|
||||
{
|
||||
// //////////////////////////////////
|
||||
|
|
|
@ -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<std::string, std::string,std::string, std::string> VarValInfo_t;
|
||||
typedef std::tuple<std::string, std::string, std::string, std::string> VarValInfo_t;
|
||||
typedef std::map<std::string, VarValInfo_t> MapVarValInfo_t;
|
||||
|
||||
VarValInfo_t GetVariableValueInfo(const po::variable_value& varValue);
|
||||
|
|
|
@ -155,72 +155,76 @@ struct ConvertVariableValue : T
|
|||
//////////////////////////////// std types
|
||||
// std::string albeit useless here
|
||||
if (is_this_type<std::string>(varValue))
|
||||
return T::template Value<std::string>(varValue, std::string(" <string>"), defaultedValue, emptyValue);
|
||||
return T::template Value<std::string>(varValue, std::string("<string>"), defaultedValue, emptyValue);
|
||||
|
||||
// std::vector<std::string>
|
||||
if (is_this_type<std::vector<std::string>>(varValue))
|
||||
return T::template Value<std::vector<std::string>>(varValue, std::string(" <vector<string>>"), defaultedValue, emptyValue);
|
||||
return T::template Value<std::vector<std::string>>(varValue, std::string("<vector<string>>"), defaultedValue, emptyValue);
|
||||
|
||||
// int
|
||||
if (is_this_type<int>(varValue))
|
||||
return T::template Value<int>(varValue, std::string(" <int>"), defaultedValue, emptyValue);
|
||||
return T::template Value<int>(varValue, std::string("<int>"), defaultedValue, emptyValue);
|
||||
|
||||
// std::vector<int>
|
||||
if (is_this_type<std::vector<int>>(varValue))
|
||||
return T::template Value<std::vector<int>>(varValue, std::string(" <vector<int>>"), defaultedValue, emptyValue);
|
||||
return T::template Value<std::vector<int>>(varValue, std::string("<vector<int>>"), defaultedValue, emptyValue);
|
||||
|
||||
// float
|
||||
if (is_this_type<float>(varValue))
|
||||
return T::template Value<float>(varValue, std::string(" <float>"), defaultedValue, emptyValue);
|
||||
return T::template Value<float>(varValue, std::string("<float>"), defaultedValue, emptyValue);
|
||||
|
||||
// std::vector float
|
||||
if (is_this_type<std::vector<float>>(varValue))
|
||||
return T::template Value<std::vector<float>>(varValue, std::string(" <vector<float>>"), defaultedValue, emptyValue);
|
||||
return T::template Value<std::vector<float>>(varValue, std::string("<vector<float>>"), defaultedValue, emptyValue);
|
||||
|
||||
// double
|
||||
if (is_this_type<double>(varValue))
|
||||
return T::template Value<double>(varValue, std::string(" <double>"), defaultedValue, emptyValue);
|
||||
return T::template Value<double>(varValue, std::string("<double>"), defaultedValue, emptyValue);
|
||||
|
||||
// std::vector double
|
||||
if (is_this_type<std::vector<double>>(varValue))
|
||||
return T::template Value<std::vector<double>>(varValue, std::string(" <vector<double>>"), defaultedValue, emptyValue);
|
||||
return T::template Value<std::vector<double>>(varValue, std::string("<vector<double>>"), defaultedValue, emptyValue);
|
||||
|
||||
// short
|
||||
if (is_this_type<short>(varValue))
|
||||
return T::template Value<short>(varValue, std::string(" <short>"), defaultedValue, emptyValue);
|
||||
return T::template Value<short>(varValue, std::string("<short>"), defaultedValue, emptyValue);
|
||||
|
||||
// std::vector short
|
||||
if (is_this_type<std::vector<short>>(varValue))
|
||||
return T::template Value<std::vector<short>>(varValue, std::string(" <vector<short>>"), defaultedValue, emptyValue);
|
||||
return T::template Value<std::vector<short>>(varValue, std::string("<vector<short>>"), defaultedValue, emptyValue);
|
||||
|
||||
// long
|
||||
if (is_this_type<long>(varValue))
|
||||
return T::template Value<long>(varValue, std::string(" <long>"), defaultedValue, emptyValue);
|
||||
return T::template Value<long>(varValue, std::string("<long>"), defaultedValue, emptyValue);
|
||||
|
||||
// std::vector short
|
||||
if (is_this_type<std::vector<long>>(varValue))
|
||||
return T::template Value<std::vector<long>>(varValue, std::string(" <vector<long>>"), defaultedValue, emptyValue);
|
||||
return T::template Value<std::vector<long>>(varValue, std::string("<vector<long>>"), defaultedValue, emptyValue);
|
||||
|
||||
// size_t
|
||||
if (is_this_type<std::size_t>(varValue))
|
||||
return T::template Value<std::size_t>(varValue, std::string(" <std::size_t>"), defaultedValue, emptyValue);
|
||||
return T::template Value<std::size_t>(varValue, std::string("<std::size_t>"), defaultedValue, emptyValue);
|
||||
|
||||
// uint64_t
|
||||
if (is_this_type<std::uint64_t>(varValue))
|
||||
return T::template Value<std::uint64_t>(varValue, std::string("<std::uint64_t>"), defaultedValue, emptyValue);
|
||||
|
||||
// std::vector size_t
|
||||
if (is_this_type<std::vector<std::size_t>>(varValue))
|
||||
return T::template Value<std::vector<std::size_t>>(varValue, std::string(" <vector<std::size_t>>"), defaultedValue, emptyValue);
|
||||
return T::template Value<std::vector<std::size_t>>(varValue, std::string("<vector<std::size_t>>"), defaultedValue, emptyValue);
|
||||
|
||||
// bool
|
||||
if (is_this_type<bool>(varValue))
|
||||
return T::template Value<bool>(varValue, std::string(" <bool>"), defaultedValue, emptyValue);
|
||||
return T::template Value<bool>(varValue, std::string("<bool>"), defaultedValue, emptyValue);
|
||||
|
||||
// std::vector bool
|
||||
if (is_this_type<std::vector<bool>>(varValue))
|
||||
return T::template Value<std::vector<bool>>(varValue, std::string(" <vector<bool>>"), defaultedValue, emptyValue);
|
||||
return T::template Value<std::vector<bool>>(varValue, std::string("<vector<bool>>"), defaultedValue, emptyValue);
|
||||
|
||||
//////////////////////////////// boost types
|
||||
// boost::filesystem::path
|
||||
if (is_this_type<boost::filesystem::path>(varValue))
|
||||
return T::template Value<boost::filesystem::path>(varValue, std::string(" <boost::filesystem::path>"), defaultedValue, emptyValue);
|
||||
return T::template Value<boost::filesystem::path>(varValue, std::string("<boost::filesystem::path>"), defaultedValue, emptyValue);
|
||||
|
||||
// if we get here, the type is not supported return unknown info
|
||||
return T::DefaultValue(defaultedValue, emptyValue);
|
||||
|
|
Loading…
Reference in New Issue
Block a user