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`.
This commit is contained in:
@@ -863,7 +863,7 @@ int parse(int argc, char *argv[]) {
|
|||||||
auto line = argv[x];
|
auto line = argv[x];
|
||||||
|
|
||||||
if(line == "--help"sv) {
|
if(line == "--help"sv) {
|
||||||
print_help();
|
print_help(*argv);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else if(*line == '-') {
|
else if(*line == '-') {
|
||||||
@@ -875,7 +875,7 @@ int parse(int argc, char *argv[]) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(apply_flags(line + 1)) {
|
if(apply_flags(line + 1)) {
|
||||||
print_help();
|
print_help(*argv);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -889,7 +889,7 @@ int parse(int argc, char *argv[]) {
|
|||||||
else {
|
else {
|
||||||
TUPLE_EL(var, 1, parse_option(line, line_end));
|
TUPLE_EL(var, 1, parse_option(line, line_end));
|
||||||
if(!var) {
|
if(!var) {
|
||||||
print_help();
|
print_help(*argv);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,9 +61,9 @@ BOOST_LOG_ATTRIBUTE_KEYWORD(severity, "Severity", int)
|
|||||||
|
|
||||||
This function prints output to stdout.
|
This function prints output to stdout.
|
||||||
*/
|
*/
|
||||||
void print_help() {
|
void print_help(const char *name) {
|
||||||
std::cout
|
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
|
<< " 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
|
<< " 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.
|
Calls the print_help function and then exits.
|
||||||
*/
|
*/
|
||||||
namespace help {
|
namespace help {
|
||||||
int entry(int argc, char *argv[]) {
|
int entry(const char *name, int argc, char *argv[]) {
|
||||||
print_help();
|
print_help(name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} // namespace help
|
} // namespace help
|
||||||
@@ -97,7 +97,7 @@ int entry(int argc, char *argv[]) {
|
|||||||
This function prints the version details to stdout and then exits.
|
This function prints the version details to stdout and then exits.
|
||||||
*/
|
*/
|
||||||
namespace version {
|
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;
|
std::cout << PROJECT_NAME << " version: v" << PROJECT_VER << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -120,9 +120,9 @@ void on_signal(int sig, FN &&fn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
namespace gen_creds {
|
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) {
|
if(argc < 2 || argv[0] == "help"sv || argv[1] == "help"sv) {
|
||||||
print_help();
|
print_help(name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,7 +132,7 @@ int entry(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
} // namespace gen_creds
|
} // namespace gen_creds
|
||||||
|
|
||||||
std::map<std::string_view, std::function<int(int argc, char **argv)>> cmd_to_func {
|
std::map<std::string_view, std::function<int(const char *name, int argc, char **argv)>> cmd_to_func {
|
||||||
{ "creds"sv, gen_creds::entry },
|
{ "creds"sv, gen_creds::entry },
|
||||||
{ "help"sv, help::entry },
|
{ "help"sv, help::entry },
|
||||||
{ "version"sv, version::entry }
|
{ "version"sv, version::entry }
|
||||||
@@ -229,7 +229,7 @@ int main(int argc, char *argv[]) {
|
|||||||
return 7;
|
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);
|
task_pool.start(1);
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ extern boost::log::sources::severity_logger<int> fatal;
|
|||||||
|
|
||||||
void log_flush();
|
void log_flush();
|
||||||
|
|
||||||
void print_help();
|
void print_help(const char *name);
|
||||||
|
|
||||||
std::string read_file(const char *path);
|
std::string read_file(const char *path);
|
||||||
int write_file(const char *path, const std::string_view &contents);
|
int write_file(const char *path, const std::string_view &contents);
|
||||||
|
|||||||
Reference in New Issue
Block a user