From 2b8d25559ada795c6a937c685fc9ced76c6354a3 Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Sun, 22 Mar 2020 01:48:57 -0500 Subject: [PATCH] Move help and version functions to the same place as the other arguments --- cli.cpp | 122 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 64 insertions(+), 58 deletions(-) diff --git a/cli.cpp b/cli.cpp index c9bb335e..2acc374a 100644 --- a/cli.cpp +++ b/cli.cpp @@ -30,50 +30,6 @@ struct Options DeviceOptions allDeviceOptions; }; -void PrintHelp() -{ - std::string help_text; - help_text += "OpenRGB "; - help_text += VERSION_STRING; - help_text += ", for controlling RGB lighting.\n"; - help_text += "Usage: OpenRGB (--device [--mode] [--color])...\n"; - help_text += "\n"; - help_text += "Options:\n"; - help_text += "--gui Show GUI, also appears when not passing any parameters\n"; - help_text += "-l, --list-devices Lists every compatible device with their number\n"; - help_text += "-d, --device [0-9] Selects device to apply colors and/or effect to, or applies to all devices if omitted\n"; - help_text += " Can be specified multiple times with different modes and colors\n"; - help_text += "-c, --color \"FFFFFF,00AAFF...\" Sets colors on each device directly if no effect is specified, and sets the effect color if an effect is specified\n"; - help_text += " If there are more LEDs than colors given, the last color will be applied to the remaining LEDs\n"; - help_text += "-m, --mode [breathing | static | ...] Sets the mode to be applied, check --list-devices to see which modes are supported on your device\n"; - help_text += "-v, --version Display version and software build information\n"; - help_text += "-p, --profile filename.orp Load the profile from filename.orp\n"; - help_text += "-sp, --save-profile filename.orp Save the given settings to profile filename.orp\n"; - - std::cout << help_text << std::endl; -} - -void PrintVersion() -{ - std::string version_text; - version_text += "OpenRGB "; - version_text += VERSION_STRING; - version_text += ", for controlling RGB lighting.\n"; - version_text += " Version:\t\t "; - version_text += VERSION_STRING; - version_text += "\n Build Date\t\t "; - version_text += BUILDDATE_STRING; - version_text += "\n Git Commit ID\t\t "; - version_text += GIT_COMMIT_ID; - version_text += "\n Git Commit Date\t "; - version_text += GIT_COMMIT_DATE; - version_text += "\n Git Branch\t\t "; - version_text += GIT_BRANCH; - version_text += "\n"; - - std::cout << version_text << std::endl; -} - bool ParseColors(std::string colors_string, DeviceOptions *options) { while (colors_string.length() >= 6) @@ -157,6 +113,50 @@ std::string QuoteIfNecessary(std::string str) | Option processing functions | \*---------------------------------------------------------------------------------------------------------*/ +void OptionHelp() +{ + std::string help_text; + help_text += "OpenRGB "; + help_text += VERSION_STRING; + help_text += ", for controlling RGB lighting.\n"; + help_text += "Usage: OpenRGB (--device [--mode] [--color])...\n"; + help_text += "\n"; + help_text += "Options:\n"; + help_text += "--gui Show GUI, also appears when not passing any parameters\n"; + help_text += "-l, --list-devices Lists every compatible device with their number\n"; + help_text += "-d, --device [0-9] Selects device to apply colors and/or effect to, or applies to all devices if omitted\n"; + help_text += " Can be specified multiple times with different modes and colors\n"; + help_text += "-c, --color \"FFFFFF,00AAFF...\" Sets colors on each device directly if no effect is specified, and sets the effect color if an effect is specified\n"; + help_text += " If there are more LEDs than colors given, the last color will be applied to the remaining LEDs\n"; + help_text += "-m, --mode [breathing | static | ...] Sets the mode to be applied, check --list-devices to see which modes are supported on your device\n"; + help_text += "-v, --version Display version and software build information\n"; + help_text += "-p, --profile filename.orp Load the profile from filename.orp\n"; + help_text += "-sp, --save-profile filename.orp Save the given settings to profile filename.orp\n"; + + std::cout << help_text << std::endl; +} + +void OptionVersion() +{ + std::string version_text; + version_text += "OpenRGB "; + version_text += VERSION_STRING; + version_text += ", for controlling RGB lighting.\n"; + version_text += " Version:\t\t "; + version_text += VERSION_STRING; + version_text += "\n Build Date\t\t "; + version_text += BUILDDATE_STRING; + version_text += "\n Git Commit ID\t\t "; + version_text += GIT_COMMIT_ID; + version_text += "\n Git Commit Date\t "; + version_text += GIT_COMMIT_DATE; + version_text += "\n Git Branch\t\t "; + version_text += GIT_BRANCH; + version_text += "\n"; + + std::cout << version_text << std::endl; +} + void OptionListDevices() { for(std::size_t controller_idx = 0; controller_idx < rgb_controllers.size(); controller_idx++) @@ -371,10 +371,28 @@ bool ProcessOptions(int argc, char *argv[], Options *res) arg_index++; } + /*---------------------------------------------------------*\ + | -h / --help | + \*---------------------------------------------------------*/ + else if(option == "--help" || option == "-h") + { + OptionHelp(); + exit(0); + } + + /*---------------------------------------------------------*\ + | -v / --version | + \*---------------------------------------------------------*/ + else if(option == "--version" || option == "-v") + { + OptionVersion(); + exit(0); + } + /*---------------------------------------------------------*\ | -l / --list-devices | \*---------------------------------------------------------*/ - if(option == "--list-devices" || option == "-l") + else if(option == "--list-devices" || option == "-l") { OptionListDevices(); exit(0); @@ -491,22 +509,10 @@ int cli_main(int argc, char *argv[], std::vector rgb_controller rgb_controllers = rgb_controllers_in; profile_manager = profile_manager_in; - if (argc == 2 && (!strcmp(argv[1], "--help") || !strcmp(argv[1], "-h"))) - { - PrintHelp(); - return 0; - } - - if (argc == 2 && (!strcmp(argv[1], "--version") || !strcmp(argv[1], "-v"))) - { - PrintVersion(); - return 0; - } - Options options; if (!ProcessOptions(argc, argv, &options)) { - PrintHelp(); + OptionHelp(); return -1; }