-
Notifications
You must be signed in to change notification settings - Fork 18
/
main.js
85 lines (65 loc) · 1.88 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
var app, cliConf, cmder, conf, configFile, cs, err, kit, port, remote;
kit = require('nokit');
cs = kit.require('brush');
cmder = require('commander');
cmder.option('-h, --help', 'Help', function() {
return cmder.help();
});
cmder.option('-s, --server');
cmder.option('-u, --upload [localFile host[:port]/path/to/dir]', 'Upload file or directory to remote host.');
cmder.option('-p, --password <pwd>', 'Password.');
cmder.option('-a, --algorithm <alg>', 'Algorithm', 'aes128');
cmder.option('-v, --ver', 'Print version', function() {
console.log((require('./package.json')).version);
return process.exit();
});
cmder.parse(process.argv);
cliConf = {};
configFile = cmder.args[1] || cmder.args[0];
if (cmder.upload) {
if (cmder.upload === true) {
configFile = cmder.args[0];
} else {
cliConf.localDir = cmder.upload;
remote = null;
kit._.find(cmder.args, function(arg, index) {
remote = /([^\/:]+)(:\d+)?\/(.*)/.exec(arg);
if (remote) {
cmder.args.splice(index, 1);
}
return remote;
});
if (remote) {
if (!remote[3]) {
kit.err('Wrong argument, host[:port]/path/to/file wanted.');
process.exit(1);
}
cliConf.host = remote[1] || '';
port = remote[2] || ':8345';
cliConf.port = port.slice(1);
cliConf.remoteDir = "/" + remote[3];
}
configFile = cmder.args[0];
}
}
cmder.password && (cliConf.password = cmder.password);
cmder.algorithm && (cliConf.algorithm = cmder.algorithm);
try {
conf = require(kit.path.resolve(configFile));
} catch (_error) {
err = _error;
if (cmder.args.length > 0) {
kit.err(err.stack);
process.exit(1);
} else {
kit.log(cs.yellow('No config specified, use default.'));
conf = {};
}
}
kit._.extend(conf, cliConf);
if (cmder.server) {
app = require('./server');
} else {
app = require('./client');
}
app(conf, !cmder.upload);