Skip to content

Commit 9dd5bc8

Browse files
committed
cdt-67 added command
Signed-off-by: ashish <[email protected]>
1 parent dd473d6 commit 9dd5bc8

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ USAGE
5050
# Commands
5151
<!-- commands -->
5252
* [`cdt autocomplete [SHELL]`](#cdt-autocomplete-shell)
53-
* [`cdt avro [GET_SCHEMA|TO_JSON|TO_AVRO|TO_CSV]`](#cdt-avro-get_schemato_jsonto_avroto_csv)
53+
* [`cdt avro [COMMAND]`](#cdt-avro-command)
5454
* [`cdt bundlephobia [PACKAGE]`](#cdt-bundlephobia-package)
5555
* [`cdt crypto [STRING]`](#cdt-crypto-string)
5656
* [`cdt datetime [DATE]`](#cdt-datetime-date)
@@ -81,15 +81,16 @@ EXAMPLES
8181

8282
_See code: [@oclif/plugin-autocomplete](https://github.com/oclif/plugin-autocomplete/blob/v0.1.4/src/commands/autocomplete/index.ts)_
8383

84-
## `cdt avro [GET_SCHEMA|TO_JSON|TO_AVRO|TO_CSV]`
84+
## `cdt avro [COMMAND]`
8585

8686
Avro Utility command
8787

8888
```
8989
USAGE
90-
$ cdt avro [GET_SCHEMA|TO_JSON|TO_AVRO|TO_CSV]
90+
$ 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 & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@ 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

28-
static args = [{name: `${Avro.SupportedCommands.join('|')}`}] // operation type
29+
static args = [{name: 'command'}] // operation type
2930
/*
3031
* input,output, and operation are all must
3132
* */
@@ -40,11 +41,16 @@ 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(args.command)
46+
args.command = args.command
47+
else
48+
args.command = flags.command
49+
4350
if (!args.command)
4451
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()
52+
else // if exists then make Lower Case
53+
args.command= args.command.toLowerCase()
4854

4955
// output is not mendatory for 'get_schema' command
5056
if (args.command !== Avro.GET_SCHEMA && !flags.output)

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)