Comparing version
@@ -6,7 +6,7 @@ #!/usr/local/bin/node | ||
app.config('.haibuconf',{ | ||
switches: ['c', 'conf'] | ||
app.config('.appconf',{ | ||
flags: ['c', 'conf'] | ||
}); | ||
app.use(function(req,res,next){ | ||
console.log('Using config file '+req.config.store.file); | ||
res.info('Using config file '+req.config.store.file); | ||
next(); | ||
@@ -16,42 +16,42 @@ }); | ||
app.usage(function usage(req,res) { | ||
console.log('') | ||
console.log('app') | ||
console.log(' example CLI app for configuration files.') | ||
console.log(' Please refer to documentation of commands using `-h` or `--help`.') | ||
console.log('') | ||
console.log('commands') | ||
console.log(' app config') | ||
console.log('') | ||
res.info('') | ||
res.info('app') | ||
res.info(' example CLI app for configuration files.') | ||
res.info(' Please refer to documentation of commands using `-h` or `--help`.') | ||
res.info('') | ||
res.info('commands') | ||
res.info(' app config') | ||
res.info('') | ||
}) | ||
app.usage('/config',function config(req,res) { | ||
console.log('') | ||
console.log('app config') | ||
console.log(' Actions related to the app configuration file.') | ||
console.log('') | ||
console.log('notes') | ||
console.log(' The configuration will be found recursively up the file system.') | ||
console.log(' If no configuration file is found the HOME folder will be used.') | ||
console.log(' A default configuration file will be created if none exist.') | ||
console.log('') | ||
console.log('commands') | ||
console.log(' app config get' + ' <id>') | ||
console.log(' app config set' + ' <id> <value>') | ||
console.log('') | ||
console.log('options') | ||
console.log(' -c --conf [.appconf] The file to use as our configuration') | ||
console.log('') | ||
res.info('') | ||
res.info('app config') | ||
res.info(' Actions related to the app configuration file.') | ||
res.info('') | ||
res.info('notes') | ||
res.info(' The configuration will be found recursively up the file system.') | ||
res.info(' If no configuration file is found the HOME folder will be used.') | ||
res.info(' A default configuration file will be created if none exist.') | ||
res.info('') | ||
res.info('commands') | ||
res.info(' app config get' + ' <id>') | ||
res.info(' app config set' + ' <id> <value>') | ||
res.info('') | ||
res.info('options') | ||
res.info(' -c --conf [.appconf] The file to use as our configuration') | ||
res.info('') | ||
}) | ||
app.cli('/config/get/:id',function configGet(req,res) { | ||
console.log(req.params.id + ' = ' + (''+req.config.get(req.params.id))); | ||
res.info(req.params.id + ' = ' + (''+req.config.get(req.params.id))); | ||
}); | ||
app.usage('/config/get',function configGetUsage(req,res) { | ||
console.log('') | ||
console.log('app config get' + ' <id>') | ||
console.log(' Gets the value of a property in the app configuration') | ||
console.log(' See `app config -h` for more details') | ||
console.log('') | ||
console.log('params') | ||
console.log(' id - nconf compatible name of the property') | ||
res.info('') | ||
res.info('app config get' + ' <id>') | ||
res.info(' Gets the value of a property in the app configuration') | ||
res.info(' See `app config -h` for more details') | ||
res.info('') | ||
res.info('params') | ||
res.info(' id - nconf compatible name of the property') | ||
}); | ||
@@ -64,12 +64,12 @@ | ||
app.usage('/config/set',function configSetUsage(req,res) { | ||
console.log('') | ||
console.log('app config set' + ' <id> <value>') | ||
console.log(' Sets the value of a property in the app configuration') | ||
console.log(' See `app config -h` for more details') | ||
console.log('') | ||
console.log('params') | ||
console.log(' id - nconf compatible name of the property') | ||
console.log(' value - json compatible value of the property') | ||
res.info('') | ||
res.info('app config set' + ' <id> <value>') | ||
res.info(' Sets the value of a property in the app configuration') | ||
res.info(' See `app config -h` for more details') | ||
res.info('') | ||
res.info('params') | ||
res.info(' id - nconf compatible name of the property') | ||
res.info(' value - json compatible value of the property') | ||
}); | ||
app.run(); |
var optimist = require('optimist'); | ||
var reconf = require('reconf'); | ||
var router = require('./router'); | ||
var prompt = require('prompt'); | ||
var cliff = require('cliff'); | ||
var winston = require('winston'); | ||
var hasOwnProperty = Object.prototype.hasOwnProperty; | ||
function clip() { | ||
@@ -13,2 +18,9 @@ if (!this instanceof clip) { | ||
} | ||
clip.prototype.configure = function configure(name, handler) { | ||
this.middleware.push(function(req,res,next) { | ||
if(req.env.NODE_ENV === name) { | ||
handler(req,res,next) | ||
} | ||
}) | ||
} | ||
clip.prototype.mixin = function mixin(prefix,exports) { | ||
@@ -33,4 +45,26 @@ if(!exports) { | ||
} | ||
clip.prototype.config = function config(file,options) { | ||
var switches = options.switches || []; | ||
clip.prototype.params = function params (name, handler) { | ||
var names = [].concat(name) | ||
this.middleware.push(function(req,res,next) { | ||
for(var i = 0; i < names.length; i++) { | ||
var name = names[i]; | ||
if(hasOwnProperty.call(req.params,name)) { | ||
handler(req,res,next) | ||
} | ||
} | ||
}) | ||
} | ||
clip.prototype.flag = function flag (name, handler) { | ||
var names = [].concat(name) | ||
this.middleware.push(function(req,res,next) { | ||
for(var i = 0; i < names.length; i++) { | ||
var name = names[i]; | ||
if(hasOwnProperty.call(req.flags,name)) { | ||
handler(req,res,next) | ||
} | ||
} | ||
}) | ||
} | ||
clip.prototype.config = function config (file,options) { | ||
var flags = options.flags || []; | ||
var defaults = options.defaults || {}; | ||
@@ -40,5 +74,5 @@ var overrides = options.overrides || undefined; | ||
var filename = file; | ||
for(var i = 0; i < switches.length; i++) { | ||
var switchname = switches[i]; | ||
var value = req.switches[switchname]; | ||
for(var i = 0; i < flags.length; i++) { | ||
var flagname = flags[i]; | ||
var value = req.flags[flagname]; | ||
if (value) { | ||
@@ -70,9 +104,9 @@ filename = value; | ||
} | ||
var req = { | ||
env: cli.env, | ||
switches: argv, | ||
url: '/' + argv._.map(function encode(component) { | ||
return encodeURIComponent(component) | ||
}).join('/') | ||
}; | ||
var req = {}; | ||
req.env = cli.env; | ||
req.flags = argv; | ||
req.url = '/' + argv._.map(function encode(component) { | ||
return encodeURIComponent(component) | ||
}).join('/'); | ||
req.prompt = prompt; | ||
var res = new CLIResponse(); | ||
@@ -126,4 +160,4 @@ this.handle(req, res, cb); | ||
} | ||
req.switches = req.switches || {} | ||
var routers = req.switches.h || req.switches.help ? this.usages : this.routers | ||
req.flags = req.flags || {} | ||
var routers = req.flags.h || req.flags.help ? this.usages : this.routers | ||
for(var i = 0; i < routers.length; i++) { | ||
@@ -153,4 +187,4 @@ var route = routers[i], match; | ||
} | ||
if(!req.switches.h) { | ||
req.switches.h = true; | ||
if(!req.flags.h) { | ||
req.flags.h = true; | ||
res.end(404); | ||
@@ -167,3 +201,10 @@ this.handle(req, res, cb); | ||
this.statusCode = 0; | ||
for(var key in cliff) { | ||
var value = cliff[key]; | ||
if(typeof value === 'function') { | ||
this[key] = value.bind(cliff); | ||
} | ||
} | ||
} | ||
CLIResponse.prototype = winston; | ||
CLIResponse.prototype.end = function end(statusCode) { | ||
@@ -170,0 +211,0 @@ this.statusCode = statusCode |
@@ -5,8 +5,11 @@ { | ||
"author": "bradleymeck", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"keywords": ["CLI"], | ||
"dependencies": { | ||
"reconf": "0.1.x", | ||
"optimist": "0.2.x" | ||
"optimist": "0.2.x", | ||
"prompt": "0.1.x", | ||
"cliff": "0.1.x" | ||
}, | ||
"main": "lib/clip.js" | ||
} |
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
9700
12.11%7
16.67%305
15.09%1
-50%2
Infinity%4
100%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added