@@ -38,7 +38,8 @@ program
38
38
. option ( '--abi' , 'ABI of the contracts.' )
39
39
. option ( '--standard-json' , 'Turn on Standard JSON Input / Output mode.' )
40
40
. option ( '--base-path <path>' , 'Automatically resolve all imports inside the given path.' )
41
- . option ( '-o, --output-dir <output-directory>' , 'Output directory for the contracts.' ) ;
41
+ . option ( '-o, --output-dir <output-directory>' , 'Output directory for the contracts.' )
42
+ . option ( '-p, --pretty-json' , 'Pretty-print all JSON output.' , false ) ;
42
43
43
44
program . parse ( process . argv ) ;
44
45
const options = program . opts ( ) ;
@@ -91,18 +92,26 @@ function stripBasePath(sourcePath) {
91
92
return withUnixPathSeparators ( relativeSourcePath ) ;
92
93
}
93
94
95
+ function toFormattedJson ( input ) {
96
+ return JSON . stringify ( input , null , program . prettyJson ? 4 : 0 ) ;
97
+ }
98
+
99
+ function reformatJsonIfRequested ( inputJson ) {
100
+ return ( program . prettyJson ? toFormattedJson ( JSON . parse ( inputJson ) ) : inputJson ) ;
101
+ }
102
+
94
103
var callbacks = undefined
95
104
if ( options . basePath || ! options . standardJson )
96
105
callbacks = { 'import' : readFileCallback } ;
97
106
98
107
if ( options . standardJson ) {
99
108
var input = fs . readFileSync ( process . stdin . fd ) . toString ( 'utf8' ) ;
100
- var output = solc . compile ( input , callbacks ) ;
109
+ var output = reformatJsonIfRequested ( solc . compile ( input , callbacks ) ) ;
101
110
102
111
try {
103
112
var inputJSON = smtchecker . handleSMTQueries ( JSON . parse ( input ) , JSON . parse ( output ) , smtsolver . smtSolver ) ;
104
113
if ( inputJSON ) {
105
- output = solc . compile ( JSON . stringify ( inputJSON ) , callbacks ) ;
114
+ output = reformatJsonIfRequested ( solc . compile ( JSON . stringify ( inputJSON ) , callbacks ) ) ;
106
115
}
107
116
}
108
117
catch ( e ) {
@@ -118,7 +127,7 @@ if (options.standardJson) {
118
127
outputJSON . errors = [ ]
119
128
}
120
129
outputJSON . errors . push ( addError ) ;
121
- output = JSON . stringify ( outputJSON ) ;
130
+ output = toFormattedJson ( outputJSON ) ;
122
131
}
123
132
124
133
console . log ( output ) ;
@@ -195,7 +204,7 @@ for (var fileName in output.contracts) {
195
204
}
196
205
197
206
if ( options . abi ) {
198
- writeFile ( contractFileName + '.abi' , JSON . stringify ( output . contracts [ fileName ] [ contractName ] . abi ) ) ;
207
+ writeFile ( contractFileName + '.abi' , toFormattedJson ( output . contracts [ fileName ] [ contractName ] . abi ) ) ;
199
208
}
200
209
}
201
210
}
0 commit comments