@@ -11,48 +11,29 @@ var smtsolver = require('./smtsolver.js');
11
11
// FIXME: remove annoying exception catcher of Emscripten
12
12
// see https://github.com/chriseth/browser-solidity/issues/167
13
13
process . removeAllListeners ( 'uncaughtException' ) ;
14
-
15
- var yargs = require ( 'yargs' )
16
- . usage ( 'Usage: $0 [options] [input_file...]' )
17
- . option ( 'version' , {
18
- describe : 'Show version and exit.' ,
19
- type : 'boolean'
20
- } )
21
- . option ( 'optimize' , {
22
- describe : 'Enable bytecode optimizer.' ,
23
- type : 'boolean'
24
- } )
25
- . option ( 'bin' , {
26
- describe : 'Binary of the contracts in hex.' ,
27
- type : 'boolean'
28
- } )
29
- . option ( 'abi' , {
30
- describe : 'ABI of the contracts.' ,
31
- type : 'boolean'
32
- } )
33
- . option ( 'standard-json' , {
34
- describe : 'Turn on Standard JSON Input / Output mode.' ,
35
- type : 'boolean'
36
- } )
37
- . option ( 'output-dir' , {
38
- alias : 'o' ,
39
- describe : 'Output directory for the contracts.' ,
40
- type : 'string'
41
- } )
42
- . version ( solc . version ( ) )
43
- . showHelpOnFail ( false , 'Specify --help for available options' )
44
- . help ( )
45
-
46
- var argv = yargs . argv ;
47
- var files = argv . _ ;
48
- var destination = argv [ 'output-dir' ] || '.'
14
+ var commander = require ( 'commander' ) ;
15
+
16
+ var program = new commander . Command ( ) ;
17
+ program . name ( 'solcjs' ) ;
18
+ program . version ( solc . version ( ) ) ;
19
+ program
20
+ . option ( '--version' , 'Show version and exit.' )
21
+ . option ( '--optimize' , 'Enable bytecode optimizer.' )
22
+ . option ( '--bin' , 'Binary of the contracts in hex.' )
23
+ . option ( '--abi' , 'ABI of the contracts.' )
24
+ . option ( '--standard-json' , 'Turn on Standard JSON Input / Output mode.' )
25
+ . option ( '-o, --output-dir <output-directory>' , 'Output directory for the contracts.' ) ;
26
+ program . parse ( process . argv ) ;
27
+
28
+ var files = program . args ;
29
+ var destination = program . outputDir || '.'
49
30
50
31
function abort ( msg ) {
51
32
console . error ( msg || 'Error occured' ) ;
52
33
process . exit ( 1 ) ;
53
34
}
54
35
55
- if ( argv [ 'standard-json' ] ) {
36
+ if ( program . standardJson ) {
56
37
var input = fs . readFileSync ( process . stdin . fd ) . toString ( 'utf8' ) ;
57
38
var output = solc . compileStandardWrapper ( input ) ;
58
39
@@ -85,7 +66,7 @@ if (argv['standard-json']) {
85
66
process . exit ( 1 ) ;
86
67
}
87
68
88
- if ( ! ( argv . bin || argv . abi ) ) {
69
+ if ( ! ( program . bin || program . abi ) ) {
89
70
abort ( 'Invalid option selected, must specify either --bin or --abi' ) ;
90
71
}
91
72
@@ -103,7 +84,7 @@ var output = JSON.parse(solc.compileStandardWrapper(JSON.stringify({
103
84
language : 'Solidity' ,
104
85
settings : {
105
86
optimizer : {
106
- enabled : argv . optimize
87
+ enabled : program . optimize
107
88
} ,
108
89
outputSelection : {
109
90
'*' : {
@@ -146,11 +127,11 @@ for (var fileName in output.contracts) {
146
127
var contractFileName = fileName + ':' + contractName ;
147
128
contractFileName = contractFileName . replace ( / [: ./ \\ ] / g, '_' ) ;
148
129
149
- if ( argv . bin ) {
130
+ if ( program . bin ) {
150
131
writeFile ( contractFileName + '.bin' , output . contracts [ fileName ] [ contractName ] . evm . bytecode . object ) ;
151
132
}
152
133
153
- if ( argv . abi ) {
134
+ if ( program . abi ) {
154
135
writeFile ( contractFileName + '.abi' , JSON . stringify ( output . contracts [ fileName ] [ contractName ] . abi ) ) ;
155
136
}
156
137
}
0 commit comments