Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

'parseArgs' -> 'parse'

  • Loading branch information...
commit 034e3f36c7cd4a0edd6484f03df9c23b0f211f9d 1 parent 1b4585c
@harthur authored
View
12 README.md
@@ -22,7 +22,7 @@ var options = require("nomnom")
}
}
})
- .parseArgs();
+ .parse();
if (options.debug)
// do stuff
@@ -31,7 +31,7 @@ if (options.debug)
You don't have to specify anything if you don't want to:
```javascript
-var options = require("nomnom").parseArgs();
+var options = require("nomnom").parse();
var url = options[0]; // get the first positional arg
var file = options.file // see if --file was specified
@@ -84,7 +84,7 @@ parser.command('sanity')
})
.help("run the sanity tests")
-parser.parseArgs();
+parser.parse();
```
Each command generates its own usage message when `-h` or `--help` is specified with the command.
@@ -111,7 +111,7 @@ var options = require("nomnom")
flag: true,
help: "Print debugging info"
}
- }).parseArgs();
+ }).parse();
```
...would look like this:
@@ -249,12 +249,12 @@ Takes a command name and gives you a command object on which you can chain comma
Gives a command object that will be used when no command is called.
-#### parseArgs
+#### parse
Parses node's `process.argv` and returns the parsed options hash. You can also provide argv:
```javascript
-var options = nomnom.parseArgs(["-xvf", "--atomic=true"])
+var options = nomnom.parse(["-xvf", "--atomic=true"])
```
# Command interface
View
8 nomnom.js
@@ -69,6 +69,7 @@ ArgParser.prototype = {
},
scriptName : function(script) {
+ // old API
return this.script(script);
},
@@ -76,8 +77,13 @@ ArgParser.prototype = {
this._help = help;
return this;
},
-
+
parseArgs : function(argv) {
+ // old API
+ return this.parse(argv);
+ },
+
+ parse : function(argv) {
this.print = this.print || function(str) {
console.log(str);
process.exit(0);
View
4 test/callback.js
@@ -9,7 +9,7 @@ exports.testVersion = function(test) {
test.equal(date, "2010-02-03", "date should match value")
}
}
- }).parseArgs(["--date=2010-02-03"]);
+ }).parse(["--date=2010-02-03"]);
test.done();
}
@@ -29,5 +29,5 @@ exports.testReturnString = function(test) {
test.equal(0, string.indexOf("v0.3"))
test.done();
})
- .parseArgs(["--version"]);
+ .parse(["--version"]);
}
View
14 test/commands.js
@@ -15,7 +15,7 @@ exports.testCallback = function(test) {
test.ok(false, "callback for other command shouldn't be called");
});
- parser.parseArgs(["run","-v", "3"]);
+ parser.parse(["run","-v", "3"]);
test.done();
}
@@ -31,7 +31,7 @@ exports.testMissingCommand = function(test) {
test.done();
});
- parser.parseArgs(["other"]);
+ parser.parse(["other"]);
}
exports.testNoCommand = function(test) {
@@ -52,7 +52,7 @@ exports.testNoCommand = function(test) {
parser.command('run');
- var options = parser.parseArgs(["--version"]);
+ var options = parser.parse(["--version"]);
test.strictEqual(options.version, true);
test.done();
@@ -94,19 +94,19 @@ exports.testUsage = function(test) {
parser.printer(function(string) {
test.equal(strip(string), "testusage");
});
- parser.parseArgs(["test", "-h"]);
+ parser.parse(["test", "-h"]);
parser = createParser();
parser.printer(function(string) {
test.equal(strip(string), "usage:testrun[options]options:--debug--filefiletorunrunall");
});
- parser.parseArgs(["run", "-h"]);
+ parser.parse(["run", "-h"]);
parser = createParser();
parser.printer(function(string) {
test.equal(strip(string), "usage:test<command>[options]commandoneof:run,testoptions:--debug--verbosenocommand");
});
- parser.parseArgs(["-h"]);
+ parser.parse(["-h"]);
parser = createParser();
parser.nocommand()
@@ -114,7 +114,7 @@ exports.testUsage = function(test) {
parser.printer(function(string) {
test.equal(strip(string), "fallback");
});
- parser.parseArgs(["-h"]);
+ parser.parse(["-h"]);
test.done();
}
View
8 test/expected.js
@@ -21,7 +21,7 @@ exports.testFlag = function(test) {
test.equal(0, string.indexOf("'--key1' expects a value"))
test.done();
})
- .parseArgs(["--key1"]);
+ .parse(["--key1"]);
}
exports.testRequired = function(test) {
@@ -36,7 +36,7 @@ exports.testRequired = function(test) {
test.equal(0, string.indexOf("file argument is required"))
test.done();
})
- .parseArgs([]);
+ .parse([]);
}
exports.testChoices = function(test) {
@@ -51,9 +51,9 @@ exports.testChoices = function(test) {
test.equal(0, string.indexOf("color must be one of: green, blue"))
});
- parser.parseArgs(['--color', 'red']);
+ parser.parse(['--color', 'red']);
- var options = parser.parseArgs(['--color', 'green']);
+ var options = parser.parse(['--color', 'green']);
test.equal(options.color, 'green');
test.done();
}
View
6 test/matching.js
@@ -40,7 +40,7 @@ var opts = {
var parser = nomnom().opts(opts);
exports.testPositional = function(test) {
- var options = parser.parseArgs(["--flag1", "val1", "--config", "file", "val2"]);
+ var options = parser.parse(["--flag1", "val1", "--config", "file", "val2"]);
test.equal(options.pos1, "val1");
test.equal(options.pos2, "val2");
@@ -49,7 +49,7 @@ exports.testPositional = function(test) {
}
exports.testAbbr = function(test) {
- var options = parser.parseArgs(["-d", "yes", "--num-lines", "3"]);
+ var options = parser.parse(["-d", "yes", "--num-lines", "3"]);
test.equal(options.debug, "yes")
test.equal(options.numLines, 3)
@@ -57,7 +57,7 @@ exports.testAbbr = function(test) {
}
exports.testString = function(test) {
- var options = parser.parseArgs(["-k", "val", "--config=test.js",
+ var options = parser.parse(["-k", "val", "--config=test.js",
"--key2", "val2", "--key3", "val3", "--key4=val4", "-v", "v0.3"]);
test.equal(options.version, "v0.3")
View
10 test/usage.js
@@ -39,7 +39,7 @@ exports.testH = function(test) {
test.equal(strip(string), expected)
test.done();
})
- .parseArgs(["-h"]);
+ .parse(["-h"]);
}
exports.testHelp = function(test) {
@@ -49,7 +49,7 @@ exports.testHelp = function(test) {
test.equal(strip(string), expected)
test.done();
})
- .parseArgs(["--help"]);
+ .parse(["--help"]);
}
exports.testScriptName = function(test) {
@@ -61,7 +61,7 @@ exports.testScriptName = function(test) {
test.equal(strip(string),"usage:test")
test.done();
})
- .parseArgs(["-h"]);
+ .parse(["-h"]);
}
exports.testUsage = function(test) {
@@ -73,7 +73,7 @@ exports.testUsage = function(test) {
test.equal(string, "test usage")
test.done();
})
- .parseArgs(["--help"]);
+ .parse(["--help"]);
}
exports.testHidden = function(test) {
@@ -89,5 +89,5 @@ exports.testHidden = function(test) {
test.equal(strip("usage:test[options]options:"), strip(string))
test.done();
})
- .parseArgs(["-h"]);
+ .parse(["-h"]);
}
View
6 test/values.js
@@ -32,7 +32,7 @@ var opts = {
var parser = nomnom().opts(opts);
exports.testFlag = function(test) {
- var options = parser.parseArgs(["--debug", "pos0", "--no-verbose"]);
+ var options = parser.parse(["--debug", "pos0", "--no-verbose"]);
test.strictEqual(options.debug, true);
test.strictEqual(options.verbose, false);
@@ -42,7 +42,7 @@ exports.testFlag = function(test) {
}
exports.testList = function(test) {
- var options = parser.parseArgs(["pos0", "pos1", "--list1=val0", "--list2", "val1",
+ var options = parser.parse(["pos0", "pos1", "--list1=val0", "--list2", "val1",
"--list2", "val2", "pos2"]);
test.deepEqual(options.list1, ["val0"]);
@@ -52,7 +52,7 @@ exports.testList = function(test) {
}
exports.testDefault = function(test) {
- var options = parser.parseArgs(["--def2", "val2", "--def3", "val3"]);
+ var options = parser.parse(["--def2", "val2", "--def3", "val3"]);
test.strictEqual(options.def1, "val1");
test.strictEqual(options.def2, "val2");
Please sign in to comment.
Something went wrong with that request. Please try again.