-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcli.js
64 lines (55 loc) · 1.24 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
#!/usr/bin/env node
'use strict';
const pkg = require('./package.json');
const avail = require('./');
const argv = process.argv.slice(2);
const symbols = require('log-symbols');
const updateNotifier = require('update-notifier');
updateNotifier({pkg}).notify();
function help() {
console.log([
'',
' ' + pkg.description,
'',
' Example',
' avail avail.io',
'',
' avail.io ' + symbols.success,
' avail.com ' + symbols.error
].join('\n'));
}
if (argv.indexOf('--help') !== -1) {
help();
return;
}
if (argv.indexOf('--version') !== -1) {
console.log(pkg.version);
return;
}
function summarySymbol(summary) {
switch (summary) {
case 'inactive':
return symbols.success;
break;
case 'active':
return symbols.error;
break;
case 'reserved':
return symbols.warning;
break;
default:
return symbols.error;
break;
}
}
avail(argv[0])
.then(result => {
const status = result[0];
const whois = result[1];
const domains = status.body.status;
domains.forEach(domain => {
console.log(whois.body.whoisText);
console.log(summarySymbol(domain.summary), domain.domain, `(${domain.status})`);
});
})
.catch(console.log);