Resolve ConfigKit paths from declaration origins

This commit is contained in:
2026-09-13 16:48:44 +00:00
parent 69295d72c9
commit 320de32a61
7 changed files with 326 additions and 10 deletions

View File

@@ -1,6 +1,8 @@
package config
import (
"path/filepath"
configkit "gitea.maximumdirect.net/eric/ConfigKit"
)
@@ -8,26 +10,43 @@ import (
// boundary. It is intentionally narrow: configuration discovery and CLI flag
// parsing remain outside this package.
type LoadOptions struct {
Profile string
Overrides []configkit.Override
Profile string
Overrides []configkit.Override
InvocationDirectory string
}
// loadDocument is the private ConfigKit load boundary under construction.
// Production commands continue to use the existing version 4 loader until the
// runtime conversion and command wiring are complete.
func loadDocument(path string, options LoadOptions) (*configkit.Result[Document], error) {
return loadDocumentSource(configkit.File(path), options)
return loadDocumentWithSource(configkit.File(path), options, true)
}
func loadDocumentSource(source configkit.Source, options LoadOptions) (*configkit.Result[Document], error) {
state := newDocumentLoadState()
return loadDocumentWithSource(source, options, false)
}
func loadDocumentWithSource(source configkit.Source, options LoadOptions, imports bool) (*configkit.Result[Document], error) {
state := newDocumentLoadState(options.InvocationDirectory)
return configkit.Load(source, configkit.Options[Document]{
Definition: documentDefinition(state),
Imports: imports,
Profile: options.Profile,
Overrides: options.Overrides,
})
}
func cleanInvocationDirectory(value string) string {
if value == "" {
return ""
}
absolute, err := filepath.Abs(value)
if err != nil {
return ""
}
return filepath.Clean(absolute)
}
func documentDefinition(state *documentLoadState) configkit.Definition[Document] {
return configkit.Definition[Document]{
Defaults: documentDefaults,