add --print-options to print available options in short format

This commit is contained in:
Alexey Rybalchenko 2017-06-07 16:27:40 +02:00 committed by Mohammad Al-Turany
parent cae3fd6aa3
commit 1d38a2350f
4 changed files with 72 additions and 40 deletions

View File

@ -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 verbosity = GetValue<string>("verbosity");
string logFile = GetValue<string>("log-to-file"); string logFile = GetValue<string>("log-to-file");
bool color = GetValue<bool>("log-color"); 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"; LOG(DEBUG) << "channel-config: Parsing channel configuration";
UserParser<FairMQParser::SUBOPT>(fVarMap, id); UserParser<FairMQParser::SUBOPT>(fVarMap, id);
} }
} }
FairProgOptions::PrintOptions(); FairProgOptions::PrintOptions();
@ -312,7 +323,7 @@ void FairMQProgOptions::InitOptionDescription()
; ;
fMQOptionsInCfg.add_options() 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.") ("io-threads", po::value<int >()->default_value(1), "Number of I/O threads.")
("transport", po::value<string>()->default_value("zeromq"), "Transport ('zeromq'/'nanomsg').") ("transport", po::value<string>()->default_value("zeromq"), "Transport ('zeromq'/'nanomsg').")
("config", po::value<string>()->default_value("static"), "Config source ('static'/<config library filename>).") ("config", po::value<string>()->default_value("static"), "Config source ('static'/<config library filename>).")
@ -331,7 +342,7 @@ void FairMQProgOptions::InitOptionDescription()
else else
{ {
fMQOptionsInCmd.add_options() 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") ("io-threads", po::value<int >()->default_value(1), "Number of I/O threads")
("transport", po::value<string>()->default_value("zeromq"), "Transport ('zeromq'/'nanomsg').") ("transport", po::value<string>()->default_value("zeromq"), "Transport ('zeromq'/'nanomsg').")
("config", po::value<string>()->default_value("static"), "Config source ('static'/<config library filename>).") ("config", po::value<string>()->default_value("static"), "Config source ('static'/<config library filename>).")

View File

@ -37,27 +37,18 @@ FairProgOptions::FairProgOptions() :
fGenericDesc.add_options() fGenericDesc.add_options()
("help,h", "produce help") ("help,h", "produce help")
("version,v", "print version") ("version,v", "print version")
("verbosity", po::value<std::string>(&fVerbosityLevel)->default_value("DEBUG"), "Verbosity level : \n" ("verbosity", po::value<std::string>(&fVerbosityLevel)->default_value("DEBUG"), "Verbosity level : TRACE, DEBUG, RESULTS, INFO, WARN, ERROR, STATE, NOLOG")
" TRACE \n"
" DEBUG \n"
" RESULTS \n"
" INFO \n"
" WARN \n"
" ERROR \n"
" STATE \n"
" NOLOG"
)
("log-color", po::value<bool>()->default_value(true), "logger color: true or false") ("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["TRACE"] = FairMQ::severity_level::TRACE;
fSeverityMap["DEBUG"] = FairMQ::severity_level::DEBUG; fSeverityMap["DEBUG"] = FairMQ::severity_level::DEBUG;
fSeverityMap["RESULTS"] = FairMQ::severity_level::RESULTS; fSeverityMap["RESULTS"] = FairMQ::severity_level::RESULTS;
fSeverityMap["INFO"] = FairMQ::severity_level::INFO; fSeverityMap["INFO"] = FairMQ::severity_level::INFO;
fSeverityMap["WARN"] = FairMQ::severity_level::WARN; fSeverityMap["WARN"] = FairMQ::severity_level::WARN;
fSeverityMap["ERROR"] = FairMQ::severity_level::ERROR; fSeverityMap["ERROR"] = FairMQ::severity_level::ERROR;
fSeverityMap["STATE"] = FairMQ::severity_level::STATE; fSeverityMap["STATE"] = FairMQ::severity_level::STATE;
fSeverityMap["NOLOG"] = FairMQ::severity_level::NOLOG; fSeverityMap["NOLOG"] = FairMQ::severity_level::NOLOG;
} }
/// Destructor /// Destructor
@ -241,6 +232,31 @@ int FairProgOptions::PrintHelp() const
return 0; 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() int FairProgOptions::PrintOptions()
{ {
// ////////////////////////////////// // //////////////////////////////////

View File

@ -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 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 PrintOptions();
virtual int PrintOptionsRaw();
int PrintHelp() const; int PrintHelp() const;
protected: protected:
@ -176,7 +177,7 @@ class FairProgOptions
private: private:
// Methods below are helper functions used in the PrintOptions method // 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; typedef std::map<std::string, VarValInfo_t> MapVarValInfo_t;
VarValInfo_t GetVariableValueInfo(const po::variable_value& varValue); VarValInfo_t GetVariableValueInfo(const po::variable_value& varValue);

View File

@ -155,72 +155,76 @@ struct ConvertVariableValue : T
//////////////////////////////// std types //////////////////////////////// std types
// std::string albeit useless here // std::string albeit useless here
if (is_this_type<std::string>(varValue)) 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> // std::vector<std::string>
if (is_this_type<std::vector<std::string>>(varValue)) 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 // int
if (is_this_type<int>(varValue)) 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> // std::vector<int>
if (is_this_type<std::vector<int>>(varValue)) 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 // float
if (is_this_type<float>(varValue)) 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 // std::vector float
if (is_this_type<std::vector<float>>(varValue)) 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 // double
if (is_this_type<double>(varValue)) 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 // std::vector double
if (is_this_type<std::vector<double>>(varValue)) 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 // short
if (is_this_type<short>(varValue)) 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 // std::vector short
if (is_this_type<std::vector<short>>(varValue)) 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 // long
if (is_this_type<long>(varValue)) 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 // std::vector short
if (is_this_type<std::vector<long>>(varValue)) 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 // size_t
if (is_this_type<std::size_t>(varValue)) 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 // std::vector size_t
if (is_this_type<std::vector<std::size_t>>(varValue)) 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 // bool
if (is_this_type<bool>(varValue)) 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 // std::vector bool
if (is_this_type<std::vector<bool>>(varValue)) 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 types
// boost::filesystem::path // boost::filesystem::path
if (is_this_type<boost::filesystem::path>(varValue)) 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 // if we get here, the type is not supported return unknown info
return T::DefaultValue(defaultedValue, emptyValue); return T::DefaultValue(defaultedValue, emptyValue);