-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathhelp.js
43 lines (32 loc) · 1.17 KB
/
help.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
var prettyjson = require('prettyjson');
var path = require('path');
var fs = require('fs');
module.exports = {
name:'help',
description:'Shows help about Bosco',
example:'bosco help <command>',
cmd:cmd
}
function cmd(bosco, args) {
var cmdName = args.shift();
if(!cmdName) return bosco.error("You need to provide a command name. e.g: " + module.exports.example);
var cmdPath = path.join(__dirname,'commands',cmdName + '.js'),
localPath = path.join(path.resolve("."),"commands",cmdName + '.js'),
helpPath = path.join(__dirname,'help',cmdName + '.txt'),
localHelpPath = path.join(path.resolve("."),'help',cmdName + '.txt');
var printHelp = function(module) {
var m = require(module);
var o = {
name: m.name,
description: m.description,
example: m.example
}
console.log("");
console.log(prettyjson.render(o, {noColor: false}));
console.log("");
if(bosco.exists(helpPath)) return console.log(fs.readFileSync(helpPath).toString());
if(bosco.exists(localHelpPath)) return console.log(fs.readFileSync(localHelpPath).toString());
}
if(bosco.exists(cmdPath)) return printHelp(cmdPath);
if(bosco.exists(localPath)) return printHelp(localPath);
}