mirror of https://github.com/databricks/cli.git
address some comments
This commit is contained in:
parent
5771b62afd
commit
9a70861e4b
|
@ -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)
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue