-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli.js
executable file
·58 lines (46 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
#!/usr/bin/env node
const { Readable } = require('stream');
const meow = require('meow');
const chalk = require('chalk');
const { parseLyrics } = require('./');
const cli = meow(chalk`
{yellow.bold Usage}
$ lyrics [artist] [song] [-c]
{yellow.bold Options}
-c, --clean Just lyrics without title
{yellow.bold Examples}
$ {green.bold lyrics} radiohead reckoner
{grey > radiohead - reckoner [In Rainbows]}
{grey > Reckoner,}
{grey > You can't take it with you, ..}
`, {
flags: {
clean: {
type: 'boolean',
alias: 'c',
default: false,
},
}
});
const [artist, song] = cli.input;
if (!artist || !song) {
cli.showHelp();
}
const main = async () => {
const res = await parseLyrics(artist, song);
let lyrics = res.lyrics.split('\n').map((line) => {
if (line[0] == ',') {
line = line.substr(1, line.length);
}
return line;
}).join('\n');
let title = `${artist} - ${song} [${res.album}]\n\n`;
if (cli.flags.clean) {
title = '';
}
const body = `${title}${lyrics}`;
const outStream = new Readable({ read() {} });
outStream.push(body);
outStream.pipe(process.stdout);
}
main();