@@ -17,12 +17,13 @@ export default class Avro extends Command {
17
17
18
18
// do not change order otherwise we need to change order in getCommand() also
19
19
static SupportedCommands = [ Avro . GET_SCHEMA , Avro . TO_JSON , Avro . TO_AVRO , Avro . TO_CSV ]
20
+
20
21
static flags = {
21
22
help : flags . help ( { char : 'h' } ) ,
23
+ command : flags . string ( { char : 'c' , description : `commands supported: ${ Avro . SupportedCommands } ` } ) ,
22
24
file : flags . string ( { char : 'f' , description : 'input file path' } ) ,
23
25
output : flags . string ( { char : 'o' , description : 'output file path' } ) ,
24
26
schemaType : flags . string ( { char : 't' , description : 'schema type file path' } ) ,
25
-
26
27
}
27
28
28
29
static args = [ { name : 'command' } ] // operation type
@@ -40,11 +41,14 @@ export default class Avro extends Command {
40
41
private checkParameters ( flags : any , args : any ) {
41
42
if ( ! flags . file )
42
43
Logger . error ( this , 'Input file is not provided' )
44
+
45
+ if ( flags . command ) // if -c flag have value, then override
46
+ args . command = flags . command
47
+
43
48
if ( ! args . command )
44
49
Logger . error ( this , 'Command is empty or not provided, supported:' + Avro . SupportedCommands )
45
-
46
- // if exists then make it upperCase
47
- args . command = args . command . toLowerCase ( )
50
+ else // if exists then make Lower Case
51
+ args . command = args . command . toLowerCase ( )
48
52
49
53
// output is not mendatory for 'get_schema' command
50
54
if ( args . command !== Avro . GET_SCHEMA && ! flags . output )
@@ -110,15 +114,15 @@ export default class Avro extends Command {
110
114
let prependHeader = true // only write on the first line
111
115
avro . createFileDecoder ( flags . file )
112
116
. on ( 'data' , function ( recordStr ) {
113
- // @ts -ignore
117
+ // @ts -ignore
114
118
let json = JSON . parse ( JSON . stringify ( recordStr ) )
115
119
Json2Csv . json2csv ( json , ( err ?: Error , csv ?: string ) => {
116
120
if ( csv ) {
117
- // @ts -ignore
121
+ // @ts -ignore
118
122
Utilities . appendStringToFile ( this , flags . output , csv + '\n' )
119
123
}
120
124
if ( err ) {
121
- // @ts -ignore
125
+ // @ts -ignore
122
126
Logger . error ( this , err . toString ( ) )
123
127
}
124
128
} , { prependHeader} )
0 commit comments