Browse files

Add JS example in the

  • Loading branch information...
1 parent 7fa33d4 commit 71cc02cefdfa3024bff8eec2d52f44354977f3f8 @relistan committed Dec 5, 2012
Showing with 20 additions and 8 deletions.
  1. +20 −8
@@ -1,18 +1,30 @@
-A simple command line parser in CoffeeScript for Node applications inspired
-by William Morgan's outstanding [Trollop](
-library for Ruby.
+A simple command line parser in CoffeeScript for Node.js apps inspired
+by William Morgan's awesome [Trollop](
+gem for Ruby.
Troll.opt allows you to define and parse command line args in one simple
+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:
+(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:
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: [options]
If we pass that a command line like:
-$ coffee --name="something" --add
+$ ./ --name="something" --add
-$ coffee --name something --add
+$ ./ --name something --add
-$ coffee -n something -d
+$ ./ -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.