Browse files

argparse -> nomnom

  • Loading branch information...
1 parent ecdff84 commit 12001ad3d1688b88f905623c13670145d71eebf0 @harthur committed Aug 25, 2010
Showing with 43 additions and 36 deletions.
  1. +22 −15 README.md
  2. 0 lib/{argparse.js → nomnom.js}
  3. +3 −3 package.json
  4. +2 −2 test/argv.js
  5. +2 −2 test/default.js
  6. +3 −3 test/help.js
  7. +2 −2 test/key.js
  8. +3 −3 test/long.js
  9. +3 −3 test/positional.js
  10. +3 −3 test/short.js
View
37 README.md
@@ -1,7 +1,7 @@
-# argparse
-argparse is a small option parser for CommonJS.
+# nomnom
+nomnom is a small option parser for CommonJS. It just parses your args and gives them back to you in a hash.
- var argparse = require("argparse");
+ var nomnom = require("nomnom");
var opts = [
{ name: 'config',
@@ -13,35 +13,42 @@ argparse is a small option parser for CommonJS.
{ name: 'debug',
string: '-d'}
];
-
- var parser = new argparse.ArgParser(opts);
+
+ var parser = new nomnom.ArgParser(opts);
var options = parser.parse();
if(options.debug)
// do stuff
-
+
# Install
for [node.js](http://nodejs.org/) and [npm](http://github.com/isaacs/npm):
- git clone http://github.com/harthur/argparse
- cd argparse
+ git clone http://github.com/harthur/nomnomargs
+ cd nomnomargs
npm install .
# More Details
-By default, argparse parses [node](http://nodejs.org/)'s `process.argv`. You can also pass in the args:
+By default, nomnom parses [node](http://nodejs.org/)'s `process.argv`. You can also pass in the args:
var options = parser.parse(["-xvf", "--atomic=true"])
-All parsed arguments that don't follow the form '-a' or '--atomic' and can't be attached to an option are positional and can be matched on via the `position`:
+All parsed arguments that don't fit the `-a` or `--atomic' format and aren't attached to an option are positional and can be matched on via the `position`:
var opts = [
{ name: 'filename',
- position: 0,
- default: 'test.js'},
+ position: 0
+ }
];
- var parser = new argparse.ArgParser(opts);
+ var parser = new nomnom.ArgParser(opts);
var options = parser.parse();
sys.puts(options.filename);
-Argparse prints out a usage message if `--help` or `-h` is an argument. You can disable this with the `printHelp` flag and specify the printing function with `printFunc` if you're not using node:
+You don't even have to specify anything if you don't want to:
+ var parser = new nomnom.ArgParser();
+ var options = parser.parse();
+
+ var url = options[0]; // get the first positional arg
+ var debug = options.debug // see if --debug was specified
+
+Nomnom prints out a usage message if `--help` or `-h` is an argument. You can disable this with the `printHelp` flag and specify the printing function with `printFunc` if you're not using node:
- var parser = new argparse.ArgParser(opts, {printHelp: false});
+ var parser = new nomnom.ArgParser(opts, {printHelp: false});
View
0 lib/argparse.js → lib/nomnom.js
File renamed without changes.
View
6 package.json
@@ -1,14 +1,14 @@
{
- "name": "argparse",
+ "name": "nomnom",
"description": "Small option parser that doesn't try to do anything",
"version": "0.1.0",
"author": "Heather Arthur <fayearthur@gmail.com>",
"repository": {
"type": "git",
- "url": "http://github.com/harthur/argparse.git"
+ "url": "http://github.com/harthur/nomnomargs.git"
},
"directories": {
"lib": "./lib"
},
- "main": "./lib/argparse"
+ "main": "./lib/nomnom"
}
View
4 test/argv.js
@@ -1,4 +1,4 @@
-var argparse = require("argparse"),
+var nomnom = require("../lib/nomnom"),
sys = require("sys");
var opts = [
@@ -11,7 +11,7 @@ var opts = [
{ name: 'logfile',
string: '-l LOG'}
];
-var parser = new argparse.ArgParser(opts, {printHelp: true, printFunc : function(msg) {
+var parser = new nomnom.ArgParser(opts, {printHelp: true, printFunc : function(msg) {
sys.puts("heeeeeeeeeeeelp" + msg);
}});
parser.parse();
View
4 test/default.js
@@ -1,4 +1,4 @@
-var argparse = require("../lib/argparse"),
+var nomnom = require("../lib/nomnom"),
assert = require("assert");
opts = [
@@ -21,7 +21,7 @@ opts = [
}
];
-var parser = new argparse.ArgParser(opts);
+var parser = new nomnom.ArgParser(opts);
var options = parser.parse(["-c", "other.json", "--debug=false"]);
assert.equal(options.config, "other.json");
View
6 test/help.js
@@ -1,4 +1,4 @@
-var argparse = require("argparse"),
+var nomnom = require("../lib/nomnom"),
sys = require("sys"),
assert = require("assert");
@@ -16,7 +16,7 @@ var opts = [
{ name: 'logfile',
string: '-l LOG'}
];
-var parser = new argparse.ArgParser(opts);
+var parser = new nomnom.ArgParser(opts);
assert.equal(strip(parser.helpString()), strip("usage:<script>[options]\
options:-c,--config=PATHJSONconfigwithtestinfo-lLOG"));
@@ -34,6 +34,6 @@ var opts = [
position: 1}
];
-var parser = new argparse.ArgParser(opts);
+var parser = new nomnom.ArgParser(opts);
assert.equal(strip(parser.helpString()), strip("usage: <script> aname0\
aname1 aname2 [options]options:-d"));
View
4 test/key.js
@@ -1,4 +1,4 @@
-var argparse = require("../lib/argparse"),
+var nomnom = require("../lib/nomnom"),
assert = require("assert");
opts = [
@@ -13,7 +13,7 @@ opts = [
}
];
-var parser = new argparse.ArgParser(opts);
+var parser = new nomnom.ArgParser(opts);
var options = parser.parse(["-a", "--config", "--bkey"]);
assert.ok(options.aname);
View
6 test/long.js
@@ -1,8 +1,8 @@
-var argparse = require("../lib/argparse"),
+var nomnom = require("../lib/nomnom"),
assert = require("assert");
-var parser = new argparse.ArgParser();
+var parser = new nomnom.ArgParser();
var options = parser.parse(["--atomic"]);
assert.ok(options.atomic);
@@ -17,7 +17,7 @@ opts = [
},
];
-var parser = new argparse.ArgParser(opts);
+var parser = new nomnom.ArgParser(opts);
var options = parser.parse(["--atomic","--config"]);
assert.ok(options.atomic);
View
6 test/positional.js
@@ -1,4 +1,4 @@
-var argparse = require("../lib/argparse"),
+var nomnom = require("../lib/nomnom"),
assert = require("assert");
@@ -29,7 +29,7 @@ var opts = [
}
];
-parser = new argparse.ArgParser(opts);
+parser = new nomnom.ArgParser(opts);
// mix args w/ values with positional args
var options = parser.parse(["-l", "temp.log", "-c", "12", "-a", "test0.js",
@@ -57,7 +57,7 @@ assert.equal(options.test1, "def1");
assert.ok(!options.test2);
// positionals that weren't specified in opts
-parser = new argparse.ArgParser([]);
+parser = new nomnom.ArgParser([]);
options = parser.parse(["pos1", "pos2", "pos3"]);
assert.equal(options[0], "pos1");
assert.equal(options[1], "pos2");
View
6 test/short.js
@@ -1,7 +1,7 @@
-var argparse = require("../lib/argparse"),
+var nomnom = require("../lib/nomnom"),
assert = require("assert");
-var parser = new argparse.ArgParser();
+var parser = new nomnom.ArgParser();
var options = parser.parse(["-cxf"]);
assert.ok(options.c);
@@ -15,7 +15,7 @@ var opts = [
}
];
-parser = new argparse.ArgParser(opts);
+parser = new nomnom.ArgParser(opts);
var options = parser.parse(["-l"]);
assert.ok(options.logfile);

0 comments on commit 12001ad

Please sign in to comment.