41 lines
1.4 KiB
Go
41 lines
1.4 KiB
Go
// Package configuration supplies construction helpers for internal tests.
|
|
package configuration
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"go.maximumdirect.net/configkit"
|
|
adapter "go.maximumdirect.net/promptkit/internal/configuration"
|
|
"go.maximumdirect.net/promptkit/internal/settings"
|
|
)
|
|
|
|
type application struct {
|
|
PromptKit settings.Settings `yaml:"promptkit"`
|
|
Other map[string]any `yaml:",inline"`
|
|
}
|
|
|
|
// Capture loads the provided native inputs with component rules and captures
|
|
// the resulting resources. Inputs specify their own destinations and context.
|
|
func Capture(main configkit.Input, underlays []configkit.Underlay) (*adapter.Snapshot, error) {
|
|
definition := configkit.Definition[application]{
|
|
SequenceIdentities: adapter.SequenceIdentities(),
|
|
Sensitive: adapter.Sensitive,
|
|
Resolve: func(value *application, resolution *configkit.Resolution) error {
|
|
adapter.Resolve(&value.PromptKit, resolution)
|
|
return nil
|
|
},
|
|
Validate: func(value *application, validation *configkit.Validation) {
|
|
adapter.Validate(&value.PromptKit, validation)
|
|
},
|
|
}
|
|
result, err := configkit.LoadLayered(main, configkit.LayeredOptions[application]{Definition: definition, Underlays: underlays})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
view, ok := result.InspectSubtree(configkit.Keys("promptkit"))
|
|
if !ok {
|
|
return nil, fmt.Errorf("configuration inspection unavailable")
|
|
}
|
|
return adapter.Capture(&result.Config.PromptKit, view, result.Diagnostics())
|
|
}
|