-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbin.js
executable file
·125 lines (110 loc) · 3.5 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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env node
'use strict';
const {
getAST,
getSource,
getSuspensionReasons,
getSynths,
getTarget,
getUsers,
getVersions,
networks,
toBytes32,
} = require('./index');
const commander = require('commander');
const program = new commander.Command();
program
.command('ast <source>')
.description('Get the AST for some source file')
.action(async source => {
console.log(JSON.stringify(getAST({ source, match: /./ }), null, 2));
});
program
.command('bytes32 <key>')
.description('Bytes32 representation of a currency key')
.option('-c, --skip-check', 'Skip the check')
.action(async (key, { skipCheck }) => {
if (
!skipCheck &&
getSynths({ network: 'bsc' }).filter(({ name }) => name === key).length < 1
) {
throw Error(
`Given key of "${key}" does not exist as a synth in bsc (case-sensitive). Use --skip-check to skip this check.`
);
}
console.log(toBytes32(key));
});
program
.command('networks')
.description('Get networks')
.action(async () => {
console.log(networks);
});
program
.command('source')
.description('Get source files for an environment')
.option('-n, --network <value>', 'The network to run off.', x => x.toLowerCase(), 'bsc')
.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('suspension-reasons')
.description('Get the suspension reason')
.option('-c, --code [value]', 'A specific suspension code')
.action(async ({ code }) => {
const reason = getSuspensionReasons({ code });
console.log(reason);
});
program
.command('synths')
.description('Get the list of synths')
.option('-n, --network <value>', 'The network to run off.', x => x.toLowerCase(), 'bsc')
.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
)
);
});
program
.command('target')
.description('Get deployed target files for an environment')
.option('-n, --network <value>', 'The network to run off.', x => x.toLowerCase(), 'bsc')
.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('users')
.description('Get the list of system users')
.option('-n, --network <value>', 'The network to run off.', x => x.toLowerCase(), 'bsc')
.option('-u, --user [value]', 'A specific user wanted')
.action(async ({ network, user }) => {
const users = getUsers({ network, user });
console.log(JSON.stringify(users, null, 2));
});
program
.command('versions')
.description('Get the list of deployed versions')
.option('-n, --network <value>', 'The network to run off.', x => x.toLowerCase(), 'bsc')
.option('-b, --by-contract', 'To key off the contract name')
.action(async ({ network, byContract }) => {
const versions = getVersions({ network, byContract });
console.log(JSON.stringify(versions, null, 2));
});
// perform as CLI tool if args given
if (require.main === module) {
require('pretty-error').start();
program.parse(process.argv);
}