-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
executable file
·61 lines (49 loc) · 1.12 KB
/
main.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
59
60
61
#!/usr/bin/env node
'use strict';
const Alldebrid = require('./lib/alldebrid.js');
const fs = require('fs');
let alldebrid = new Alldebrid();
const [,, ...args] = process.argv;
let help = `
Alldebrid CLI.
Usage:
alldebrid <url>
Options:
-h --help Show this help screen.
--version Show version.
`;
let username = process.env.ALLDEBRID_LOGIN;
let password = process.env.ALLDEBRID_PASSWORD;
//
let url = args[0];
function main(login, password, url) {
alldebrid.connect(login, password)
.then(() => {
return alldebrid.debrid(url);
})
.then(link => console.log(link))
.catch(err => console.error(err));
}
function version() {
fs.readFile('package.json', (err, data) => {
if (err) throw err;
let ver = JSON.parse(data).version;
console.log(ver);
});
}
if (args.length != 1) {
console.error(help);
process.exit(1);
} else {
switch (args[0]) {
case '-h':
case '--help':
console.log(help);
break;
case '--version':
version();
break;
default:
main(username, password, url);
}
}