forked from Synthetixio/synthetix
-
Notifications
You must be signed in to change notification settings - Fork 4
/
bin.js
executable file
·55 lines (47 loc) · 1.69 KB
/
bin.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
#!/usr/bin/env node
'use strict';
const { getTarget, getSource, getSynths } = require('./index');
const commander = require('commander');
const program = new commander.Command();
program
.command('target')
.description('Get deployed target files for an environment')
.option('-n, --network <value>', 'The network to run off.', x => x.toLowerCase(), 'mainnet')
.option('-c, --contract [value]', 'The name of the contract')
.option('-k, --key [value]', 'A specific key wanted')
.action(async ({ network, contract, key }) => {
const target = getTarget({ network, contract });
console.log(JSON.stringify(key in target ? target[key] : target, null, 2));
});
program
.command('source')
.description('Get source files for an environment')
.option('-n, --network <value>', 'The network to run off.', x => x.toLowerCase(), 'mainnet')
.option('-c, --contract [value]', 'The name of the contract')
.option('-k, --key [value]', 'A specific key wanted')
.action(async ({ network, contract, key }) => {
const source = getSource({ network, contract });
console.log(JSON.stringify(key in source ? source[key] : source, null, 2));
});
program
.command('synths')
.description('Get the list of synths')
.option('-n, --network <value>', 'The network to run off.', x => x.toLowerCase(), 'mainnet')
.option('-k, --key [value]', 'A specific key wanted')
.action(async ({ network, key }) => {
const synthList = getSynths({ network });
console.log(
JSON.stringify(
synthList.map(entry => {
return key in entry ? entry[key] : entry;
}),
null,
2
)
);
});
// perform as CLI tool if args given
if (require.main === module) {
require('pretty-error').start();
program.parse(process.argv);
}