Skip to content

Commit

Permalink
updated readme with .default() stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Dec 1, 2010
1 parent cd7f8c5 commit 656a1d5
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 3 deletions.
42 changes: 40 additions & 2 deletions README.markdown
Expand Up @@ -5,8 +5,7 @@ Optimist is a node.js library for option parsing for people who hate option
parsing. More specifically, this module is for people who like all the --bells
and -whistlz of program usage but think optstrings are a waste of time.

But all hope is not lost, dear reader, because there is Optimist, proving that
option parsing doesn't have to suck (as much).
With optimist, option parsing doesn't have to suck (as much).

With Optimist, the options are just a hash! No optstrings attached.
-------------------------------------------------------------------
Expand All @@ -27,6 +26,9 @@ xup.js:

$ ./xup.js --rif=55 --xup=9.52
Buy more riffiwobbles

$ ./xup.js --rif 55 --xup 9.52
Buy more riffiwobbles

But wait! There's more! You can do short options:
-------------------------------------------------
Expand Down Expand Up @@ -109,6 +111,42 @@ divide.js:
Usage: ./divide.js -x [num] -y [num]
Missing arguments: y

EVEN MORE HOLY COW
------------------

default_singles.js:
#!/usr/bin/env node
var argv = require('optimist')
.default('x', 10)
.default('y', 10)
.argv
;

var x = parseInt(argv.x, 10);
var y = parseInt(argv.y, 10);
console.log(x + y);

***

$ ./default_singles.js -x 5
15

default_hash.js:
#!/usr/bin/env node
var argv = require('optimist')
.default({ x : 10, y : 10 })
.argv
;

var x = parseInt(argv.x, 10);
var y = parseInt(argv.y, 10);
console.log(x + y);

***

$ ./default_hash.js -y 7
17

Installation
============

Expand Down
10 changes: 10 additions & 0 deletions examples/default_hash.js
@@ -0,0 +1,10 @@
#!/usr/bin/env node

var argv = require('optimist')
.default({ x : 10, y : 10 })
.argv
;

var x = parseInt(argv.x, 10);
var y = parseInt(argv.y, 10);
console.log(x + y);
11 changes: 11 additions & 0 deletions examples/default_singles.js
@@ -0,0 +1,11 @@
#!/usr/bin/env node

var argv = require('optimist')
.default('x', 10)
.default('y', 10)
.argv
;

var x = parseInt(argv.x, 10);
var y = parseInt(argv.y, 10);
console.log(x + y);
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name" : "optimist",
"version" : "0.1.0",
"version" : "0.1.1",
"description" : "Light-weight option parsing with an argv hash. No optstrings attached.",
"modules" : {
"index" : "./lib/optimist.js",
Expand Down

0 comments on commit 656a1d5

Please sign in to comment.