UNPKG

2.39 kBJavaScriptView Raw
1// Generated by CoffeeScript 1.8.0
2(function() {
3 var Config, fs, getHelpTopics, path, printHelpTopic, projectRoot;
4
5 path = require('path');
6
7 fs = require('fs');
8
9 Config = require('./config');
10
11 projectRoot = Config.projectRoot();
12
13 getHelpTopics = function() {
14 var lakeConfig, rule, ruleFile, topic, topics, _i, _len, _ref, _ref1, _ref2;
15 topics = [];
16 lakeConfig = Config.config();
17 _ref = lakeConfig.rules;
18 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
19 ruleFile = _ref[_i];
20 rule = require(path.join(projectRoot, ruleFile));
21 if ((((_ref1 = rule.readme) != null ? _ref1.name : void 0) != null) && (((_ref2 = rule.readme) != null ? _ref2.path : void 0) != null)) {
22 topic = {
23 name: rule.readme.name,
24 description: rule.description,
25 path: rule.readme.path
26 };
27 topics.push(topic);
28 }
29 }
30 return topics;
31 };
32
33 printHelpTopic = function(topics, requestedTopic) {
34 var helpText, topic, topicFound, _i, _len;
35 topicFound = false;
36 for (_i = 0, _len = topics.length; _i < _len; _i++) {
37 topic = topics[_i];
38 if (topic.name === requestedTopic) {
39 helpText = fs.readFileSync(topic.path, 'utf8');
40 console.log("Help for '" + requestedTopic + "':\n");
41 console.log(helpText);
42 topicFound = true;
43 break;
44 }
45 }
46 if (!topicFound) {
47 return console.log("Help topic '" + requestedTopic + "' doesn't exist.");
48 }
49 };
50
51 module.exports.help = function() {
52 var command, listTopics, topics;
53 listTopics = function(topics) {
54 var text, topic, _i, _len, _results;
55 _results = [];
56 for (_i = 0, _len = topics.length; _i < _len; _i++) {
57 topic = topics[_i];
58 text = '\t' + topic.name;
59 if (topic.description != null) {
60 text += ' - ' + topic.description;
61 }
62 _results.push(console.log(text));
63 }
64 return _results;
65 };
66 topics = getHelpTopics();
67 command = process.argv[2];
68 if (command == null) {
69 console.log("Run 'lake-help [topic]' to show additional information about a specific topic.");
70 console.log("Available topics are:");
71 return listTopics(topics);
72 } else if (command === 'topics') {
73 return listTopics(topics);
74 } else {
75 return printHelpTopic(topics, command);
76 }
77 };
78
79}).call(this);