-
Notifications
You must be signed in to change notification settings - Fork 58
/
index.js
executable file
·36 lines (30 loc) · 1005 Bytes
/
index.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
#!/usr/bin/env node
// dependencies
const cmd = require('./cmd');
const docopt = require('docopt').docopt;
const fs = require('fs');
const mkdirp = require('mkdirp');
const path = require('path');
const version = require('../package.json').version;
// generate and parse the command-line options
const doc = fs.readFileSync(path.join(__dirname, 'docopt.txt'), 'utf8');
const options = docopt(doc, { version: version });
// load the configs
var config = require('./config')(options, { version : version });
// assert that the download dir exists
try {
mkdirp.sync(config.global.downloadDir);
} catch (e) {
console.warn('Cannot create download dir: ' + config.global.downloadDir);
console.warn(e.message);
process.exit(1);
}
// determine the appropriate subcommand
var subcommand =
(options.config) ? cmd.config :
(options.shell) ? cmd.shell :
(options.trojan) ? cmd.trojan :
( function() { throw 'Invalid subcommand'; })
;
// execute
subcommand(options, config);