-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
66 lines (64 loc) · 2.18 KB
/
app.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
/**
* This is the command-line wrapper for the bridging
* tool prividing all the command line options.
*/
const program = require('./bin/cli')
const colors = require('colors')
const runBridges = require('./bin/bridge-runner')
const config = require('./config.json')
//show valid tables
if (['source','table','show'].every(e => Object.keys(program).includes(e))) {
try {
console.log('\n Valid tables for ' + program.source + ':')
require('./bin/list-tables')(program.source).map(t => console.log(` ${t}`))
} catch (e) {
console.log(e)
}
}
//show valid sources
else if (['source','show'].every(e=>Object.keys(program).includes(e)) && program.source === true) {
console.log('\n Valid sources:');
require('./bin/list-src')(config).map(v => console.log(` ${v}`));
}
//show valid destinations
else if (['destination','show'].every(e => Object.keys(program).includes(e))) {
console.log('\n Valid destinations:')
require('./bin/list-dest')(config).map(v => console.log(` ${v}`))
}
//show valid batches
else if (['batch','show'].every(e => Object.keys(program).includes(e))) {
console.log('\n Valid batches:');
require('./bin/list-batches')().map(v => console.log(` ${v}`))
}
//run batch if specified
else if (Object.keys(program).includes('batch')) {
const parseBatch = require('./bin/batch-parse');
const bridges = parseBatch(program.batch, config.dirs.batches + program.batch);
runBridges(bridges, function(err, responses) {
if (err) {
console.error(colors.red(err));
program.help();
return;
}
if (config.logto == 'console' && responses) console.log(responses);
})
} else {
//otherwise, run bridge once
//only source / destination are required - each source module should throw
//an error if table is necessary
if (!['source','destination'].every(e => Object.keys(program).includes(e))) {
console.error(colors.red('Wrong usage.'))
program.help()
}
//run one bridge
const Bridge = require('./bin/bridge')
const bridge = new Bridge({config: config, opt: program})
bridge.run((err,response) => {
if (err) {
process.stdout.clearLine()
process.stdout.cursorTo(0)
console.error(err)
return;
}
})
}