UNPKG

2.52 kBJavaScriptView Raw
1//this file contains help docs for help command
2// for 'flow help' and for 'flow help help'
3const fs = require('fs');
4const folderPath = __dirname;
5const Table = require('cli-table2');
6const chalk = require('chalk');
7const _ = require('lodash');
8const command_col_len = 20;
9const example_col_len = 45;
10const info_col_len = 80;
11const total_table_col_len = command_col_len + example_col_len + info_col_len;
12
13function 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 //fetching the names of all the files from the docs directory
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 //table.push(["Title", command_name.charAt(0).toUpperCase() + command_name.slice(1)]);
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
65help.example = "flow help or flow"
66help.intro = "Lists all the commands"
67help.info = "Lists all the commands"
68help.explanation = `Helps get you details about all the commands with an example.`
69
70module.exports.help = help;
71
72