Update the simple configuration consumer

This commit is contained in:
2026-11-07 04:54:44 +00:00
parent 0b70f37267
commit 42af1da142
5 changed files with 84 additions and 3 deletions

View File

@@ -49,10 +49,15 @@ func loadAppConfiguration(_ context.Context, selection ckconfig.Selection) (*con
options.Overlay = selection.Overlay.Value
options.Filesystem = &configkit.FilesystemContext{Root: ".", BaseDir: "."}
}
options.Overrides = append(options.Overrides, selection.Overrides...)
return configkit.Load(source, options)
}
func newApp() (*commandkit.App, error) {
return newAppWithLoader(loadAppConfiguration)
}
func newAppWithLoader(load func(context.Context, ckconfig.Selection) (*configkit.Result[appConfiguration], error)) (*commandkit.App, error) {
countDefault := 1
tagDefaults := []string{"example"}
greet := commandkit.NewCommand(commandkit.CommandSpec[greetInput]{
@@ -68,7 +73,7 @@ func newApp() (*commandkit.App, error) {
},
Run: func(invocation commandkit.Invocation, input greetInput) commandkit.Outcome {
reporter := invocation.Reporter()
configuration, err := loadAppConfiguration(invocation.Context, ckconfig.Selection{})
configuration, err := load(invocation.Context, ckconfig.Selection{})
if err != nil {
return commandkit.Failure("Could not load application configuration.").WithCause(err)
}
@@ -87,9 +92,13 @@ func newApp() (*commandkit.App, error) {
return commandkit.Success()
},
})
scope := ckconfig.FromConfigKit("app", "Application configuration.", func(ctx context.Context, selection ckconfig.Selection, _, _ struct{}) (*configkit.Result[appConfiguration], error) {
return load(ctx, selection)
})
scope.Features.Overrides = true
return commandkit.New(
commandkit.Identity{Name: "simple-example", Version: "1.0"},
ckconfig.AppCommand(loadAppConfiguration),
ckconfig.Command(ckconfig.Suite[struct{}, struct{}]{Scopes: []ckconfig.Scope[struct{}, struct{}]{scope}}),
greet,
)
}