Use native ConfigKit application loading
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
||||
renderformat "gitea.maximumdirect.net/eric/scriptorium/internal/format"
|
||||
"go.maximumdirect.net/configkit"
|
||||
)
|
||||
|
||||
// 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.
|
||||
func Load(options LoadOptions) (*configkit.Result[Document], error) {
|
||||
var source configkit.Source
|
||||
fileBacked := false
|
||||
if options.Explicit {
|
||||
source = configkit.File(options.Path)
|
||||
fileBacked = true
|
||||
} else {
|
||||
selected := ""
|
||||
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
|
||||
}
|
||||
source = configkit.SearchConfig("scriptorium", configkit.SearchPaths(defaultConfigSearchPaths...))
|
||||
}
|
||||
|
||||
result, err := configkit.Load(source, configkit.Options[Document]{
|
||||
Definition: documentDefinition(),
|
||||
Imports: fileBacked,
|
||||
Imports: true,
|
||||
Overlay: options.Overlay,
|
||||
Overrides: options.Overrides,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user