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.
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.