@@ -498,9 +498,10 @@ function jsonToGo(json, options = {}) {
498
498
499
499
if ( typeof module === 'undefined' || ! module . parent ) {
500
500
let filename = null
501
+ let options = { }
501
502
502
- function jsonToGoWithErrorHandling ( json ) {
503
- const output = jsonToGo ( json )
503
+ function jsonToGoWithErrorHandling ( json , options ) {
504
+ const output = jsonToGo ( json , options )
504
505
if ( output . error ) {
505
506
console . error ( output . error )
506
507
process . exitCode = 1
@@ -517,11 +518,32 @@ if (typeof module === 'undefined' || !module.parent) {
517
518
return
518
519
}
519
520
520
- const argument = val . replace ( / - / g, '' )
521
- switch ( argument ) {
521
+ let argument = {
522
+ arg : val . split ( "=" ) [ 0 ] . replace ( / ^ - + / , '' ) ,
523
+ value : val . split ( "=" ) [ 1 ] || true ,
524
+ }
525
+
526
+ if ( argument . arg . startsWith ( "no-" ) ) {
527
+ argument . arg = argument . arg . replace ( / ^ n o - / , '' )
528
+ argument . value = ! argument . value
529
+ }
530
+
531
+ switch ( argument . arg ) {
522
532
case "big" :
523
533
console . warn ( `Warning: The argument '${ argument } ' has been deprecated and has no effect anymore` )
524
534
break
535
+ case "typename" :
536
+ options . typename = argument . value
537
+ break
538
+ case "flatten" :
539
+ options . flatten = argument . value
540
+ break
541
+ case "examples" :
542
+ options . example = argument . value
543
+ break
544
+ case "all-omitempty" :
545
+ options . allOmitempty = argument . value
546
+ break
525
547
default :
526
548
console . error ( `Unexpected argument ${ val } received` )
527
549
process . exit ( 1 )
@@ -531,7 +553,7 @@ if (typeof module === 'undefined' || !module.parent) {
531
553
if ( filename ) {
532
554
const fs = require ( 'fs' ) ;
533
555
const json = fs . readFileSync ( filename , 'utf8' ) ;
534
- jsonToGoWithErrorHandling ( json )
556
+ jsonToGoWithErrorHandling ( json , options )
535
557
}
536
558
537
559
if ( ! filename ) {
@@ -541,7 +563,7 @@ if (typeof module === 'undefined' || !module.parent) {
541
563
} )
542
564
process . stdin . on ( 'end' , function ( ) {
543
565
const json = Buffer . concat ( bufs ) . toString ( 'utf8' )
544
- jsonToGoWithErrorHandling ( json )
566
+ jsonToGoWithErrorHandling ( json , options )
545
567
} )
546
568
}
547
569
}
0 commit comments