Argument parsing works when node is started with explicit path #9

Merged
merged 1 commit into from May 11, 2011

3 participants

@tikonen

First argument is recognized correctly as "node" binary when started with explicit path

Example script myscript.js

cli = require('cli')
console.log(cli.argv)

Before change

$ node example.js 
[]
$ node example.js teemu ikonen
[ 'teemu', 'ikonen' ]
$ /usr/local/bin/node example.js teemu ikonen
[ '/tmp/example.js', 'teemu', 'ikonen' ]

Now

$ node example.js 
[]
$ node example.js teemu ikonen
[ 'teemu', 'ikonen' ]
$ /usr/local/bin/node example.js teemu ikonen
[ 'teemu', 'ikonen' ]
@tikonen tikonen First argument is recognized correctly as "node" binary when started …
…with explicit path e.g. /to/some/path/node myscript.js
da16289
@chriso

Awesome thanks

@chriso chriso closed this May 11, 2011
@chriso chriso merged commit 99e9a5c into node-js-libs:master May 11, 2011
@jsen-

But what if the first argument is not 'node' binary at all?
Sometimes during the development I'm running my scripts with node-dev as the node executable, and in this case cli does not cooperate.

my proposal is to alter cli.setArgv method as follows:

  if (process.execPath === cli.app) {
    cli.app = arr.shift();
   }
@chriso chriso added a commit that referenced this pull request Apr 10, 2012
@chriso chriso Use process.execPath, re #9 919ee05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment