-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
cli.js
executable file
·58 lines (52 loc) · 1.11 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
#!/usr/bin/env node
import process from 'node:process';
import meow from 'meow';
import sparkly from 'sparkly';
import getStdin from 'get-stdin';
const cli = meow(`
Usage
$ sparkly <number> […]
$ echo <number> […] | sparkly
Options
--min Minimum range
--max Maximum range
--style Style for the sparklines [Values: fire]
Examples
$ sparkly 0 3 5 8 4 3 4 10
▁▃▄▅▃▃▃▆
$ sparkly --min=0 --max=10 1 2 3 4 5
▁▂▃▄▄
$ sparkly --style=fire 1 2 3 4 5 6 7 8
▁▂▂▃▃▄▄▅
$ echo 0 3 5 8 4 3 | sparkly
▁▂▃▅▃▂
`, {
importMeta: import.meta,
input: {
type: 'number',
},
flags: {
min: {
type: 'number',
},
max: {
type: 'number',
},
style: {
type: 'string',
},
},
});
const {input} = cli;
if (input.length === 0 && process.stdin.isTTY) {
console.error('Input required');
process.exit(1);
}
if (input.length > 0) {
console.log(sparkly(input, cli.flags));
} else {
(async () => {
const data = (await getStdin()).match(/\d/g).map(x => Number.parseInt(x, 10));
console.log(sparkly(data, cli.flags));
})();
}