address some comments

This commit is contained in:
Shreyas Goenka 2023-05-17 15:00:27 +02:00
parent 5771b62afd
commit 9a70861e4b
No known key found for this signature in database
GPG Key ID: 92A07DF49CCB0622
3 changed files with 10 additions and 11 deletions

View File

@ -12,7 +12,7 @@ import (
const ConfigFileName = "config.json"
const SchemaFileName = "schema.json"
const TemplateDirname = "template"
const TemplateDirName = "template"
var initCmd = &cobra.Command{
Use: "init",
@ -58,7 +58,7 @@ var initCmd = &cobra.Command{
}
// materialize the template
return template.WalkFileTree(config, filepath.Join(args[0], TemplateDirname), targetDir)
return template.WalkFileTree(config, filepath.Join(args[0], TemplateDirName), targetDir)
},
}

View File

@ -7,11 +7,11 @@ import (
"text/template"
)
// Executes the template by appling config on it. Returns the materialized config
// Executes the template by applying config on it. Returns the materialized config
// as a string
func executeTemplate(config map[string]any, templateDefination string) (string, error) {
// configure template with helper functions
tmpl, err := template.New("foo").Funcs(HelperFuncs).Parse(templateDefination)
tmpl, err := template.New("").Funcs(HelperFuncs).Parse(templateDefination)
if err != nil {
return "", err
}

View File

@ -92,13 +92,6 @@ func validateType(v any, fieldType FieldType) error {
// TODO: add validation check for regex for string types
func (schema Schema) ValidateConfig(config map[string]any) error {
// assert all fields are defined in
for k := range schema {
if _, ok := config[k]; !ok {
return fmt.Errorf("input parameter %s is not defined in config", k)
}
}
// validate types defined in config
for k, v := range config {
fieldMetadata, ok := schema[k]
@ -110,5 +103,11 @@ func (schema Schema) ValidateConfig(config map[string]any) error {
return fmt.Errorf("incorrect type for %s. %w", k, err)
}
}
// assert all fields are defined in
for k := range schema {
if _, ok := config[k]; !ok {
return fmt.Errorf("input parameter %s is not defined in config", k)
}
}
return nil
}