shadows-contract
Version:
The smart contracts which make up the Shadows system. (shadows.link)
56 lines (47 loc) • 1.73 kB
JavaScript
;
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);
}