-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·72 lines (57 loc) · 1.55 KB
/
cli.js
File metadata and controls
executable file
·72 lines (57 loc) · 1.55 KB
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
#!/usr/bin/env node
const pkg = require('./package.json');
const program = require('commander');
const telehook = require('./index');
const chalk = require('chalk');
const runTelehook = (token, hook, config) => {
console.log();
let run = telehook(token, hook, config);
run.on('data', function(data){
console.group();
console.log(chalk.green("+++++++++++++++++\nDATA RECEIVED\n+++++++++++++++++"));
console.log(chalk.white(JSON.stringify(data, null, 2)));
console.groupEnd();
})
run.on('error', function(error){
console.group();
console.log(chalk.red("+++++++++++++++++\nERROR\n+++++++++++++++++"));
console.error(error);
console.groupEnd();
})
run.on('forwarded', function(data){
console.log();
console.log(chalk.green('✔') + chalk.blue(' forwarded'));
console.log();
})
run.on('forward.error', function(error){
console.group();
console.log(chalk.red("+++++++++++++++++\nFORWARD ERROR\n+++++++++++++++++"));
console.error(error);
console.groupEnd();
})
}
program
.version(pkg.version)
.description(pkg.description);
program
.command('run <token> <hook>')
.alias('*')
.option(
'-i, --interval [interval]',
'Set the interval'
)
.option(
'-t, --timeout [timeout]',
'Set the timeout'
)
.action(function (token, hook, options) {
let config = {};
if(options.interval){
config.interval = parseInt(options.interval);
}
if(options.timeout){
config.timeout = parseInt(options.timeout);
}
runTelehook(token, hook, config);
});
program.parse(process.argv);