refactor: more code cleanup and simplification

This commit is contained in:
David Allen 2024-11-21 14:14:44 -07:00
parent 32065dc163
commit a7b8fb0de5
Signed by: towk
GPG key ID: 793B2924A49B3A3F
11 changed files with 268 additions and 398 deletions

43
pkg/generator/params.go Normal file
View file

@ -0,0 +1,43 @@
package generator
import (
configurator "github.com/OpenCHAMI/configurator/pkg"
"github.com/OpenCHAMI/configurator/pkg/client"
"github.com/OpenCHAMI/configurator/pkg/config"
)
type (
// Params used by the generator
Params struct {
Templates map[string]Template
Files map[string][]byte
ClientOpts []client.Option
Verbose bool
}
Option func(Params)
)
func ToParams(opts ...Option) Params {
params := Params{}
for _, opt := range opts {
opt(params)
}
return params
}
func WithClientOpts(opts ...client.Option) Option {
return func(p Params) {
p.ClientOpts = opts
}
}
func WithTemplates(templates map[string]Template) Option {
return func(p Params) {
p.Templates = templates
}
}
// Helper function to get the target in generator.Generate() plugin implementations.
func GetTarget(config *config.Config, key string) configurator.Target {
return config.Targets[key]
}