diff options
author | Steve Engledow <steve.engledow@proxama.com> | 2011-07-05 15:07:08 +0400 |
---|---|---|
committer | koichik <koichik@improvement.jp> | 2011-07-16 10:24:36 +0400 |
commit | 292345fe626bc4185e8bb1c41bf3f859f48b3bd4 (patch) | |
tree | c681774ca8096ffed0ca1dbc51c5ea08a5910f28 /src | |
parent | 4662ace9165ae6d8aab06ba7ef3ffff4c971c859 (diff) |
Improve --help message and Fix -e/--eval switch
--help should at least give some hint that node takes the -e switch
Update help message to include -e and swap eval block with module load block so argv works correctly
[steve@sane node](master)$ ./node -e 'process.argv' foo bar
[ '/home/steve/code/node/node', 'foo', 'bar' ]
:)
Add simple test for -e option.
Fixes #1311.
Diffstat (limited to 'src')
-rw-r--r-- | src/node.cc | 5 | ||||
-rw-r--r-- | src/node.js | 24 |
2 files changed, 15 insertions, 14 deletions
diff --git a/src/node.cc b/src/node.cc index 78ac8a8e053..aca5f6a0e61 100644 --- a/src/node.cc +++ b/src/node.cc @@ -2241,11 +2241,12 @@ static void ParseDebugOpt(const char* arg) { } static void PrintHelp() { - printf("Usage: node [options] script.js [arguments] \n" - " node debug script.js [arguments] \n" + printf("Usage: node [options] [ -e script | script.js ] [arguments] \n" + " node debug [ -e script | script.js ] [arguments] \n" "\n" "Options:\n" " -v, --version print node's version\n" + " -e, --eval script evaluate script\n" " --v8-options print v8 command line options\n" " --vars print various compiled-in variables\n" " --max-stack-size=val set max v8 stack size (bytes)\n" diff --git a/src/node.js b/src/node.js index 8be85945ac8..e4a9de45e8c 100644 --- a/src/node.js +++ b/src/node.js @@ -65,6 +65,18 @@ var d = NativeModule.require('_debugger'); d.start(); + } else if (process._eval != null) { + // User passed '-e' or '--eval' arguments to Node. + var Module = NativeModule.require('module'); + var path = NativeModule.require('path'); + var cwd = process.cwd(); + + var module = new Module('eval'); + module.filename = path.join(cwd, 'eval'); + module.paths = Module._nodeModulePaths(cwd); + var rv = module._compile('return eval(process._eval)', 'eval'); + console.log(rv); + } else if (process.argv[1]) { // make process.argv[1] into a full path if (!(/^http:\/\//).exec(process.argv[1])) { @@ -78,18 +90,6 @@ // Main entry point into most programs: process.nextTick(Module.runMain); - } else if (process._eval != null) { - // User passed '-e' or '--eval' arguments to Node. - var Module = NativeModule.require('module'); - var path = NativeModule.require('path'); - var cwd = process.cwd(); - - var module = new Module('eval'); - module.filename = path.join(cwd, 'eval'); - module.paths = Module._nodeModulePaths(cwd); - var rv = module._compile('return eval(process._eval)', 'eval'); - console.log(rv); - } else { var binding = process.binding('stdio'); var fd = binding.openStdin(); |