Use native ConfigKit application loading
This commit is contained in:
@@ -108,6 +108,10 @@ Do not publish, tag, push, or invoke the release script.
|
|||||||
|
|
||||||
## Stage 2: Move Application Loading And Resolution To Native v1.2.0
|
## Stage 2: Move Application Loading And Resolution To Native v1.2.0
|
||||||
|
|
||||||
|
**Complete.** Application loading uses native search and v1.2.0 resolution;
|
||||||
|
`go build ./internal/config` passed with Go 1.27.4. Adapter and test migration
|
||||||
|
remain assigned below.
|
||||||
|
|
||||||
**Primary files:** `internal/config/document.go`, `load.go`, and `settings.go`.
|
**Primary files:** `internal/config/document.go`, `load.go`, and `settings.go`.
|
||||||
|
|
||||||
**Work**
|
**Work**
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
|
||||||
"gitea.maximumdirect.net/eric/scriptorium/internal/defaults"
|
"gitea.maximumdirect.net/eric/scriptorium/internal/defaults"
|
||||||
renderformat "gitea.maximumdirect.net/eric/scriptorium/internal/format"
|
renderformat "gitea.maximumdirect.net/eric/scriptorium/internal/format"
|
||||||
|
"go.maximumdirect.net/configkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Document is Scriptorium's ConfigKit-native application configuration shape.
|
// Document is Scriptorium's ConfigKit-native application configuration shape.
|
||||||
@@ -58,16 +58,14 @@ func documentDefaults() Document {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func resolveDocument(document *Document, resolution *configkit.Resolution) error {
|
func resolveDocument(document *Document, resolution *configkit.Resolution) error {
|
||||||
normalizePath := func(path configkit.Path, value *string) bool {
|
normalizePath := func(path configkit.Path, value *string) {
|
||||||
cleaned := strings.TrimSpace(*value)
|
cleaned := strings.TrimSpace(*value)
|
||||||
if cleaned != "" {
|
if cleaned != "" {
|
||||||
cleaned = filepath.Clean(cleaned)
|
cleaned = filepath.Clean(cleaned)
|
||||||
}
|
}
|
||||||
if cleaned != *value {
|
if cleaned != *value {
|
||||||
configkit.Normalize(resolution, path, value, cleaned, "normalized application path")
|
configkit.Normalize(resolution, path, value, cleaned, "normalized application path")
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
normalizeString := func(path configkit.Path, value *string, normalized, reason string) {
|
normalizeString := func(path configkit.Path, value *string, normalized, reason string) {
|
||||||
if normalized != *value {
|
if normalized != *value {
|
||||||
@@ -75,14 +73,10 @@ func resolveDocument(document *Document, resolution *configkit.Resolution) error
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sourcePathsChanged := false
|
|
||||||
for i := range document.PromptKitSources {
|
for i := range document.PromptKitSources {
|
||||||
path := configkit.Keys("promptkit_sources").Index(i)
|
path := configkit.Keys("promptkit_sources").Index(i)
|
||||||
sourcePathsChanged = normalizePath(path.Key("file"), &document.PromptKitSources[i].File) || sourcePathsChanged
|
normalizePath(path.Key("file"), &document.PromptKitSources[i].File)
|
||||||
sourcePathsChanged = normalizePath(path.Key("directory"), &document.PromptKitSources[i].Directory) || sourcePathsChanged
|
normalizePath(path.Key("directory"), &document.PromptKitSources[i].Directory)
|
||||||
}
|
|
||||||
if sourcePathsChanged {
|
|
||||||
resolution.Record(configkit.Keys("promptkit_sources"), configkit.ChangeNormalization, "normalized selected source paths")
|
|
||||||
}
|
}
|
||||||
normalizePath(configkit.Keys("schema_dir"), &document.SchemaDir)
|
normalizePath(configkit.Keys("schema_dir"), &document.SchemaDir)
|
||||||
normalizePath(configkit.Keys("server", "artifact_root"), &document.Server.ArtifactRoot)
|
normalizePath(configkit.Keys("server", "artifact_root"), &document.Server.ArtifactRoot)
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
|
|
||||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
|
||||||
renderformat "gitea.maximumdirect.net/eric/scriptorium/internal/format"
|
renderformat "gitea.maximumdirect.net/eric/scriptorium/internal/format"
|
||||||
|
"go.maximumdirect.net/configkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
// LoadOptions selects one application source and explicit configuration values.
|
// LoadOptions selects one application source and explicit configuration values.
|
||||||
@@ -20,35 +18,15 @@ type LoadOptions struct {
|
|||||||
// Load resolves one ConfigKit document and retains its inspection snapshot.
|
// Load resolves one ConfigKit document and retains its inspection snapshot.
|
||||||
func Load(options LoadOptions) (*configkit.Result[Document], error) {
|
func Load(options LoadOptions) (*configkit.Result[Document], error) {
|
||||||
var source configkit.Source
|
var source configkit.Source
|
||||||
fileBacked := false
|
|
||||||
if options.Explicit {
|
if options.Explicit {
|
||||||
source = configkit.File(options.Path)
|
source = configkit.File(options.Path)
|
||||||
fileBacked = true
|
|
||||||
} else {
|
} else {
|
||||||
selected := ""
|
source = configkit.SearchConfig("scriptorium", configkit.SearchPaths(defaultConfigSearchPaths...))
|
||||||
for _, candidate := range defaultConfigSearchPaths {
|
|
||||||
if _, err := os.Stat(candidate); err == nil {
|
|
||||||
selected = candidate
|
|
||||||
break
|
|
||||||
} else if !errors.Is(err, os.ErrNotExist) {
|
|
||||||
reason := "filesystem error"
|
|
||||||
if errors.Is(err, os.ErrPermission) {
|
|
||||||
reason = "permission denied"
|
|
||||||
}
|
|
||||||
return nil, fmt.Errorf("cannot inspect configuration path %q: %s", candidate, reason)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if selected == "" {
|
|
||||||
source = configkit.NoSource()
|
|
||||||
} else {
|
|
||||||
source = configkit.File(selected)
|
|
||||||
fileBacked = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := configkit.Load(source, configkit.Options[Document]{
|
result, err := configkit.Load(source, configkit.Options[Document]{
|
||||||
Definition: documentDefinition(),
|
Definition: documentDefinition(),
|
||||||
Imports: fileBacked,
|
Imports: true,
|
||||||
Overlay: options.Overlay,
|
Overlay: options.Overlay,
|
||||||
Overrides: options.Overrides,
|
Overrides: options.Overrides,
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user