From a2b757ad96620ff1958160a65adcdb58b4ed2ba9 Mon Sep 17 00:00:00 2001 From: Jesse Bryan Date: Thu, 19 Dec 2019 15:43:34 -0600 Subject: [PATCH] finished the help menu and started expanding into multiple files --- .gitignore | 1 + CMakeLists.txt | 6 +- src/main.cpp | 166 +++++++++++++++++++++++++++---------------------- src/util.cpp | 16 +++++ src/util.hpp | 5 ++ 5 files changed, 117 insertions(+), 77 deletions(-) create mode 100644 src/util.cpp create mode 100644 src/util.hpp diff --git a/.gitignore b/.gitignore index eb5c4d8..2194641 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ build/ CMakeFiles/ +.vscode/ CMakeCache.txt \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index ad2cf9d..c82c7a0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,8 +13,10 @@ set(Boost_USE_MULTITHREADED ON) set(Boost_USE_STATIC_RUNTIME OFF) # set main entry point into program -add_executable(gsu src/main.cpp) +add_executable(gsu src/main.cpp src/util.cpp) -# include dependencies +# add libraries find_package(Boost REQUIRED COMPONENTS program_options) + +# link libraries target_link_libraries(gsu PUBLIC Boost::program_options) \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 0dc52a6..c629a3f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,89 +1,87 @@ #include #include + #include -int main(int argc, char *argv[]) +#include "util.hpp" + +int handle_cmdline_options(int argc, char *argv[]) { namespace po = boost::program_options; + po::options_description cmdline_options; + + po::options_description general_options("GENERAL OPTIONS"); + po::options_description utility_options("UTILITY OPTIONS"); + po::options_description capture_options("CAPTURE OPTIONS"); + po::options_description screenshot_options("SCREENSHOT OPTIONS"); + po::options_description video_options("VIDEO OPTIONS"); + + general_options.add_options() + ("help,h", + "Show the help menu.") + ("version,v", + "Show the current version.") + ("list-displays,l", + "List your current displays and their resolutions.") + ("upload,u", + "Upload after running the utility.") + ("terminal", + "Open interactive commands in a new terminal.\n" + "SET THIS IF RUNNING FROM ANYTHING OTHER THAN A TERM, i.e. xbindkeys") + ("hide", + "Minimize the current window while capturing.\n" + "This is useful when running with --terminal to hide the newly opened term.") + ("notify", + "Send a libnotify notification of the output.") + ; + + utility_options.add_options() + ("dmenu,r", + "Enable dmenu or rofi integration.") + ("screenshot,s", + "Take a screenshot. (default)") + ("video,m", + "Record a video of the screen.") + ("gif,g", + "Record a video and convert it to the gif format.") + ; + + capture_options.add_options() + ("no-cursor,n", + "Hide the cursor.") + ("display,d", + po::value()->value_name("NUM|TYPE"), + "Set the selection to a specific display.\n" + "Can read from an argument or from stdin.\n" + "Values: number of display, 'active', 'all' (default)") + ; + + screenshot_options.add_options() + ("no-opengl,o", + "Disable OpenGL hardware-accelerated capture.") + ; + + video_options.add_options() + ("countdown,c", + po::value()->value_name("NUM"), + "Count down before recording.") + ; + + cmdline_options + .add(general_options) + .add(utility_options) + .add(capture_options) + .add(screenshot_options) + .add(video_options) + ; + + po::variables_map vm; + try { - po::options_description cmdline_options; - - po::options_description general_options("GENERAL OPTIONS"); - po::options_description utility_options("UTILITY OPTIONS"); - po::options_description capture_options("CAPTURE OPTIONS"); - po::options_description screenshot_options("SCREENSHOT OPTIONS"); - po::options_description video_options("VIDEO OPTIONS"); - - general_options.add_options() - ("help,h", - "Show the help menu.") - ("version,v", - "Show the current version.") - ("list-displays,l", - "List your current displays and their resolutions.") - ("upload,u", - "Upload after running the utility.") - ("terminal", - "Open interactive commands in a new terminal.\n" - "SET THIS IF RUNNING FROM ANYTHING OTHER THAN A TERM, i.e. xbindkeys") - ("hide", - "Minimize the current window while capturing.\n" - "This is useful when running with --terminal to hide the newly opened term.") - ("notify", - "Send a libnotify notification of the output.") - ; - - utility_options.add_options() - ("dmenu,r", - "Enable dmenu or rofi integration.") - ("screenshot,s", - "Take a screenshot. (default)") - ("video,m", - "Record a video of the screen.") - ("gif,g", - "Record a video and convert it to the gif format.") - ; - - capture_options.add_options() - ("no-cursor,n", - "Hide the cursor.") - ("display,d", - po::value()->value_name("NUM|TYPE"), - "Set the selection to a specific display.\n" - "Can read from an argument or from stdin.\n" - "Values: number of display, 'active', 'all' (default)") - ; - - screenshot_options.add_options() - ("no-opengl,o", - "Disable OpenGL hardware-accelerated capture.") - ; - - video_options.add_options() - ("countdown,c", - po::value()->value_name("NUM"), - "Count down before recording.") - ; - - cmdline_options - .add(general_options) - .add(utility_options) - .add(capture_options) - .add(screenshot_options) - .add(video_options) - ; - - po::variables_map vm; po::store(po::parse_command_line(argc, argv, cmdline_options), vm); po::notify(vm); - - if (vm.count("help")) - { - std::cout << cmdline_options << std::endl; - return 0; - } } catch (std::exception &e) { @@ -91,5 +89,23 @@ int main(int argc, char *argv[]) return 1; } + if (vm.count("help")) + { + util::print_help(cmdline_options); + return 0; + } + + return 0; +} + +int main(int argc, char *argv[]) +{ + int code = handle_cmdline_options(argc, argv); + + if (code > 0) + { + return code; + } + return 0; } \ No newline at end of file diff --git a/src/util.cpp b/src/util.cpp new file mode 100644 index 0000000..a39aa6f --- /dev/null +++ b/src/util.cpp @@ -0,0 +1,16 @@ +#include +#include + +namespace util { + void print_help(boost::program_options::options_description options) + { + std::cout << + "Usage: gsu [OPTION]... OUTPUT\n" + "A general screenshot and upload utility for images, video, and gifs.\n\n" + + "OUTPUT defaults to $XDG_CONFIG_HOME/gsu/imgs if nothing is provided.\n" + "The most common location for $XDG_CONFIG_HOME is ~/.config.\n" + + << options << std::endl; // piping `options` to stdout automatically appends a newline beforehand + } +} \ No newline at end of file diff --git a/src/util.hpp b/src/util.hpp new file mode 100644 index 0000000..0332fe9 --- /dev/null +++ b/src/util.hpp @@ -0,0 +1,5 @@ +#include + +namespace util { + void print_help(boost::program_options::options_description options); +} \ No newline at end of file