Skip to content
This repository
Browse code

Remove '--' from command line parsing

  • Loading branch information...
commit 2916a2acd45a0d828c550be3f31e61022974cf18 1 parent a0c48ee
Jeremy Ashkenas jashkenas authored ry committed

Showing 2 changed files with 14 additions and 13 deletions. Show diff stats Hide diff stats

  1. +1 0  AUTHORS
  2. +13 13 src/node.cc
1  AUTHORS
@@ -51,3 +51,4 @@ Michael Stillwell <mjs@beebo.org>
51 51 Yuichiro MASUI <masui@masuidrive.jp>
52 52 Mark Hansen <mark@markhansen.co.nz>
53 53 Zoran Tomicic <ztomicic@gmail.com>
  54 +Jeremy Ashkenas <jashkenas@gmail.com>
26 src/node.cc
@@ -60,7 +60,7 @@ static Persistent<String> listeners_symbol;
60 60 static Persistent<String> uncaught_exception_symbol;
61 61 static Persistent<String> emit_symbol;
62 62
63   -static int dash_dash_index = 0;
  63 +static int option_end_index = 0;
64 64 static bool use_debug_agent = false;
65 65
66 66
@@ -951,9 +951,9 @@ static void Load(int argc, char *argv[]) {
951 951
952 952 // process.argv
953 953 int i, j;
954   - Local<Array> arguments = Array::New(argc - dash_dash_index + 1);
  954 + Local<Array> arguments = Array::New(argc - option_end_index + 1);
955 955 arguments->Set(Integer::New(0), String::New(argv[0]));
956   - for (j = 1, i = dash_dash_index + 1; i < argc; j++, i++) {
  956 + for (j = 1, i = option_end_index + 1; i < argc; j++, i++) {
957 957 Local<String> arg = String::New(argv[i]);
958 958 arguments->Set(Integer::New(j), arg);
959 959 }
@@ -1078,7 +1078,7 @@ static void Load(int argc, char *argv[]) {
1078 1078 }
1079 1079
1080 1080 static void PrintHelp() {
1081   - printf("Usage: node [options] [--] script.js [arguments] \n"
  1081 + printf("Usage: node [options] script.js [arguments] \n"
1082 1082 " -v, --version print node's version\n"
1083 1083 " --debug enable remote debugging\n" // TODO specify port
1084 1084 " --cflags print pre-processor and compiler flags\n"
@@ -1092,13 +1092,10 @@ static void ParseArgs(int *argc, char **argv) {
1092 1092 // TODO use parse opts
1093 1093 for (int i = 1; i < *argc; i++) {
1094 1094 const char *arg = argv[i];
1095   - if (strcmp(arg, "--") == 0) {
1096   - dash_dash_index = i;
1097   - break;
1098   - } else if (strcmp(arg, "--debug") == 0) {
  1095 + if (strcmp(arg, "--debug") == 0) {
1099 1096 argv[i] = reinterpret_cast<const char*>("");
1100 1097 use_debug_agent = true;
1101   - dash_dash_index = i;
  1098 + option_end_index = i;
1102 1099 } else if (strcmp(arg, "--version") == 0 || strcmp(arg, "-v") == 0) {
1103 1100 printf("%s\n", NODE_VERSION);
1104 1101 exit(0);
@@ -1110,7 +1107,10 @@ static void ParseArgs(int *argc, char **argv) {
1110 1107 exit(0);
1111 1108 } else if (strcmp(arg, "--v8-options") == 0) {
1112 1109 argv[i] = reinterpret_cast<const char*>("--help");
1113   - dash_dash_index = i+1;
  1110 + option_end_index = i+1;
  1111 + } else if (argv[i][0] != '-') {
  1112 + option_end_index = i-1;
  1113 + break;
1114 1114 }
1115 1115 }
1116 1116 }
@@ -1121,9 +1121,9 @@ static void ParseArgs(int *argc, char **argv) {
1121 1121 int main(int argc, char *argv[]) {
1122 1122 // Parse a few arguments which are specific to Node.
1123 1123 node::ParseArgs(&argc, argv);
1124   - // Parse the rest of the args (up to the 'dash_dash_index' (where '--' was
  1124 + // Parse the rest of the args (up to the 'option_end_index' (where '--' was
1125 1125 // in the command line))
1126   - V8::SetFlagsFromCommandLine(&node::dash_dash_index, argv, false);
  1126 + V8::SetFlagsFromCommandLine(&node::option_end_index, argv, false);
1127 1127
1128 1128 // Error out if we don't have a script argument.
1129 1129 if (argc < 2) {
@@ -1144,7 +1144,7 @@ int main(int argc, char *argv[]) {
1144 1144 // watchers. In this way it can check if the 'tick' has other pending
1145 1145 // watchers by using ev_pending_count() - if it ran with lower priority
1146 1146 // then the other watchers might run before it - not giving us good idea
1147   - // of loop idleness.
  1147 + // of loop idleness.
1148 1148 ev_set_priority(&node::gc_timer, EV_MAXPRI);
1149 1149 ev_timer_start(EV_DEFAULT_UC_ &node::gc_timer);
1150 1150 ev_unref(EV_DEFAULT_UC);

0 comments on commit 2916a2a

Please sign in to comment.
Something went wrong with that request. Please try again.