From 6316b89840a5fa3da402959b90ee74ead5a9afa5 Mon Sep 17 00:00:00 2001 From: PixlOne <8843371+PixlOne@users.noreply.github.com> Date: Sun, 12 Apr 2020 19:44:12 -0400 Subject: [PATCH] Reorganise logid.cpp --- src/logid/logid.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/logid/logid.cpp b/src/logid/logid.cpp index ab63b8a..ba36241 100644 --- a/src/logid/logid.cpp +++ b/src/logid/logid.cpp @@ -26,6 +26,8 @@ using namespace logid; +std::string config_file = DEFAULT_CONFIG_FILE; + LogLevel logid::global_verbosity = INFO; Configuration* logid::global_config; EvdevDevice* logid::global_evdev; @@ -40,10 +42,8 @@ enum class Option Version }; -int main(int argc, char** argv) +void read_cli_options(int argc, char** argv) { - std::string config_file = DEFAULT_CONFIG_FILE; - // Read command line options for(int i = 1; i < argc; i++) { Option option = Option::None; @@ -97,7 +97,7 @@ int main(int argc, char** argv) { log_printf(WARN, e.what()); printf("Valid verbosity levels are: Debug, Info, Warn/Warning, or Error.\n"); - return EXIT_FAILURE; + exit(EXIT_FAILURE); } } break; @@ -107,7 +107,7 @@ int main(int argc, char** argv) if (++i >= argc) { log_printf(ERROR, "Config file is not specified."); - return EXIT_FAILURE; + exit(EXIT_FAILURE); } config_file = argv[i]; break; @@ -123,18 +123,23 @@ Possible options are: -h,--help Print this message. )", LOGIOPS_VERSION, argv[0], DEFAULT_CONFIG_FILE); - return EXIT_SUCCESS; + exit(EXIT_SUCCESS); } case Option::Version: { printf("%s\n", LOGIOPS_VERSION); - return EXIT_SUCCESS; + exit(EXIT_SUCCESS); } case Option::None: break; } } } +} + +int main(int argc, char** argv) +{ + read_cli_options(argc, argv); // Read config try { global_config = new Configuration(config_file.c_str()); }