@@ -498,9 +498,10 @@ function jsonToGo(json, options = {}) {
498498
499499if ( typeof module === 'undefined' || ! module . parent ) {
500500 let filename = null
501+ let options = { }
501502
502- function jsonToGoWithErrorHandling ( json ) {
503- const output = jsonToGo ( json )
503+ function jsonToGoWithErrorHandling ( json , options ) {
504+ const output = jsonToGo ( json , options )
504505 if ( output . error ) {
505506 console . error ( output . error )
506507 process . exitCode = 1
@@ -517,11 +518,32 @@ if (typeof module === 'undefined' || !module.parent) {
517518 return
518519 }
519520
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 ) {
522532 case "big" :
523533 console . warn ( `Warning: The argument '${ argument } ' has been deprecated and has no effect anymore` )
524534 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
525547 default :
526548 console . error ( `Unexpected argument ${ val } received` )
527549 process . exit ( 1 )
@@ -531,7 +553,7 @@ if (typeof module === 'undefined' || !module.parent) {
531553 if ( filename ) {
532554 const fs = require ( 'fs' ) ;
533555 const json = fs . readFileSync ( filename , 'utf8' ) ;
534- jsonToGoWithErrorHandling ( json )
556+ jsonToGoWithErrorHandling ( json , options )
535557 }
536558
537559 if ( ! filename ) {
@@ -541,7 +563,7 @@ if (typeof module === 'undefined' || !module.parent) {
541563 } )
542564 process . stdin . on ( 'end' , function ( ) {
543565 const json = Buffer . concat ( bufs ) . toString ( 'utf8' )
544- jsonToGoWithErrorHandling ( json )
566+ jsonToGoWithErrorHandling ( json , options )
545567 } )
546568 }
547569}
0 commit comments