-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli.js
executable file
·73 lines (66 loc) · 3.56 KB
/
cli.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
#!/usr/bin/env node
'use strict';
const ipInfo = require('ipinfo');
const chalk = require('chalk');
const Table = require('cli-table');
const meow = require('meow');
const tbl = new Table({
head: [chalk.magenta.bold('Title'), chalk.magenta.bold('Value')]
});
const cli = meow({
help: [
'Usage',
' - If an IP address is passed, information about it is',
' fetched and displayed.',
' - Otherwise, the current public address will be used.',
'',
'Examples',
'',
' > ipinfo',
' > ipinfo 8.8.8.8',
'',
'Result',
'',
' ┌──────────┬──────────────────────────────────────────┐',
' │ Title │ Value │',
' ├──────────┼──────────────────────────────────────────┤',
' │ ip │ 8.8.8.8 │',
' ├──────────┼──────────────────────────────────────────┤',
' │ hostname │ www.xyz.com │',
' ├──────────┼──────────────────────────────────────────┤',
' │ city │ Mountain View │',
' ├──────────┼──────────────────────────────────────────┤',
' │ region │ California │',
' ├──────────┼──────────────────────────────────────────┤',
' │ country │ US │',
' ├──────────┼──────────────────────────────────────────┤',
' │ loc │ 37.4192,-122.0574 │',
' ├──────────┼──────────────────────────────────────────┤',
' │ org │ XYZ Inc. │',
' ├──────────┼──────────────────────────────────────────┤',
' │ postal │ 99999 │',
' ├──────────┼──────────────────────────────────────────┤',
' │ timezone │ America/Los_Angeles │',
' └──────────┴──────────────────────────────────────────┘'
]
});
const ignoredKeys = ['readme'];
ipInfo(cli.input[0], (err, ipResults) => {
if (err) {
console.error(err);
process.exit(1);
}
if (ipResults.error) {
console.error(ipResults.error);
process.exit(1);
}
for (const key in ipResults) {
if (Object.prototype.hasOwnProperty.call(ipResults, key)) {
if (!ignoredKeys.includes(key)) {
const value = ipResults[key];
tbl.push([chalk.cyan(key), chalk.green(value)]);
}
}
}
console.log(tbl.toString());
});