-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
44 lines (38 loc) · 1.04 KB
/
cli.js
File metadata and controls
44 lines (38 loc) · 1.04 KB
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
#!/usr/bin/env node
'use strict';
const filenamify = require('filenamify');
const fs = require('fs');
const ipics = require('ipics');
const meow = require('meow');
const opn = require('opn');
const cli = meow(`
Usage
$ ipics <searchTerm>
Options
-t, --type Type of item to search for
(can be one of 'album', 'book', 'ios-app', 'mac-app', 'movie' or 'tv-show')
Examples
ipics OU812 -t album
ipics "Twin Peaks" -t tv-show
`, {
alias: {
't': 'type'
}
});
if(cli.input.length === 0 || cli.flags.type === undefined) {
cli.showHelp();
}
else {
ipics(cli.input[0], cli.flags.type).then(results => {
let html = '';
results.forEach(result => {
html += `<a href="${result.imageUrl}" title="${result.name}"><img src="${result.thumbnailUrl}"></a>`;
});
const outputFilename = `${filenamify(cli.input[0])}.html`;
fs.writeFileSync(outputFilename, html);
opn(outputFilename, {wait: false}); // open in default browser
}).catch(error => {
console.error(error);
cli.showHelp();
});
}