Permalink
Browse files

use optimist to parse bin args, merge usage into bin/usage.txt

  • Loading branch information...
substack committed Mar 22, 2013
2 parents 7fbc21b + 8bffe3b commit b08390a432132870be8763a5a611340d1d5cc29b
Showing with 15 additions and 5 deletions.
  1. +5 −4 bin/bouncy.js
  2. +4 −0 bin/usage.txt
  3. +2 −1 package.json
  4. +4 −0 readme.markdown
View
@@ -1,6 +1,8 @@
#!/usr/bin/env node
-var configFile = process.argv[2];
-var port = parseInt(process.argv[3], 10);
+var argv = require('optimist').argv;
+var configFile = argv.config || argv._.shift();
+var port = parseInt(argv.port || argv._.shift(), 10);
+var address = argv.address || argv._.shift() || '0.0.0.0';
var fs = require('fs');
if (!configFile || !port) {
@@ -47,5 +49,4 @@ var server = bouncy(function (req, res, bounce) {
res.write('host not found\r\n');
res.end();
}
-});
-server.listen(port);
+}).listen(port, address);
View
@@ -17,3 +17,7 @@ colon-separated string to specify a host and port in a route.
Use `""` for the host as a default route.
+You can optionally specify a listen address as the third parameter or with
+`--address`. It defaults to `0.0.0.0`. Specify `::` to listen on both IPv4 and
+IPv6 addresses.
+
View
@@ -21,7 +21,8 @@
"test" : "tap test/*.js"
},
"dependencies" : {
- "through" : "~2.2.7"
+ "through": "~2.2.7",
+ "optimist": "~0.3.5"
},
"devDependencies" : {
"tap" : "~0.4.0",
View
@@ -95,6 +95,10 @@ The `routes.json` file should just map host names to host/port combos. Use a
colon-separated string to specify a host and port in a route.
Use `""` for the host as a default route.
+
+You can optionally specify a listen address as the third parameter or with
+`--address`. It defaults to `0.0.0.0`. Specify `::` to listen on both IPv4 and
+IPv6 addresses.
```
# install

0 comments on commit b08390a

Please sign in to comment.