From 28aa5e4caa27d3a0ba87065269f7eb1bbaf47606 Mon Sep 17 00:00:00 2001 From: Alexey Rybalchenko Date: Thu, 12 May 2016 11:35:24 +0200 Subject: [PATCH] Let ParseAll exit if unsuccessfull --- fairmq/options/FairMQProgOptions.cxx | 24 ++++++++++++------------ fairmq/options/FairMQProgOptions.h | 2 +- fairmq/options/FairProgOptions.h | 11 +++++------ fairmq/run/runBenchmarkSampler.cxx | 6 +----- fairmq/run/runMerger.cxx | 6 +----- fairmq/run/runProxy.cxx | 6 +----- fairmq/run/runSink.cxx | 6 +----- fairmq/run/runSplitter.cxx | 6 +----- 8 files changed, 23 insertions(+), 44 deletions(-) diff --git a/fairmq/options/FairMQProgOptions.cxx b/fairmq/options/FairMQProgOptions.cxx index 315d2416..7e98b5ab 100644 --- a/fairmq/options/FairMQProgOptions.cxx +++ b/fairmq/options/FairMQProgOptions.cxx @@ -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 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(file, id); } else { - if (file_extension == ".xml") + if (fileExtension == ".xml") { UserParser(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() diff --git a/fairmq/options/FairMQProgOptions.h b/fairmq/options/FairMQProgOptions.h index 5282cd84..6dabc300 100644 --- a/fairmq/options/FairMQProgOptions.h +++ b/fairmq/options/FairMQProgOptions.h @@ -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 diff --git a/fairmq/options/FairProgOptions.h b/fairmq/options/FairProgOptions.h index 1c878d09..91ac82c0 100644 --- a/fairmq/options/FairProgOptions.h +++ b/fairmq/options/FairProgOptions.h @@ -27,7 +27,7 @@ #include /* - * 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&); - 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; diff --git a/fairmq/run/runBenchmarkSampler.cxx b/fairmq/run/runBenchmarkSampler.cxx index ded04ac6..3f26a011 100644 --- a/fairmq/run/runBenchmarkSampler.cxx +++ b/fairmq/run/runBenchmarkSampler.cxx @@ -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); diff --git a/fairmq/run/runMerger.cxx b/fairmq/run/runMerger.cxx index 26d188ab..aeb1923d 100644 --- a/fairmq/run/runMerger.cxx +++ b/fairmq/run/runMerger.cxx @@ -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); diff --git a/fairmq/run/runProxy.cxx b/fairmq/run/runProxy.cxx index 418195f2..90f92e20 100644 --- a/fairmq/run/runProxy.cxx +++ b/fairmq/run/runProxy.cxx @@ -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); diff --git a/fairmq/run/runSink.cxx b/fairmq/run/runSink.cxx index 30ecca9f..e3163c74 100644 --- a/fairmq/run/runSink.cxx +++ b/fairmq/run/runSink.cxx @@ -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); diff --git a/fairmq/run/runSplitter.cxx b/fairmq/run/runSplitter.cxx index a4e49ea7..7a2d3a6f 100644 --- a/fairmq/run/runSplitter.cxx +++ b/fairmq/run/runSplitter.cxx @@ -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);