Comparing version
@@ -51,4 +51,6 @@ var optimist = require('optimist'); | ||
handler(req,res,next) | ||
return | ||
} | ||
} | ||
next(); | ||
}) | ||
@@ -63,4 +65,6 @@ } | ||
handler(req,res,next) | ||
return; | ||
} | ||
} | ||
next(); | ||
}) | ||
@@ -166,3 +170,3 @@ } | ||
res = res || new CLIResponse(); | ||
if (this.middleware) { | ||
if (this.middleware.length) { | ||
var i = 1, $this = this; | ||
@@ -169,0 +173,0 @@ this.middleware[0](req,res,function next() { |
@@ -5,3 +5,3 @@ { | ||
"author": "bradleymeck", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"keywords": ["CLI"], | ||
@@ -12,5 +12,6 @@ "dependencies": { | ||
"prompt": "0.1.x", | ||
"cliff": "0.1.x" | ||
"cliff": "0.1.x", | ||
"winston": "0.3.x" | ||
}, | ||
"main": "lib/clip.js" | ||
} |
@@ -0,1 +1,79 @@ | ||
Clip is a port of most of the features of Express to CLI programming. | ||
Many times we want to have complex use cases that are hard to express and routing along Express and Sugarskull seem to be an apt way of doing this. | ||
Another thing that we want to do in CLI programming often is use configuration files, flags, and parameters. | ||
# URLs | ||
Urls are partitioned with '/' with a starting '/' at all times, they are url encoded, and accept ':param' and '*' | ||
# Requests | ||
Request follow the `req,res,next` methodology. | ||
In the future chaining CLI requests should be easier (ie a clean + build could be done through clip by calling the corresponding urls). | ||
# Basic idea of handler arguments | ||
``` | ||
req.env = process.env | ||
req.flags = require('optimist').argv | ||
req.config = require('nconf') + app.config(...) | ||
req.prompt = require('prompt') | ||
req.params = app.cli(':param') ... | ||
res = require('winston') + require('cliff') | ||
``` | ||
## require('clip')() -> app | ||
## app.config | ||
Determines where to find the config property for requests, uses reconf | ||
## app.flag(flag, handler) | ||
Uses a middleware if a flag is set, uses optimist | ||
## app.cli(path||[path0,...],handler) | ||
Executes a handler if the path is matched | ||
## app.param | ||
CLI parameter preconditions ala express | ||
```javascript | ||
#!/usr/local/bin/node | ||
var clip = require('../'); | ||
var app = new clip(); | ||
var version = '0.0.1'; | ||
// | ||
// SETUP | ||
// | ||
// Recursively find an 'app.json' file with reconf and add it to req.config | ||
app.config('app.json',{flags:['conf']}); | ||
// Dont print stuff to console if --silent is set | ||
app.flag('silent',function(req,res,next){ | ||
res.remove(res.transports.Console); | ||
next(); | ||
}); | ||
// Always print out the app info (middleware) | ||
app.use(function(req,res,next){ | ||
res.info('App.js '+version); | ||
next(); | ||
}); | ||
app.usage(function(req,res,next) { | ||
res.info('commands: helloworld, info'); | ||
}); | ||
app.cli(['/hello','/helloworld'], function(req,res,next) { | ||
res.info('hello world!'); | ||
}); | ||
var utils = require('util'); | ||
app.cli(['/info','/dump'], function(req,res,next) { | ||
res.data(utils.inspect(req)); | ||
}); | ||
app.run(); | ||
``` |
12639
30.3%8
14.29%339
11.15%80
3900%5
25%+ Added
+ Added
- Removed