1 | 'use strict';
|
2 |
|
3 |
|
4 |
|
5 | const request = require('./index.js');
|
6 | const commander = require('commander');
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | const parse = (uri) => {
|
13 | try {
|
14 | return JSON.parse(uri);
|
15 | } catch (e) {
|
16 | return uri;
|
17 | }
|
18 | };
|
19 |
|
20 |
|
21 | const runCLI = () => {
|
22 |
|
23 | commander
|
24 | .arguments('<uri>')
|
25 | .action((uri) => {
|
26 | commander.uri = uri;
|
27 | })
|
28 | .parse(process.argv);
|
29 |
|
30 |
|
31 | const opt = parse(commander.uri);
|
32 | console.log('Pinging %s', typeof opt === 'object' ? opt.uri : opt);
|
33 | request.waitFor(opt, function(err, val) {
|
34 | if (err) {
|
35 | console.log('Timed out');
|
36 | process.exit(1);
|
37 | }
|
38 | console.log('Ready');
|
39 | process.exit(0);
|
40 | });
|
41 | };
|
42 |
|
43 |
|
44 | exports.runCLI = runCLI;
|