Permalink
Browse files

Add JS example in the README.md.

  • Loading branch information...
1 parent 7fa33d4 commit 71cc02cefdfa3024bff8eec2d52f44354977f3f8 @relistan committed Dec 5, 2012
Showing with 20 additions and 8 deletions.
  1. +20 −8 README.md
View
@@ -1,18 +1,30 @@
Troll.opt
=========
-A simple command line parser in CoffeeScript for Node applications inspired
-by William Morgan's outstanding [Trollop](http://trollop.rubyforge.org/)
-library for Ruby.
+A simple command line parser in CoffeeScript for Node.js apps inspired
+by William Morgan's awesome [Trollop](http://trollop.rubyforge.org/)
+gem for Ruby.
Troll.opt allows you to define and parse command line args in one simple
-definition.
+definition. One line per opt: that's all you need. No chaining long
+series of commands together, no multiline parsing definitions.
+
+A simple defintion in Javascript looks like this:
+
+```javascript
+(new Troll).options(function(t) {
+ t.opt("word", "something to talk about", {default: 'cake'})
+});
+```
+
+Or, a slightly more complicated definition in Coffeescript that takes
+three different arguments and defines a help banner:
```coffeescript
Troll = require('troll').Troll
opts = (new Troll).options (troll) ->
- troll.banner "A great program that everyone should run every day"
+ troll.banner "Totally rad app that does something cool"
troll.opt 'awesome', 'Turn on the awesome', default: true
troll.opt 'name', 'The name of the application', type: 'String', required: true
troll.opt 'add', 'Add some more awesome', short: 'd'
@@ -33,19 +45,19 @@ Usage: app.coffee [options]
If we pass that a command line like:
```bash
-$ coffee test.coffee --name="something" --add
+$ ./test.coffee --name="something" --add
```
or:
```bash
-$ coffee test.coffee --name something --add
+$ ./test.coffee --name something --add
```
or:
```bash
-$ coffee test.coffee -n something -d
+$ ./test.coffee -n something -d
```
If we then inspect the contents of `opts` as defined above we see:

0 comments on commit 71cc02c

Please sign in to comment.