Skip to content

Commit a38fe7f

Browse files
author
Mike Dirolf
committed
minor: fix some bugs in arg handling
1 parent ee964dc commit a38fe7f

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

shell/dbshell.cpp

+15-6
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ int main(int argc, char* argv[]) {
153153
string script;
154154

155155
po::options_description shell_options("options");
156+
po::options_description hidden_options("Hidden options");
157+
po::options_description cmdline_options("Command line options");
156158
po::positional_options_description positional_options;
157159

158160
shell_options.add_options()
@@ -166,9 +168,16 @@ int main(int argc, char* argv[]) {
166168
("help,h", "show this usage information")
167169
;
168170

171+
hidden_options.add_options()
172+
("dbaddress", po::value<string>(), "dbaddress")
173+
("files", po::value< vector<string> >(), "files")
174+
;
175+
169176
positional_options.add("dbaddress", 1);
170177
positional_options.add("files", -1);
171178

179+
cmdline_options.add(shell_options).add(hidden_options);
180+
172181
if (argc >= 2) {
173182
po::variables_map params;
174183

@@ -180,14 +189,14 @@ int main(int argc, char* argv[]) {
180189
po::command_line_style::allow_sticky);
181190

182191
try {
183-
po::store(po::command_line_parser(argc, argv).options(shell_options).
192+
po::store(po::command_line_parser(argc, argv).options(cmdline_options).
184193
positional(positional_options).
185194
style(command_line_style).run(), params);
186195
po::notify(params);
187196
} catch (po::error &e) {
188197
cout << "ERROR: " << e.what() << endl << endl;
189198
show_help_text(argv[0], shell_options);
190-
return 0;
199+
return mongo::EXIT_BADOPTIONS;
191200
}
192201

193202
if (params.count("shell")) {
@@ -198,7 +207,7 @@ int main(int argc, char* argv[]) {
198207
}
199208
if (params.count("help")) {
200209
show_help_text(argv[0], shell_options);
201-
return 0;
210+
return mongo::EXIT_CLEAN;
202211
}
203212

204213
if (params.count("files")) {
@@ -213,14 +222,14 @@ int main(int argc, char* argv[]) {
213222
* - it contains no '.' after the last appearance of '\' or '/'
214223
* - it doesn't end in '.js' and it doesn't specify a path to an existing file */
215224
if (params.count("dbaddress")) {
216-
string dbaddress = params["dbaddress"].as< vector<string> >()[0];
225+
string dbaddress = params["dbaddress"].as<string>();
217226
if (nodb) {
218227
files.insert(files.begin(), dbaddress);
219228
} else {
220229
string basename = dbaddress.substr(dbaddress.find_last_of("/\\") + 1);
221230
path p(dbaddress);
222-
if (!basename.find_first_of('.') ||
223-
(!basename.find(".js", basename.size() - 3) && !boost::filesystem::exists(p))) {
231+
if (basename.find_first_of('.') == string::npos ||
232+
(basename.find(".js", basename.size() - 3) == string::npos && !boost::filesystem::exists(p))) {
224233
url = dbaddress;
225234
} else {
226235
files.insert(files.begin(), dbaddress);

0 commit comments

Comments
 (0)