use enum as return code instead of boolean logic in extractor
This commit is contained in:
parent
dc7f21513a
commit
cf21074f10
12
extract.cpp
12
extract.cpp
@ -36,10 +36,18 @@ int main(int argc, char *argv[])
|
|||||||
LogPolicy::GetInstance().Unmute();
|
LogPolicy::GetInstance().Unmute();
|
||||||
ExtractorConfig extractor_config;
|
ExtractorConfig extractor_config;
|
||||||
|
|
||||||
if (!ExtractorOptions::ParseArguments(argc, argv, extractor_config))
|
const return_code result = ExtractorOptions::ParseArguments(argc, argv, extractor_config);
|
||||||
|
|
||||||
|
if (return_code::fail == result)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (return_code::exit == result)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ExtractorOptions::GenerateOutputFilesNames(extractor_config);
|
ExtractorOptions::GenerateOutputFilesNames(extractor_config);
|
||||||
|
|
||||||
if (1 > extractor_config.requested_num_threads)
|
if (1 > extractor_config.requested_num_threads)
|
||||||
@ -61,11 +69,11 @@ int main(int argc, char *argv[])
|
|||||||
<< " not found!";
|
<< " not found!";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return extractor().run(extractor_config);
|
return extractor().run(extractor_config);
|
||||||
}
|
}
|
||||||
catch (const std::exception &e)
|
catch (const std::exception &e)
|
||||||
{
|
{
|
||||||
SimpleLogger().Write(logWARNING) << "[exception] " << e.what();
|
SimpleLogger().Write(logWARNING) << "[exception] " << e.what();
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
|
|
||||||
#include <tbb/task_scheduler_init.h>
|
#include <tbb/task_scheduler_init.h>
|
||||||
|
|
||||||
bool ExtractorOptions::ParseArguments(int argc, char *argv[], ExtractorConfig &extractor_config)
|
return_code
|
||||||
|
ExtractorOptions::ParseArguments(int argc, char *argv[], ExtractorConfig &extractor_config)
|
||||||
{
|
{
|
||||||
// declare a group of options that will be allowed only on command line
|
// declare a group of options that will be allowed only on command line
|
||||||
boost::program_options::options_description generic_options("Options");
|
boost::program_options::options_description generic_options("Options");
|
||||||
@ -79,23 +80,24 @@ bool ExtractorOptions::ParseArguments(int argc, char *argv[], ExtractorConfig &e
|
|||||||
visible_options.add(generic_options).add(config_options);
|
visible_options.add(generic_options).add(config_options);
|
||||||
|
|
||||||
// parse command line options
|
// parse command line options
|
||||||
|
try
|
||||||
|
{
|
||||||
boost::program_options::variables_map option_variables;
|
boost::program_options::variables_map option_variables;
|
||||||
boost::program_options::store(boost::program_options::command_line_parser(argc, argv)
|
boost::program_options::store(boost::program_options::command_line_parser(argc, argv)
|
||||||
.options(cmdline_options)
|
.options(cmdline_options)
|
||||||
.positional(positional_options)
|
.positional(positional_options)
|
||||||
.run(),
|
.run(),
|
||||||
option_variables);
|
option_variables);
|
||||||
|
|
||||||
if (option_variables.count("version"))
|
if (option_variables.count("version"))
|
||||||
{
|
{
|
||||||
SimpleLogger().Write() << g_GIT_DESCRIPTION;
|
SimpleLogger().Write() << g_GIT_DESCRIPTION;
|
||||||
return false;
|
return return_code::exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (option_variables.count("help"))
|
if (option_variables.count("help"))
|
||||||
{
|
{
|
||||||
SimpleLogger().Write() << visible_options;
|
SimpleLogger().Write() << visible_options;
|
||||||
return false;
|
return return_code::exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::program_options::notify(option_variables);
|
boost::program_options::notify(option_variables);
|
||||||
@ -103,8 +105,8 @@ bool ExtractorOptions::ParseArguments(int argc, char *argv[], ExtractorConfig &e
|
|||||||
// parse config file
|
// parse config file
|
||||||
if (boost::filesystem::is_regular_file(extractor_config.config_file_path))
|
if (boost::filesystem::is_regular_file(extractor_config.config_file_path))
|
||||||
{
|
{
|
||||||
SimpleLogger().Write() << "Reading options from: "
|
SimpleLogger().Write()
|
||||||
<< extractor_config.config_file_path.string();
|
<< "Reading options from: " << extractor_config.config_file_path.string();
|
||||||
std::string ini_file_contents =
|
std::string ini_file_contents =
|
||||||
ReadIniFileAndLowerContents(extractor_config.config_file_path);
|
ReadIniFileAndLowerContents(extractor_config.config_file_path);
|
||||||
std::stringstream config_stream(ini_file_contents);
|
std::stringstream config_stream(ini_file_contents);
|
||||||
@ -116,9 +118,16 @@ bool ExtractorOptions::ParseArguments(int argc, char *argv[], ExtractorConfig &e
|
|||||||
if (!option_variables.count("input"))
|
if (!option_variables.count("input"))
|
||||||
{
|
{
|
||||||
SimpleLogger().Write() << visible_options;
|
SimpleLogger().Write() << visible_options;
|
||||||
return false;
|
return return_code::exit;
|
||||||
}
|
}
|
||||||
return true;
|
}
|
||||||
|
catch (std::exception &e)
|
||||||
|
{
|
||||||
|
SimpleLogger().Write(logWARNING) << e.what();
|
||||||
|
return return_code::fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
return return_code::ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExtractorOptions::GenerateOutputFilesNames(ExtractorConfig &extractor_config)
|
void ExtractorOptions::GenerateOutputFilesNames(ExtractorConfig &extractor_config)
|
||||||
|
@ -30,6 +30,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
|
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
|
|
||||||
|
enum class return_code : unsigned
|
||||||
|
{
|
||||||
|
ok,
|
||||||
|
fail,
|
||||||
|
exit
|
||||||
|
};
|
||||||
|
|
||||||
struct ExtractorConfig
|
struct ExtractorConfig
|
||||||
{
|
{
|
||||||
ExtractorConfig() noexcept : requested_num_threads(0) {}
|
ExtractorConfig() noexcept : requested_num_threads(0) {}
|
||||||
@ -46,7 +53,7 @@ struct ExtractorConfig
|
|||||||
|
|
||||||
struct ExtractorOptions
|
struct ExtractorOptions
|
||||||
{
|
{
|
||||||
static bool ParseArguments(int argc, char *argv[], ExtractorConfig &extractor_config);
|
static return_code ParseArguments(int argc, char *argv[], ExtractorConfig &extractor_config);
|
||||||
|
|
||||||
static void GenerateOutputFilesNames(ExtractorConfig &extractor_config);
|
static void GenerateOutputFilesNames(ExtractorConfig &extractor_config);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user