-
Notifications
You must be signed in to change notification settings - Fork 10
/
cli.js
40 lines (29 loc) · 843 Bytes
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var fs = require('fs');
var path = require('path');
var program = require('commander');
var pkg = require('./package.json');
var out = require('./lib/output');
program
.version(pkg.version);
function requireCommand(f){
var m = require(path.join(__dirname,'./commands',f));
if(!m.setup || typeof m.setup !== 'function')
throw new Error('Command must export setup as a function.')
m.setup(program);
return m;
}
fs.readdirSync(path.join(__dirname,'./commands')).map(requireCommand);
function increaseVerbosity(v,total){
out.verbose(v);
return v;
}
program
.option('-v, --verbose [value]', 'Verbose level', increaseVerbosity, 1)
.command('*')
.action(function(env){
out.error('Command not found');
program.help();
});
program.parse(process.argv);
if(program.args.length === 0)
return program.help();