Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Commit

Permalink
argparse -> nomnom
Browse files Browse the repository at this point in the history
  • Loading branch information
harthur committed Aug 25, 2010
1 parent ecdff84 commit 12001ad
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 36 deletions.
37 changes: 22 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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});
File renamed without changes.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
}
4 changes: 2 additions & 2 deletions test/argv.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var argparse = require("argparse"),
var nomnom = require("../lib/nomnom"),
sys = require("sys");

var opts = [
Expand All @@ -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();
4 changes: 2 additions & 2 deletions test/default.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var argparse = require("../lib/argparse"),
var nomnom = require("../lib/nomnom"),
assert = require("assert");

opts = [
Expand All @@ -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");
Expand Down
6 changes: 3 additions & 3 deletions test/help.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var argparse = require("argparse"),
var nomnom = require("../lib/nomnom"),
sys = require("sys"),
assert = require("assert");

Expand All @@ -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"));

Expand All @@ -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"));
4 changes: 2 additions & 2 deletions test/key.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var argparse = require("../lib/argparse"),
var nomnom = require("../lib/nomnom"),
assert = require("assert");

opts = [
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions test/long.js
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions test/positional.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var argparse = require("../lib/argparse"),
var nomnom = require("../lib/nomnom"),
assert = require("assert");


Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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");
Expand Down
6 changes: 3 additions & 3 deletions test/short.js
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 12001ad

Please sign in to comment.