From 3d6611fd50d1eb95732ab6f4306cd57a572ab735 Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Thu, 28 Apr 2022 22:51:02 -0400 Subject: [PATCH 1/4] Update help argument --- sunshine/main.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sunshine/main.cpp b/sunshine/main.cpp index bcab4b3b..c78c897f 100644 --- a/sunshine/main.cpp +++ b/sunshine/main.cpp @@ -61,17 +61,19 @@ void print_help(const char *name) { std::cout << "Usage: "sv << name << " [options] [/path/to/configuration_file] [--cmd]"sv << std::endl << " Any configurable option can be overwritten with: \"name=value\""sv << std::endl + << std:endl + << " Note: The configuration will be created if it doesn't exist."sv << std::endl << std::endl << " --help | print help"sv << std::endl - << " --creds username password | set user credentials for the Web manager" << std::endl - << " --version | print the version of sunshine" << std::endl + << " --creds username password | set user credentials for the Web manager"sv << std::endl + << " --version | print the version of sunshine"sv << std::endl << std::endl << " flags"sv << std::endl << " -0 | Read PIN from stdin"sv << std::endl << " -1 | Do not load previously saved state and do retain any state after shutdown"sv << std::endl << " | Effectively starting as if for the first time without overwriting any pairings with your devices"sv << std::endl - << " -2 | Force replacement of headers in video stream" << std::endl - << " -p | Enable/Disable UPnP" << std::endl + << " -2 | Force replacement of headers in video stream"sv << std::endl + << " -p | Enable/Disable UPnP"sv << std::endl << std::endl; } From a9cf0ebf188095bac103adb12b3ed2d0acd1dbb4 Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Thu, 28 Apr 2022 23:18:58 -0400 Subject: [PATCH 2/4] Remove unused `name` variable - Add documentation blocks --- sunshine/main.cpp | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/sunshine/main.cpp b/sunshine/main.cpp index c78c897f..93bd40aa 100644 --- a/sunshine/main.cpp +++ b/sunshine/main.cpp @@ -57,11 +57,15 @@ struct NoDelete { BOOST_LOG_ATTRIBUTE_KEYWORD(severity, "Severity", int) -void print_help(const char *name) { +/** Print the help to stdout. + + This function prints output to stdout. +*/ +void print_help() { std::cout - << "Usage: "sv << name << " [options] [/path/to/configuration_file] [--cmd]"sv << std::endl + << "Usage: "sv << PROJECT_NAME << " [options] [/path/to/configuration_file] [--cmd]"sv << std::endl << " Any configurable option can be overwritten with: \"name=value\""sv << std::endl - << std:endl + << std::endl << " Note: The configuration will be created if it doesn't exist."sv << std::endl << std::endl << " --help | print help"sv << std::endl @@ -77,15 +81,23 @@ void print_help(const char *name) { << std::endl; } +/** Call the print_help function. + + Calls the print_help function and then exits. +*/ namespace help { -int entry(const char *name, int argc, char *argv[]) { - print_help(name); +int entry(int argc, char *argv[]) { + print_help(); return 0; } } // namespace help +/** Print the version details to stdout. + + This function prints the version details to stdout and then exits. +*/ namespace version { -int entry(const char *name, int argc, char *argv[]) { +int entry(int argc, char *argv[]) { std::cout << PROJECT_NAME << " version: v" << PROJECT_VER << std::endl; return 0; } @@ -108,9 +120,9 @@ void on_signal(int sig, FN &&fn) { } namespace gen_creds { -int entry(const char *name, int argc, char *argv[]) { +int entry(int argc, char *argv[]) { if(argc < 2 || argv[0] == "help"sv || argv[1] == "help"sv) { - print_help(name); + print_help(); return 0; } @@ -120,7 +132,7 @@ int entry(const char *name, int argc, char *argv[]) { } } // namespace gen_creds -std::map> cmd_to_func { +std::map> cmd_to_func { { "creds"sv, gen_creds::entry }, { "help"sv, help::entry }, { "version"sv, version::entry } @@ -328,4 +340,4 @@ int write_file(const char *path, const std::string_view &contents) { std::uint16_t map_port(int port) { return (std::uint16_t)((int)config::sunshine.port + port); -} \ No newline at end of file +} From ced0029abc479d49263f6de34b1a81b812d4631e Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Thu, 28 Apr 2022 23:47:05 -0400 Subject: [PATCH 3/4] Remove unused argument --- sunshine/config.cpp | 6 +++--- sunshine/main.cpp | 2 +- sunshine/main.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/sunshine/config.cpp b/sunshine/config.cpp index 6aaeb305..022df5e2 100644 --- a/sunshine/config.cpp +++ b/sunshine/config.cpp @@ -863,7 +863,7 @@ int parse(int argc, char *argv[]) { auto line = argv[x]; if(line == "--help"sv) { - print_help(*argv); + print_help(); return 1; } else if(*line == '-') { @@ -875,7 +875,7 @@ int parse(int argc, char *argv[]) { break; } if(apply_flags(line + 1)) { - print_help(*argv); + print_help(); return -1; } } @@ -889,7 +889,7 @@ int parse(int argc, char *argv[]) { else { TUPLE_EL(var, 1, parse_option(line, line_end)); if(!var) { - print_help(*argv); + print_help(); return -1; } diff --git a/sunshine/main.cpp b/sunshine/main.cpp index 93bd40aa..5a52f4aa 100644 --- a/sunshine/main.cpp +++ b/sunshine/main.cpp @@ -229,7 +229,7 @@ int main(int argc, char *argv[]) { return 7; } - return fn->second(argv[0], config::sunshine.cmd.argc, config::sunshine.cmd.argv); + return fn->second(config::sunshine.cmd.argc, config::sunshine.cmd.argv); } task_pool.start(1); diff --git a/sunshine/main.h b/sunshine/main.h index aa9558b3..48cbc62f 100644 --- a/sunshine/main.h +++ b/sunshine/main.h @@ -24,7 +24,7 @@ extern boost::log::sources::severity_logger fatal; void log_flush(); -void print_help(const char *name); +void print_help(); std::string read_file(const char *path); int write_file(const char *path, const std::string_view &contents); From aa46b8e293f065946df84238c71b7347e347e7db Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Fri, 29 Apr 2022 12:52:09 -0400 Subject: [PATCH 4/4] Revert removing `name` argument from `print_help` function - The existing method is better because it uses the binary name instead of the project name `Sunshine`. --- sunshine/config.cpp | 6 +++--- sunshine/main.cpp | 18 +++++++++--------- sunshine/main.h | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/sunshine/config.cpp b/sunshine/config.cpp index 022df5e2..6aaeb305 100644 --- a/sunshine/config.cpp +++ b/sunshine/config.cpp @@ -863,7 +863,7 @@ int parse(int argc, char *argv[]) { auto line = argv[x]; if(line == "--help"sv) { - print_help(); + print_help(*argv); return 1; } else if(*line == '-') { @@ -875,7 +875,7 @@ int parse(int argc, char *argv[]) { break; } if(apply_flags(line + 1)) { - print_help(); + print_help(*argv); return -1; } } @@ -889,7 +889,7 @@ int parse(int argc, char *argv[]) { else { TUPLE_EL(var, 1, parse_option(line, line_end)); if(!var) { - print_help(); + print_help(*argv); return -1; } diff --git a/sunshine/main.cpp b/sunshine/main.cpp index 5a52f4aa..0f5581d6 100644 --- a/sunshine/main.cpp +++ b/sunshine/main.cpp @@ -61,9 +61,9 @@ BOOST_LOG_ATTRIBUTE_KEYWORD(severity, "Severity", int) This function prints output to stdout. */ -void print_help() { +void print_help(const char *name) { std::cout - << "Usage: "sv << PROJECT_NAME << " [options] [/path/to/configuration_file] [--cmd]"sv << std::endl + << "Usage: "sv << name << " [options] [/path/to/configuration_file] [--cmd]"sv << std::endl << " Any configurable option can be overwritten with: \"name=value\""sv << std::endl << std::endl << " Note: The configuration will be created if it doesn't exist."sv << std::endl @@ -86,8 +86,8 @@ void print_help() { Calls the print_help function and then exits. */ namespace help { -int entry(int argc, char *argv[]) { - print_help(); +int entry(const char *name, int argc, char *argv[]) { + print_help(name); return 0; } } // namespace help @@ -97,7 +97,7 @@ int entry(int argc, char *argv[]) { This function prints the version details to stdout and then exits. */ namespace version { -int entry(int argc, char *argv[]) { +int entry(const char *name, int argc, char *argv[]) { std::cout << PROJECT_NAME << " version: v" << PROJECT_VER << std::endl; return 0; } @@ -120,9 +120,9 @@ void on_signal(int sig, FN &&fn) { } namespace gen_creds { -int entry(int argc, char *argv[]) { +int entry(const char *name, int argc, char *argv[]) { if(argc < 2 || argv[0] == "help"sv || argv[1] == "help"sv) { - print_help(); + print_help(name); return 0; } @@ -132,7 +132,7 @@ int entry(int argc, char *argv[]) { } } // namespace gen_creds -std::map> cmd_to_func { +std::map> cmd_to_func { { "creds"sv, gen_creds::entry }, { "help"sv, help::entry }, { "version"sv, version::entry } @@ -229,7 +229,7 @@ int main(int argc, char *argv[]) { return 7; } - return fn->second(config::sunshine.cmd.argc, config::sunshine.cmd.argv); + return fn->second(argv[0], config::sunshine.cmd.argc, config::sunshine.cmd.argv); } task_pool.start(1); diff --git a/sunshine/main.h b/sunshine/main.h index 48cbc62f..aa9558b3 100644 --- a/sunshine/main.h +++ b/sunshine/main.h @@ -24,7 +24,7 @@ extern boost::log::sources::severity_logger fatal; void log_flush(); -void print_help(); +void print_help(const char *name); std::string read_file(const char *path); int write_file(const char *path, const std::string_view &contents);