From d268ffae2087d800390f32dac1e71a460335a099 Mon Sep 17 00:00:00 2001 From: Micah Zoltu Date: Sun, 27 Oct 2019 12:20:58 +0800 Subject: [PATCH] Replaces yargs with commander. Works towards resolving #361. Yargs brings in ~26 packages while commander brings in 1. --- package.json | 6 +++--- solcjs | 61 ++++++++++++++++++---------------------------------- 2 files changed, 24 insertions(+), 43 deletions(-) diff --git a/package.json b/package.json index b03ac2a9..727d8ea0 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/solcjs b/solcjs index f379b9f3..a2b79c6f 100755 --- a/solcjs +++ b/solcjs @@ -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 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); @@ -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'); } @@ -103,7 +84,7 @@ var output = JSON.parse(solc.compileStandardWrapper(JSON.stringify({ language: 'Solidity', settings: { optimizer: { - enabled: argv.optimize + enabled: program.optimize }, outputSelection: { '*': { @@ -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)); } }