From 656a1d5a1b7c0e49d72e80cb13f20671d56f76c6 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Wed, 1 Dec 2010 05:01:28 +0000 Subject: [PATCH] updated readme with .default() stuff --- README.markdown | 42 +++++++++++++++++++++++++++++++++++-- examples/default_hash.js | 10 +++++++++ examples/default_singles.js | 11 ++++++++++ package.json | 2 +- 4 files changed, 62 insertions(+), 3 deletions(-) create mode 100755 examples/default_hash.js create mode 100755 examples/default_singles.js diff --git a/README.markdown b/README.markdown index 88d143836..cd97358d5 100644 --- a/README.markdown +++ b/README.markdown @@ -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. ------------------------------------------------------------------- @@ -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: ------------------------------------------------- @@ -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 ============ diff --git a/examples/default_hash.js b/examples/default_hash.js new file mode 100755 index 000000000..800a4b335 --- /dev/null +++ b/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); diff --git a/examples/default_singles.js b/examples/default_singles.js new file mode 100755 index 000000000..45bb0ac81 --- /dev/null +++ b/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); diff --git a/package.json b/package.json index da2a6bdd1..bc33d5fba 100644 --- a/package.json +++ b/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",