Skip to content

Commit

Permalink
Replaces yargs with commander.
Browse files Browse the repository at this point in the history
Works towards resolving #361.  Yargs brings in ~26 packages while commander brings in 1.
  • Loading branch information
MicahZoltu committed Oct 28, 2019
1 parent edfb717 commit d268ffa
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 43 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@
"homepage": "https://github.com/ethereum/solc-js#readme",
"dependencies": {
"command-exists": "^1.2.8",
"commander": "3.0.2",
"fs-extra": "^0.30.0",
"js-sha3": "0.8.0",
"memorystream": "^0.3.1",
"require-from-string": "^2.0.0",
"semver": "^5.5.0",
"js-sha3": "0.8.0",
"tmp": "0.0.33",
"yargs": "^13.2.0"
"tmp": "0.0.33"
},
"devDependencies": {
"coveralls": "^3.0.0",
Expand Down
61 changes: 21 additions & 40 deletions solcjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,48 +11,29 @@ var smtsolver = require('./smtsolver.js');
// FIXME: remove annoying exception catcher of Emscripten
// see https://github.com/chriseth/browser-solidity/issues/167
process.removeAllListeners('uncaughtException');

var yargs = require('yargs')
.usage('Usage: $0 [options] [input_file...]')
.option('version', {
describe: 'Show version and exit.',
type: 'boolean'
})
.option('optimize', {
describe: 'Enable bytecode optimizer.',
type: 'boolean'
})
.option('bin', {
describe: 'Binary of the contracts in hex.',
type: 'boolean'
})
.option('abi', {
describe: 'ABI of the contracts.',
type: 'boolean'
})
.option('standard-json', {
describe: 'Turn on Standard JSON Input / Output mode.',
type: 'boolean'
})
.option('output-dir', {
alias: 'o',
describe: 'Output directory for the contracts.',
type: 'string'
})
.version(solc.version())
.showHelpOnFail(false, 'Specify --help for available options')
.help()

var argv = yargs.argv;
var files = argv._;
var destination = argv['output-dir'] || '.'
var commander = require('commander');

var program = new commander.Command();
program.name('solcjs');
program.version(solc.version());
program
.option('--version', 'Show version and exit.')
.option('--optimize', 'Enable bytecode optimizer.')
.option('--bin', 'Binary of the contracts in hex.')
.option('--abi', 'ABI of the contracts.')
.option('--standard-json', 'Turn on Standard JSON Input / Output mode.')
.option('-o, --output-dir <output-directory>', 'Output directory for the contracts.');
program.parse(process.argv);

var files = program.args;
var destination = program.outputDir || '.'

function abort (msg) {
console.error(msg || 'Error occured');
process.exit(1);
}

if (argv['standard-json']) {
if (program.standardJson) {
var input = fs.readFileSync(process.stdin.fd).toString('utf8');
var output = solc.compileStandardWrapper(input);

Expand Down Expand Up @@ -85,7 +66,7 @@ if (argv['standard-json']) {
process.exit(1);
}

if (!(argv.bin || argv.abi)) {
if (!(program.bin || program.abi)) {
abort('Invalid option selected, must specify either --bin or --abi');
}

Expand All @@ -103,7 +84,7 @@ var output = JSON.parse(solc.compileStandardWrapper(JSON.stringify({
language: 'Solidity',
settings: {
optimizer: {
enabled: argv.optimize
enabled: program.optimize
},
outputSelection: {
'*': {
Expand Down Expand Up @@ -146,11 +127,11 @@ for (var fileName in output.contracts) {
var contractFileName = fileName + ':' + contractName;
contractFileName = contractFileName.replace(/[:./\\]/g, '_');

if (argv.bin) {
if (program.bin) {
writeFile(contractFileName + '.bin', output.contracts[fileName][contractName].evm.bytecode.object);
}

if (argv.abi) {
if (program.abi) {
writeFile(contractFileName + '.abi', JSON.stringify(output.contracts[fileName][contractName].abi));
}
}
Expand Down

0 comments on commit d268ffa

Please sign in to comment.