-
Notifications
You must be signed in to change notification settings - Fork 5
/
output.js
86 lines (73 loc) · 2.13 KB
/
output.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const Table = require('cli-table2');
const { prettyPrint } = require('./utils');
const chalk = require('chalk');
const outputResponse = (data) => {
console.log(chalk.bold(prettyPrint(data)));
}
const outputResponseHeaders = (data) => {
console.log(chalk.dim(data));
}
const outputHistory = (data) => {
var table = new Table({
head: ['id', 'method', 'url', 'status', 'timestamp'],
colWidths: [12, 8, 30, 8, 12],
wordWrap: true
});
data.forEach(row => {
table.push([row.id, row.method, row.url, row.status, row.ts]);
});
console.log(table.toString());
}
const outputCollectionRequests = (data) => {
var table = new Table({
head: ['id', 'name', 'method', 'url'],
colWidths: [12, 20, 8, 30],
wordWrap: true
});
data.forEach(row => {
table.push([row.id, row.name, row.method, row.url]);
});
console.log(table.toString());
}
const outputRun404 = (collectionName) => {
if (collectionName) {
console.log(chalk.red(`Run id not found. Please check if the {id} is present in ${collectionName}.`));
return;
}
console.log(chalk.red(`Run id not found. Please check if the reference id is present in history.`));
}
const outputCollectionExists = () => {
console.log('This collection already exists');
}
const outputCollectionNotExists = () => {
console.log(chalk.red('This collection does not exist.'));
}
const outputDefaultNewChoice = () => {
console.log('No option provided. Type', chalk.bold('cx help new') );
}
const outputEmptyArgsError = () => {
console.log(chalk.red('No arguments provided'));
}
const outpuNoRunChoiceError = () => {
console.log(chalk.red('No run id provided.'), 'Type', chalk.bold('cx help run'));
}
const outputClearHistory = () => {
console.log(chalk.bold('History cleared'));
}
const outputHelpMenu = (menus, subCmd) => {
console.log(chalk.bold(menus[subCmd] || menus.main));
}
module.exports = {
outputResponse,
outputHistory,
outputRun404,
outputResponseHeaders,
outputCollectionExists,
outputCollectionNotExists,
outputCollectionRequests,
outputDefaultNewChoice,
outputEmptyArgsError,
outpuNoRunChoiceError,
outputClearHistory,
outputHelpMenu
}