Commits

Joey Mazzarelli committed ae6abe6

Comments (0)

Files changed (1)

 == JS-OPTS ==
 
-js-opts is a library for parsing command line options in javascript. It works with node.js (http://www.nodejs.org). Grab the latest version and check out the examples below.
+js-opts is a library for parsing command line options in javascript. It works with node.js (http://www.nodejs.org). Grab the [[http://www.bitbucket.org/mazzarelli/js-opts/downloads/js-opts.zip|latest version here]] and check out the examples below.
 
 === Example ===
+
+Example 1
 {{{
 #!javascript
+/**
+ * Simple example with one optional parameter, including the help option.
+ *
+ * Examples:
+ *   $ node example1.js
+ *   
+ *   Example 1
+ *   $ node example1.js -v
+ *   > v1.0
+ *
+ *   $ node example1.js --version
+ *   > v1.0
+ *
+ *   $ node example1.js -version
+ *   > Unknown option: -version
+ *
+ *   $ node example1.js --help
+ *   > Show version and exit
+ *         -v, --version
+ *     Show this help message
+ *         --help
+ */
 
+var opts = require('./opts')
+  , puts = require('sys').puts;
+
+var options = [
+  { short       : 'v'
+  , long        : 'version'
+  , description : 'Show version and exit'
+  , callback    : function () { puts('v1.0'); process.exit(1); }
+  }
+];
+
+opts.parse(options, true);
+puts('Example 1');
+process.exit(0);
 
 }}}
 
-You can check out the source of this page to see how that's done, and make sure to bookmark [[http://pygments.org/docs/lexers/|the vast library of Pygment lexers]], we accept the 'short name' or the 'mimetype' of anything in there.