-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathcli.js
executable file
·55 lines (44 loc) · 957 Bytes
/
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
#!/usr/bin/env node
'use strict';
var pkg = require('./package.json');
var emojiFlags = require('./');
var argv = process.argv.slice(2);
var columnify = require('columnify');
function help() {
console.log([
'',
' ' + pkg.description,
'',
' Example',
' emoji-flags gb',
'',
' emoji-flags dk --verbose',
'',
' emoji-flags',
' => returns the entire dataset',
''
].join('\n'));
}
if (argv.indexOf('--help') !== -1) {
help();
return;
}
if (argv.indexOf('--version') !== -1) {
console.log(pkg.version);
return;
}
// list all countries
if (!argv.length) {
var columns = columnify(emojiFlags.data, {
columns: ['code', 'name', 'emoji'],
showHeaders: false
});
console.log(columns)
return;
}
var country = emojiFlags.countryCode(argv[0]);
if (argv.indexOf('--verbose') !== -1) {
console.log(JSON.stringify(country, null, 4));
return;
}
console.log(country.emoji);