Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
add option description on --help
Browse files Browse the repository at this point in the history
... and don't crash on invalid option
  • Loading branch information
weigon committed Jun 14, 2018
1 parent 8a9cfcf commit ef162e8
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/mock_server/src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
#endif
#endif

constexpr unsigned kHelpScreenWidth = 72;
constexpr unsigned kHelpScreenIndent = 8;

struct MysqlServerMockConfig {
std::string queries_filename;
std::string module_prefix;
Expand Down Expand Up @@ -80,7 +83,12 @@ class MysqlServerMockFrontend {
std::string get_help() {
std::stringstream os;

for (auto line: arg_handler_.usage_lines("Usage: " + program_name_, "", 80)) {
for (auto line: arg_handler_.usage_lines("Usage: " + program_name_, "", kHelpScreenWidth)) {
os << line << std::endl;
}

os << "\nOptions:" << std::endl;
for (auto line: arg_handler_.option_descriptions(kHelpScreenWidth, kHelpScreenIndent)) {
os << line << std::endl;
}

Expand Down Expand Up @@ -249,17 +257,17 @@ int main(int argc, char* argv[]) {
#endif

std::vector<std::string> arguments { argv, argv + argc };
auto frontend_config = frontend.init_from_arguments(arguments);
try {
auto frontend_config = frontend.init_from_arguments(arguments);

if (frontend.is_print_and_exit()) {
return 0;
}
if (frontend.is_print_and_exit()) {
return 0;
}

try {
frontend.run();
}
catch (const std::exception& e) {
std::cout << "MySQLServerMock ERROR: " << e.what() << std::endl;
std::cout << "ERROR: " << e.what() << std::endl;
return -1;
}

Expand Down

0 comments on commit ef162e8

Please sign in to comment.