-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcli.js
executable file
·42 lines (38 loc) · 899 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
#!/usr/bin/env node
'use strict';
const meow = require('meow');
const getStdin = require('get-stdin');
const objToTable = require('obj-to-table');
const toCsv = require('to-csv');
const viewportList = require('viewport-list');
const cli = meow({
help: [
'Usage',
' $ viewport-list [device]',
' $ viewport-list < <file>',
'',
'Example',
' $ viewport-list iphone4 iphone5',
' $ viewport-list < devices.txt',
'',
'Options',
' -p, --pretty Print the results in a table'
]
}, {alias: {p: 'pretty'}});
function run(input, opts) {
viewportList(input).then(devices => {
if (opts.pretty) {
console.log(objToTable(devices).toString());
return;
}
console.log(toCsv(devices));
});
}
if (process.stdin.isTTY) {
run(cli.input, cli.flags);
} else {
getStdin().then(data => {
[].push.apply(cli.input, data.trim().split('\n'));
run(cli.input, cli.flags);
});
}