mirror of
https://github.com/winneon/gsu.git
synced 2026-09-10 07:16:25 -04:00
finished the help menu and started expanding into multiple files
This commit is contained in:
parent
207b013d4d
commit
a2b757ad96
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,4 +1,5 @@
|
|||
build/
|
||||
CMakeFiles/
|
||||
.vscode/
|
||||
|
||||
CMakeCache.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)
|
||||
166
src/main.cpp
166
src/main.cpp
|
|
@ -1,89 +1,87 @@
|
|||
#include <iostream>
|
||||
#include <exception>
|
||||
|
||||
#include <boost/program_options.hpp>
|
||||
|
||||
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<std::string>()->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<int>()->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<std::string>()->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<int>()->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;
|
||||
}
|
||||
16
src/util.cpp
Normal file
16
src/util.cpp
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#include <iostream>
|
||||
#include <boost/program_options.hpp>
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
5
src/util.hpp
Normal file
5
src/util.hpp
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#include <boost/program_options.hpp>
|
||||
|
||||
namespace util {
|
||||
void print_help(boost::program_options::options_description options);
|
||||
}
|
||||
Loading…
Reference in a new issue