diff options
author | Mike Dirolf <mike@10gen.com> | 2009-08-07 16:02:56 -0400 |
---|---|---|
committer | Mike Dirolf <mike@10gen.com> | 2009-08-07 16:02:56 -0400 |
commit | a38fe7f2f233fe6c83fffb167476596cbc5eaf3c (patch) | |
tree | 484e6d410e86c8b96c051af51e4db3d4a8a3bf3c | |
parent | ee964dcbc9758c1a4c1831ad574a98f41f071a9e (diff) | |
download | mongo-a38fe7f2f233fe6c83fffb167476596cbc5eaf3c.tar.gz |
minor: fix some bugs in arg handling
-rw-r--r-- | shell/dbshell.cpp | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/shell/dbshell.cpp b/shell/dbshell.cpp index ee4156b877b..dcffec7a045 100644 --- a/shell/dbshell.cpp +++ b/shell/dbshell.cpp @@ -153,6 +153,8 @@ int main(int argc, char* argv[]) { string script; po::options_description shell_options("options"); + po::options_description hidden_options("Hidden options"); + po::options_description cmdline_options("Command line options"); po::positional_options_description positional_options; shell_options.add_options() @@ -166,9 +168,16 @@ int main(int argc, char* argv[]) { ("help,h", "show this usage information") ; + hidden_options.add_options() + ("dbaddress", po::value<string>(), "dbaddress") + ("files", po::value< vector<string> >(), "files") + ; + positional_options.add("dbaddress", 1); positional_options.add("files", -1); + cmdline_options.add(shell_options).add(hidden_options); + if (argc >= 2) { po::variables_map params; @@ -180,14 +189,14 @@ int main(int argc, char* argv[]) { po::command_line_style::allow_sticky); try { - po::store(po::command_line_parser(argc, argv).options(shell_options). + 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; show_help_text(argv[0], shell_options); - return 0; + return mongo::EXIT_BADOPTIONS; } if (params.count("shell")) { @@ -198,7 +207,7 @@ int main(int argc, char* argv[]) { } if (params.count("help")) { show_help_text(argv[0], shell_options); - return 0; + return mongo::EXIT_CLEAN; } if (params.count("files")) { @@ -213,14 +222,14 @@ int main(int argc, char* argv[]) { * - it contains no '.' after the last appearance of '\' or '/' * - it doesn't end in '.js' and it doesn't specify a path to an existing file */ if (params.count("dbaddress")) { - string dbaddress = params["dbaddress"].as< vector<string> >()[0]; + string dbaddress = params["dbaddress"].as<string>(); if (nodb) { files.insert(files.begin(), dbaddress); } else { string basename = dbaddress.substr(dbaddress.find_last_of("/\\") + 1); path p(dbaddress); - if (!basename.find_first_of('.') || - (!basename.find(".js", basename.size() - 3) && !boost::filesystem::exists(p))) { + if (basename.find_first_of('.') == string::npos || + (basename.find(".js", basename.size() - 3) == string::npos && !boost::filesystem::exists(p))) { url = dbaddress; } else { files.insert(files.begin(), dbaddress); |