Skip to content

Commit 7783f15

Browse files
authored
Merge pull request #83 from codingtools/cdt-67
cdt-67 added docs
2 parents 47037ee + 68759e3 commit 7783f15

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ USAGE
9090
$ cdt avro [COMMAND]
9191
9292
OPTIONS
93+
-c, --command=command commands supported: get_schema,to_json,to_avro,to_csv
9394
-f, --file=file input file path
9495
-h, --help show CLI help
9596
-o, --output=output output file path

src/commands/avro.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ export default class Avro extends Command {
1717

1818
// do not change order otherwise we need to change order in getCommand() also
1919
static SupportedCommands = [Avro.GET_SCHEMA, Avro.TO_JSON, Avro.TO_AVRO, Avro.TO_CSV]
20+
2021
static flags = {
2122
help: flags.help({char: 'h'}),
23+
command: flags.string({char: 'c' , description: `commands supported: ${Avro.SupportedCommands}`}),
2224
file: flags.string({char: 'f' , description: 'input file path'}),
2325
output: flags.string({char: 'o' , description: 'output file path'}),
2426
schemaType: flags.string({char: 't' , description: 'schema type file path'}),
25-
2627
}
2728

2829
static args = [{name: 'command'}] // operation type
@@ -40,11 +41,14 @@ export default class Avro extends Command {
4041
private checkParameters(flags: any, args: any) {
4142
if (!flags.file)
4243
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+
4348
if (!args.command)
4449
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()
4852

4953
// output is not mendatory for 'get_schema' command
5054
if (args.command !== Avro.GET_SCHEMA && !flags.output)
@@ -110,15 +114,15 @@ export default class Avro extends Command {
110114
let prependHeader = true // only write on the first line
111115
avro.createFileDecoder(flags.file)
112116
.on('data', function (recordStr) {
113-
// @ts-ignore
117+
// @ts-ignore
114118
let json = JSON.parse(JSON.stringify(recordStr))
115119
Json2Csv.json2csv(json, (err?: Error, csv?: string) => {
116120
if (csv) {
117-
// @ts-ignore
121+
// @ts-ignore
118122
Utilities.appendStringToFile(this, flags.output, csv + '\n')
119123
}
120124
if (err) {
121-
// @ts-ignore
125+
// @ts-ignore
122126
Logger.error(this, err.toString())
123127
}
124128
}, {prependHeader})

test/commands/avro.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,12 @@ describe('avro', () => {
8181
expect(ctx.stdout).to.contain('success')
8282
})
8383

84+
test
85+
.stdout()
86+
.command(['avro', '-f', 'test/resources/avro/person.avro', '-o', 'test/resources/avro/output/person.csv','-c', 'to_csv'])
87+
.it('if to_csv commands run -c flag', ctx => {
88+
expect(ctx.stdout).to.contain('success')
89+
})
90+
8491
})
8592

0 commit comments

Comments
 (0)