Skip to content

Commit

Permalink
Rename modifiers.0.func to script
Browse files Browse the repository at this point in the history
  • Loading branch information
j178 committed Jan 29, 2023
1 parent 565e06b commit 0a09b32
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
8 changes: 4 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ type Block struct {
}

type Modifier struct {
Name string `yaml:"name" mapstructure:"name"`
Func string `yaml:"func,omitempty" mapstructure:"func"`
Name string `yaml:"name" mapstructure:"name"`
Script string `yaml:"script,omitempty" mapstructure:"script"`
}

type CodeConfig struct {
Expand Down Expand Up @@ -191,11 +191,11 @@ func Default() *Config {
Blocks: []Block{
{
Name: "beforeMarker", Template: fmt.Sprintf(
`package main
`package main
{{ if .NeedsDefinition -}} import . "%s" {{- end }}
`, GoTestUtilsModPath,
),
),
},
},
Modifiers: []Modifier{
Expand Down
26 changes: 16 additions & 10 deletions lang/tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,23 @@ func getModifiers(lang Lang, modifiersMap map[string]ModifierFunc) (ans []Modifi
}

for _, m := range modifiers.([]any) {
name := m.(map[string]any)["name"].(string)
fun := m.(map[string]any)["func"]
if f, ok := modifiersMap[name]; ok {
ans = append(ans, f)
} else if fun != nil {
// TODO support js func
_ = fun
hclog.L().Warn("custom modifier not supported yet, ignored", "modifier", name)
} else {
hclog.L().Warn("modifier not supported, ignored", "modifier", name)
m := m.(map[string]any)
name, script := "", ""

if m["name"] != nil {
name = m["name"].(string)
if f, ok := modifiersMap[name]; ok {
ans = append(ans, f)
continue
}
}
if m["script"] != nil {
// TODO support js script
script = m["script"].(string)
hclog.L().Warn("custom modifier function not supported yet, ignored", "modifier", name, "script", script)
continue
}
hclog.L().Warn("invalid modifier, ignored", "modifier", name, "script", script)
}
return
}
Expand Down

0 comments on commit 0a09b32

Please sign in to comment.