From d8ce98eb36653b6497f94bdbdd68428476e9ace0 Mon Sep 17 00:00:00 2001 From: Mike Dirolf Date: Thu, 9 Jul 2009 13:59:28 -0400 Subject: [PATCH] handle errors w/ options, nice helptext for no options --- db/db.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/db/db.cpp b/db/db.cpp index 056c1d21bbe..394969bb200 100644 --- a/db/db.cpp +++ b/db/db.cpp @@ -506,7 +506,6 @@ int main(int argc, char* argv[], char *envp[] ) bool removeService = false; bool startService = false; - /* TODO handle exceptions. */ po::variables_map params; /* don't allow guessing - creates ambiguities when some options are @@ -516,10 +515,16 @@ int main(int argc, char* argv[], char *envp[] ) po::command_line_style::allow_long_disguise ^ po::command_line_style::allow_sticky); - po::store(po::command_line_parser(argc, argv).options(cmdline_options). - positional(positional_options). - style(command_line_style).run(), params); - po::notify(params); + try { + po::store(po::command_line_parser(argc, argv).options(cmdline_options). + positional(positional_options). + style(command_line_style).run(), params); + po::notify(params); + } catch (po::error &e) { + cout << "ERROR: " << e.what() << endl << endl; + cout << visible_options << endl; + return 0; + } if (params.count("help")) { cout << visible_options << endl; @@ -694,6 +699,7 @@ int main(int argc, char* argv[], char *envp[] ) dbexit(0); } + cout << "To run mongod with the default options try 'mongod run'." << endl << endl; cout << visible_options << endl; return 0;