Use native ConfigKit application loading
This commit is contained in:
@@ -4,9 +4,9 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
||||
"gitea.maximumdirect.net/eric/scriptorium/internal/defaults"
|
||||
renderformat "gitea.maximumdirect.net/eric/scriptorium/internal/format"
|
||||
"go.maximumdirect.net/configkit"
|
||||
)
|
||||
|
||||
// Document is Scriptorium's ConfigKit-native application configuration shape.
|
||||
@@ -58,16 +58,14 @@ func documentDefaults() Document {
|
||||
}
|
||||
|
||||
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)
|
||||
if cleaned != "" {
|
||||
cleaned = filepath.Clean(cleaned)
|
||||
}
|
||||
if cleaned != *value {
|
||||
configkit.Normalize(resolution, path, value, cleaned, "normalized application path")
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
normalizeString := func(path configkit.Path, value *string, normalized, reason string) {
|
||||
if normalized != *value {
|
||||
@@ -75,14 +73,10 @@ func resolveDocument(document *Document, resolution *configkit.Resolution) error
|
||||
}
|
||||
}
|
||||
|
||||
sourcePathsChanged := false
|
||||
for i := range document.PromptKitSources {
|
||||
path := configkit.Keys("promptkit_sources").Index(i)
|
||||
sourcePathsChanged = normalizePath(path.Key("file"), &document.PromptKitSources[i].File) || sourcePathsChanged
|
||||
sourcePathsChanged = normalizePath(path.Key("directory"), &document.PromptKitSources[i].Directory) || sourcePathsChanged
|
||||
}
|
||||
if sourcePathsChanged {
|
||||
resolution.Record(configkit.Keys("promptkit_sources"), configkit.ChangeNormalization, "normalized selected source paths")
|
||||
normalizePath(path.Key("file"), &document.PromptKitSources[i].File)
|
||||
normalizePath(path.Key("directory"), &document.PromptKitSources[i].Directory)
|
||||
}
|
||||
normalizePath(configkit.Keys("schema_dir"), &document.SchemaDir)
|
||||
normalizePath(configkit.Keys("server", "artifact_root"), &document.Server.ArtifactRoot)
|
||||
|
||||
Reference in New Issue
Block a user