Commit a6554f87 authored by whessev8's avatar whessev8

Adds a --help option and usage message listing all flags to V8.

Review URL: http://codereview.chromium.org/9420

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@702 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 1af131cb
......@@ -72,7 +72,7 @@ int main(int argc, char* argv[]) {
// alone JavaScript engines.
continue;
} else if (strncmp(str, "--", 2) == 0) {
printf("Warning: unknown flag %s.\n", str);
printf("Warning: unknown flag %s.\nTry --help for options\n", str);
} else if (strcmp(str, "-e") == 0 && i + 1 < argc) {
// Execute argument given to -e option directly
v8::HandleScope handle_scope;
......
......@@ -318,6 +318,9 @@ void Shell::RunShell() {
int Shell::Main(int argc, char* argv[]) {
i::FlagList::SetFlagsFromCommandLine(&argc, argv, true);
if (i::FLAG_help) {
return 1;
}
Initialize();
bool run_shell = (argc == 1);
Context::Scope context_scope(evaluation_context_);
......
......@@ -200,6 +200,7 @@ DEFINE_string(testing_serialization_file, "/tmp/serdes",
// Dev shell flags
//
DEFINE_bool(help, false, "Print usage message, including flags, on console")
DEFINE_bool(dump_counters, false, "Dump counters on exit")
//
......
......@@ -317,7 +317,8 @@ int FlagList::SetFlagsFromCommandLine(int* argc,
// sense there.
continue;
} else {
fprintf(stderr, "Error: unrecognized flag %s\n", arg);
fprintf(stderr, "Error: unrecognized flag %s\n"
"Try --help for options\n", arg);
return j;
}
}
......@@ -327,7 +328,8 @@ int FlagList::SetFlagsFromCommandLine(int* argc,
if (i < *argc) {
value = argv[i++];
} else {
fprintf(stderr, "Error: missing value for flag %s of type %s\n",
fprintf(stderr, "Error: missing value for flag %s of type %s\n"
"Try --help for options\n",
arg, Type2String(flag->type()));
return j;
}
......@@ -354,7 +356,8 @@ int FlagList::SetFlagsFromCommandLine(int* argc,
if ((flag->type() == Flag::TYPE_BOOL && value != NULL) ||
(flag->type() != Flag::TYPE_BOOL && is_bool) ||
*endp != '\0') {
fprintf(stderr, "Error: illegal value for flag %s of type %s\n",
fprintf(stderr, "Error: illegal value for flag %s of type %s\n"
"Try --help for options\n",
arg, Type2String(flag->type()));
return j;
}
......@@ -376,6 +379,9 @@ int FlagList::SetFlagsFromCommandLine(int* argc,
*argc = j;
}
if (FLAG_help) {
PrintHelp();
}
// parsed all flags successfully
return 0;
}
......@@ -447,10 +453,22 @@ void FlagList::ResetAllFlags() {
// static
void FlagList::PrintHelp() {
printf("Usage:\n");
printf(" shell [options] -e string\n");
printf(" execute string in V8\n");
printf(" shell [options] file1 file2 ... filek\n");
printf(" run JavaScript scripts in file1, file2, ..., filek\n");
printf(" shell [options]\n");
printf(" shell [options] --shell\n");
printf(" run an interactive JavaScript shell");
printf(" d8 [options] file\n");
printf(" d8 [options]\n");
printf(" run the new debugging shell\n\n");
printf("Options:\n");
for (size_t i = 0; i < num_flags; ++i) {
Flag* f = &flags[i];
char* value = ToString(f);
printf(" --%s (%s) type: %s default: %s\n",
printf(" --%s (%s)\n type: %s default: %s\n",
f->name(), f->comment(), Type2String(f->type()), value);
DeleteArray(value);
}
......
......@@ -150,10 +150,10 @@ int main(int argc, char** argv) {
// Print the usage if an error occurs when parsing the command line
// flags or if the help flag is set.
int result = i::FlagList::SetFlagsFromCommandLine(&argc, argv, true);
if (result > 0 || argc != 2 || i::FLAG_h) {
if (result > 0 || argc != 2 || i::FLAG_help) {
::printf("Usage: %s [flag] ... outfile\n", argv[0]);
i::FlagList::PrintHelp();
return !i::FLAG_h;
return !i::FLAG_help;
}
v8::V8::SetCounterFunction(counter_callback);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment