forked from jrburke/delposto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelposto.js
63 lines (50 loc) · 1.66 KB
/
delposto.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* @license Copyright (c) 2012, James Burke All Rights Reserved.
* Available via the MIT or new BSD license.
* see: http://github.com/jrburke/delposto for details
*/
/*jslint node: true, nomen: true */
'use strict';
var version = '0.0.1',
exists = require('./lib/exists'),
path = require('path'),
fs = require('fs'),
commandDir = __dirname + '/commands/';
function printHelp(command, firstArg) {
var commandModule;
if ((command === '-h' || command === 'help') && firstArg) {
if (exists(path.join(commandDir, firstArg) + '.js')) {
command = firstArg;
} else {
command = null;
}
}
if (!exists(path.join(commandDir, command) + '.js')) {
command = null;
}
if (command) {
commandModule = require('./commands/' + command);
console.log(commandModule.doc ||
commandModule.summary ||
'No docs available');
} else {
console.log(path.basename(process.argv[1]) + ' version ' + version +
'. Commands:\n');
fs.readdirSync(commandDir).forEach(function (command) {
console.log(command.replace(/\.js$/, '') + ': ' +
(require('./commands/' + command).summary || ''));
});
}
}
function main(args) {
var command = args[0],
firstArg = args[1],
hasCommand = command &&
exists(path.join(commandDir, command + '.js'));
if (!command || !hasCommand || firstArg === '-h' || firstArg === 'help') {
printHelp(command, firstArg);
process.exit();
}
require('./commands/' + command)(args.slice(1));
}
module.exports = main;