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(); | ||||
|         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; | ||||
|         } | ||||
| 
 | ||||
|         ExtractorOptions::GenerateOutputFilesNames(extractor_config); | ||||
| 
 | ||||
|         if (1 > extractor_config.requested_num_threads) | ||||
| @ -61,11 +69,11 @@ int main(int argc, char *argv[]) | ||||
|                                              << " not found!"; | ||||
|             return 1; | ||||
|         } | ||||
| 
 | ||||
|         return extractor().run(extractor_config); | ||||
|     } | ||||
|     catch (const std::exception &e) | ||||
|     { | ||||
|         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> | ||||
| 
 | ||||
| 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
 | ||||
|     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); | ||||
| 
 | ||||
|     // parse command line options
 | ||||
|     try | ||||
|     { | ||||
|         boost::program_options::variables_map option_variables; | ||||
|         boost::program_options::store(boost::program_options::command_line_parser(argc, argv) | ||||
|                                           .options(cmdline_options) | ||||
|                                           .positional(positional_options) | ||||
|                                           .run(), | ||||
|                                       option_variables); | ||||
| 
 | ||||
|         if (option_variables.count("version")) | ||||
|         { | ||||
|             SimpleLogger().Write() << g_GIT_DESCRIPTION; | ||||
|         return false; | ||||
|             return return_code::exit; | ||||
|         } | ||||
| 
 | ||||
|         if (option_variables.count("help")) | ||||
|         { | ||||
|             SimpleLogger().Write() << visible_options; | ||||
|         return false; | ||||
|             return return_code::exit; | ||||
|         } | ||||
| 
 | ||||
|         boost::program_options::notify(option_variables); | ||||
| @ -103,8 +105,8 @@ bool ExtractorOptions::ParseArguments(int argc, char *argv[], ExtractorConfig &e | ||||
|         // parse config file
 | ||||
|         if (boost::filesystem::is_regular_file(extractor_config.config_file_path)) | ||||
|         { | ||||
|         SimpleLogger().Write() << "Reading options from: " | ||||
|                                << extractor_config.config_file_path.string(); | ||||
|             SimpleLogger().Write() | ||||
|                 << "Reading options from: " << extractor_config.config_file_path.string(); | ||||
|             std::string ini_file_contents = | ||||
|                 ReadIniFileAndLowerContents(extractor_config.config_file_path); | ||||
|             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")) | ||||
|         { | ||||
|             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) | ||||
|  | ||||
| @ -30,6 +30,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||
| 
 | ||||
| #include <boost/filesystem.hpp> | ||||
| 
 | ||||
| enum class return_code : unsigned | ||||
| { | ||||
|     ok, | ||||
|     fail, | ||||
|     exit | ||||
| }; | ||||
| 
 | ||||
| struct ExtractorConfig | ||||
| { | ||||
|     ExtractorConfig() noexcept : requested_num_threads(0) {} | ||||
| @ -46,7 +53,7 @@ struct ExtractorConfig | ||||
| 
 | ||||
| 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); | ||||
| }; | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user