Let ParseAll exit if unsuccessfull

This commit is contained in:
Alexey Rybalchenko 2016-05-12 11:35:24 +02:00 committed by Mohammad Al-Turany
parent 31456e71ff
commit 28aa5e4caa
8 changed files with 23 additions and 44 deletions

View File

@ -33,7 +33,7 @@ FairMQProgOptions::~FairMQProgOptions()
{
}
int FairMQProgOptions::ParseAll(const int argc, char** argv, bool allowUnregistered)
void FairMQProgOptions::ParseAll(const int argc, char** argv, bool allowUnregistered)
{
LOG(NOLOG) << "";
// init description
@ -41,7 +41,8 @@ int FairMQProgOptions::ParseAll(const int argc, char** argv, bool allowUnregiste
// parse command line options
if (ParseCmdLine(argc, argv, fCmdLineOptions, fVarMap, allowUnregistered))
{
return 1;
LOG(ERROR) << "Could not parse cmd options";
exit(EXIT_FAILURE);
}
// if txt/INI configuration file enabled then parse it as well
@ -52,13 +53,14 @@ int FairMQProgOptions::ParseAll(const int argc, char** argv, bool allowUnregiste
{
if (ParseCfgFile(fConfigFile.string(), fConfigFileOptions, fVarMap, allowUnregistered))
{
return 1;
LOG(ERROR) << "Could not parse config";
exit(EXIT_FAILURE);
}
}
else
{
LOG(ERROR) << "config file '" << fConfigFile << "' not found";
return 1;
exit(EXIT_FAILURE);
}
}
@ -123,32 +125,30 @@ int FairMQProgOptions::ParseAll(const int argc, char** argv, bool allowUnregiste
id = fVarMap["id"].as<std::string>();
}
std::string file_extension = boost::filesystem::extension(file);
std::string fileExtension = boost::filesystem::extension(file);
std::transform(file_extension.begin(), file_extension.end(), file_extension.begin(), ::tolower);
std::transform(fileExtension.begin(), fileExtension.end(), fileExtension.begin(), ::tolower);
if (file_extension == ".json")
if (fileExtension == ".json")
{
UserParser<FairMQParser::JSON>(file, id);
}
else
{
if (file_extension == ".xml")
if (fileExtension == ".xml")
{
UserParser<FairMQParser::XML>(file, id);
}
else
{
LOG(ERROR) << "mq-config command line called but file extension '"
<< file_extension
<< fileExtension
<< "' not recognized. Program will now exit";
return 1;
exit(EXIT_FAILURE);
}
}
}
}
return 0;
}
int FairMQProgOptions::NotifySwitchOption()

View File

@ -36,7 +36,7 @@ class FairMQProgOptions : public FairProgOptions
// parse command line and txt/INI configuration file.
// default parser for the mq-configuration file (JSON/XML) is called if command line key mq-config is called
virtual int ParseAll(const int argc, char** argv, bool allowUnregistered = false);
virtual void ParseAll(const int argc, char** argv, bool allowUnregistered = false);
// external parser, store function
template <typename T, typename ...Args>

View File

@ -27,7 +27,7 @@
#include <tuple>
/*
* FairProgOptions abstract base class
* FairProgOptions abstract base class
* parse command line, configuration file options as well as environment variables.
*
* The user defines in the derived class the option descriptions and
@ -42,15 +42,14 @@
* fVisibleOptions.add(fCmdlineOptions);
* }
* virtual ~MyOptions() {}
* virtual int ParseAll(const int argc, char** argv, bool allowUnregistered = false)
* virtual void ParseAll(const int argc, char** argv, bool allowUnregistered = false)
* {
* if(ParseCmdLine(argc, argv, fCmdlineOptions, fVarMap, allowUnregistered))
* if (ParseCmdLine(argc, argv, fCmdlineOptions, fVarMap, allowUnregistered))
* {
* return 1;
* exit(EXIT_FAILURE);
* }
*
* PrintOptions();
* return 0;
* }
* }
*/
@ -110,7 +109,7 @@ class FairProgOptions
int ParseEnvironment(const std::function<std::string(std::string)>&);
virtual int 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();
int PrintHelp() const;

View File

@ -37,11 +37,7 @@ int main(int argc, char** argv)
FairMQProgOptions config;
config.AddToCmdLineOptions(samplerOptions);
if (config.ParseAll(argc, argv))
{
return 0;
}
config.ParseAll(argc, argv);
FairMQBenchmarkSampler sampler;
sampler.SetProperty(FairMQBenchmarkSampler::MsgSize, msgSize);

View File

@ -24,11 +24,7 @@ int main(int argc, char** argv)
try
{
FairMQProgOptions config;
if (config.ParseAll(argc, argv))
{
return 0;
}
config.ParseAll(argc, argv);
FairMQMerger merger;
runStateMachine(merger, config);

View File

@ -24,11 +24,7 @@ int main(int argc, char** argv)
try
{
FairMQProgOptions config;
if (config.ParseAll(argc, argv))
{
return 0;
}
config.ParseAll(argc, argv);
FairMQProxy proxy;
runStateMachine(proxy, config);

View File

@ -35,11 +35,7 @@ int main(int argc, char** argv)
FairMQProgOptions config;
config.AddToCmdLineOptions(sinkOptions);
if (config.ParseAll(argc, argv))
{
return 0;
}
config.ParseAll(argc, argv);
FairMQSink sink;
sink.SetProperty(FairMQSink::NumMsgs, numMsgs);

View File

@ -24,11 +24,7 @@ int main(int argc, char** argv)
try
{
FairMQProgOptions config;
if (config.ParseAll(argc, argv))
{
return 0;
}
config.ParseAll(argc, argv);
FairMQSplitter splitter;
runStateMachine(splitter, config);