@@ -24,21 +24,25 @@ func GenerateWithTemplateCmd() *cobra.Command {
2424 generateWithTemplateCmd := & cobra.Command {
2525 Use : "generate-with-template template-path fields-definition-path" ,
2626 Short : "Generate a corpus" ,
27- Long : "Generate a bulk request corpus given a template path and a fields definition path" ,
27+ Long : "Generate a bulk request corpus given a template path. The fields definition path is optional as long as the config has fields definitions. " ,
2828 Args : func (cmd * cobra.Command , args []string ) error {
2929 var errs []error
30- if len (args ) != 2 {
31- return errors .New ("you must pass the template path and the fields definition path" )
30+ if len (args ) != 1 {
31+ return errors .New ("you must pass the template path, fields definitions path is optional " )
3232 }
3333
3434 templatePath = args [0 ]
3535 if templatePath == "" {
3636 errs = append (errs , errors .New ("you must provide a not empty template path argument" ))
3737 }
3838
39- fieldsDefinitionPath = args [1 ]
40- if fieldsDefinitionPath == "" {
41- errs = append (errs , errors .New ("you must provide a not empty fields definition path argument" ))
39+ if len (args ) > 1 {
40+ fieldsDefinitionPath = args [1 ]
41+ if fieldsDefinitionPath == "" {
42+ errs = append (errs , errors .New ("you must provide a not empty fields definition path argument" ))
43+ }
44+ } else {
45+ fmt .Println ("Fields definition path not provided, using fields definitions from config" )
4246 }
4347
4448 if len (errs ) > 0 {
@@ -56,6 +60,14 @@ func GenerateWithTemplateCmd() *cobra.Command {
5660 return err
5761 }
5862
63+ if ! cfg .HasFieldsMappings () && fieldsDefinitionPath == "" {
64+ return errors .New ("fields types not found in config and fields definition path not provided" )
65+ }
66+
67+ if cfg .HasFieldsMappings () && fieldsDefinitionPath != "" {
68+ return errors .New ("fields types found in config and fields definition path provided, use only one" )
69+ }
70+
5971 fc , err := corpus .NewGeneratorWithTemplate (cfg , fs , location , templateType )
6072 if err != nil {
6173 return err
0 commit comments