mirror of
https://github.com/davidallendj/configurator.git
synced 2025-12-20 03:27:02 -07:00
refactor: more code cleanup and simplification
This commit is contained in:
parent
32065dc163
commit
a7b8fb0de5
11 changed files with 268 additions and 398 deletions
43
pkg/generator/params.go
Normal file
43
pkg/generator/params.go
Normal 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]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue