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] 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);