1 |
|
2 |
|
3 | const fs = require('fs');
|
4 | const folderPath = __dirname;
|
5 | const Table = require('cli-table2');
|
6 | const chalk = require('chalk');
|
7 | const _ = require('lodash');
|
8 | const command_col_len = 20;
|
9 | const example_col_len = 45;
|
10 | const info_col_len = 80;
|
11 | const total_table_col_len = command_col_len + example_col_len + info_col_len;
|
12 |
|
13 | function help() {
|
14 | if (total_table_col_len < parseInt(process.stdout.columns)) {
|
15 | var table = new Table({
|
16 | head: ['Title', 'Command', 'Info'],
|
17 | rowHeights: [2],
|
18 | colWidths: [command_col_len, example_col_len, info_col_len],
|
19 | chars: { 'mid': '', 'left-mid': '', 'mid-mid': '', 'right-mid': '' }
|
20 | });
|
21 |
|
22 | fs.readdir(folderPath, (err, files) => {
|
23 | _.pull(files, 'set.js');
|
24 | files.forEach(file => {
|
25 | var command_name = file.substr(0, file.length - 3);
|
26 | var objekt = require(folderPath + '/' + file);
|
27 | var example = objekt.example;
|
28 | table.push([command_name.charAt(0).toUpperCase() + command_name.slice(1), objekt.example, objekt.info]);
|
29 | });
|
30 | console.log(table.toString());
|
31 | })
|
32 | }
|
33 | else {
|
34 | var table = new Table({
|
35 | colWidths: [12, 80],
|
36 | rowHeights: [1],
|
37 | chars: {
|
38 | 'top': '', 'top-mid': '', 'top-left': '', 'top-right': ''
|
39 | , 'bottom': '', 'bottom-mid': '', 'bottom-left': '', 'bottom-right': ''
|
40 | , 'left': '', 'left-mid': '', 'mid': '', 'mid-mid': ''
|
41 | , 'right': '', 'right-mid': '', 'middle': ' '
|
42 | },
|
43 | style: { 'padding-left': 0, 'padding-right': 0 }
|
44 |
|
45 | });
|
46 | table.push("", "");
|
47 | fs.readdir(folderPath, (err, files) => {
|
48 | files.forEach(file => {
|
49 | var command_name = file.substr(0, file.length - 3);
|
50 | var objekt = require(folderPath + '/' + file);
|
51 | var example = objekt.example;
|
52 | if (objekt.example === 'flow set lookup') {
|
53 | return true;
|
54 | }
|
55 |
|
56 | table.push(["Command", chalk.green(objekt.example)]);
|
57 | table.push(["Info", objekt.info]);
|
58 | table.push("", "");
|
59 | });
|
60 | console.log(table.toString());
|
61 | })
|
62 | }
|
63 | }
|
64 |
|
65 | help.example = "flow help or flow"
|
66 | help.intro = "Lists all the commands"
|
67 | help.info = "Lists all the commands"
|
68 | help.explanation = `Helps get you details about all the commands with an example.`
|
69 |
|
70 | module.exports.help = help;
|
71 |
|
72 |
|