From f03c3203a1acc048b413820ef4f792bc385413cd Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Mon, 3 Sep 2012 16:42:18 +0200 Subject: [PATCH] cli: make -p equivalent to -pe Fixes #3938. --- src/node.cc | 16 +++++++--------- test/simple/test-cli-eval.js | 2 +- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/node.cc b/src/node.cc index 05eb42a5f9..cb5b25bcc9 100644 --- a/src/node.cc +++ b/src/node.cc @@ -2384,20 +2384,18 @@ static void ParseArgs(int argc, char **argv) { } else if (strcmp(arg, "--help") == 0 || strcmp(arg, "-h") == 0) { PrintHelp(); exit(0); - } else if (strcmp(arg, "--eval") == 0 || strcmp(arg, "-e") == 0 || - strcmp(arg, "-pe") == 0) { + } else if (strcmp(arg, "--eval") == 0 || + strcmp(arg, "-e") == 0 || + strcmp(arg, "--print") == 0 || + strcmp(arg, "-pe") == 0 || + strcmp(arg, "-p") == 0) { if (argc <= i + 1) { - fprintf(stderr, "Error: --eval requires an argument\n"); + fprintf(stderr, "Error: %s requires an argument\n", arg); exit(1); } - if (arg[1] == 'p') { - print_eval = true; - } + print_eval = print_eval || strchr(arg, 'p') != NULL; argv[i] = const_cast(""); eval_string = argv[++i]; - } else if (strcmp(arg, "--print") == 0 || strcmp(arg, "-p") == 0) { - print_eval = true; - argv[i] = const_cast(""); } else if (strcmp(arg, "--interactive") == 0 || strcmp(arg, "-i") == 0) { force_repl = true; argv[i] = const_cast(""); diff --git a/test/simple/test-cli-eval.js b/test/simple/test-cli-eval.js index 7e3e0cd6e3..236c990491 100644 --- a/test/simple/test-cli-eval.js +++ b/test/simple/test-cli-eval.js @@ -48,7 +48,7 @@ child.exec(nodejs + ' --eval "console.error(42)"', }); // assert that the expected output is written to stdout -['--print --eval', '-p -e', '-pe'].forEach(function(s) { +'--print -pe -p'.split(' ').forEach(function(s) { var cmd = nodejs + ' ' + s + ' '; child.exec(cmd + '42',