@@ -512,9 +512,10 @@ function jsonToGov2(json, options = {}) {
512
512
if ( typeof module != 'undefined' ) {
513
513
if ( ! module . parent ) {
514
514
let filename = null
515
+ let options = { }
515
516
516
- function jsonToGoWithErrorHandling ( json ) {
517
- const output = jsonToGov2 ( json )
517
+ function jsonToGoWithErrorHandling ( json , options ) {
518
+ const output = jsonToGov2 ( json , options )
518
519
if ( output . error ) {
519
520
console . error ( output . error )
520
521
process . exitCode = 1
@@ -531,11 +532,32 @@ if (typeof module != 'undefined') {
531
532
return
532
533
}
533
534
534
- const argument = val . replace ( / - / g, '' )
535
- switch ( argument ) {
535
+ let argument = {
536
+ arg : val . split ( "=" ) [ 0 ] . replace ( / ^ - + / , '' ) ,
537
+ value : val . split ( "=" ) [ 1 ] || true ,
538
+ }
539
+
540
+ if ( argument . arg . startsWith ( "no-" ) ) {
541
+ argument . arg = argument . arg . replace ( / ^ n o - / , '' )
542
+ argument . value = ! argument . value
543
+ }
544
+
545
+ switch ( argument . arg ) {
536
546
case "big" :
537
547
console . warn ( `Warning: The argument '${ argument } ' has been deprecated and has no effect anymore` )
538
548
break
549
+ case "typename" :
550
+ options . typename = argument . value
551
+ break
552
+ case "flatten" :
553
+ options . flatten = argument . value
554
+ break
555
+ case "examples" :
556
+ options . example = argument . value
557
+ break
558
+ case "all-omitempty" :
559
+ options . allOmitempty = argument . value
560
+ break
539
561
default :
540
562
console . error ( `Unexpected argument ${ val } received` )
541
563
process . exit ( 1 )
@@ -545,7 +567,7 @@ if (typeof module != 'undefined') {
545
567
if ( filename ) {
546
568
const fs = require ( 'fs' ) ;
547
569
const json = fs . readFileSync ( filename , 'utf8' ) ;
548
- jsonToGoWithErrorHandling ( json )
570
+ jsonToGoWithErrorHandling ( json , options )
549
571
return
550
572
}
551
573
@@ -556,7 +578,7 @@ if (typeof module != 'undefined') {
556
578
} )
557
579
process . stdin . on ( 'end' , function ( ) {
558
580
const json = Buffer . concat ( bufs ) . toString ( 'utf8' )
559
- jsonToGoWithErrorHandling ( json )
581
+ jsonToGoWithErrorHandling ( json , options )
560
582
} )
561
583
return
562
584
}
0 commit comments