Skip to content
Browse files

JSify the README.

  • Loading branch information...
1 parent 71cc02c commit 77a5034f1f2172bbf7b18262d971462567bd3e8e @relistan committed Dec 6, 2012
Showing with 22 additions and 21 deletions.
  1. +22 −21 README.md
View
43 README.md
@@ -1,40 +1,41 @@
Troll.opt
=========
-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.
+A powerful-but-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. One line per opt: that's all you need. No chaining long
-series of commands together, no multiline parsing definitions.
+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:
+A simple single option defintion looks like this:
```javascript
-(new Troll).options(function(t) {
+(new Troll()).options(function(t) {
t.opt("word", "something to talk about", {default: 'cake'})
});
```
-Or, a slightly more complicated definition in Coffeescript that takes
+Or, a slightly more complicated definition that takes
three different arguments and defines a help banner:
-```coffeescript
+```javascript
Troll = require('troll').Troll
-opts = (new Troll).options (troll) ->
- 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'
+opts = (new Troll()).options(function(troll) {
+ 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' });
+});
```
This in turn will supply the following help document when the calling
-application is invoked with the help flag: `app.coffee --help`.
+application is invoked with the help flag: `app.js --help`.
```
-Usage: app.coffee [options]
+Usage: app.js [options]
A great program that everyone should run every day
--add, -d: Add some more awesome
--awesome, -a: Turn on the awesome (default: true)
@@ -45,24 +46,24 @@ Usage: app.coffee [options]
If we pass that a command line like:
```bash
-$ ./test.coffee --name="something" --add
+$ ./test.js --name="something" --add
```
or:
```bash
-$ ./test.coffee --name something --add
+$ ./test.js --name something --add
```
or:
```bash
-$ ./test.coffee -n something -d
+$ ./test.js -n something -d
```
If we then inspect the contents of `opts` as defined above we see:
-```coffeescript
+```javascript
{ name: 'something', add: true, awesome: true }
```

0 comments on commit 77a5034

Please sign in to comment.
Something went wrong with that request. Please try again.