Compose native application commands and shared configuration scopes

This commit is contained in:
2026-11-21 22:59:46 +00:00
parent a1c888d2cd
commit 91869ba191
7 changed files with 150 additions and 350 deletions

View File

@@ -0,0 +1,38 @@
package cli
import (
"context"
"fmt"
"strings"
"gitea.maximumdirect.net/eric/notarius/internal/core/config"
"go.maximumdirect.net/ckconfig"
"go.maximumdirect.net/commandkit"
"go.maximumdirect.net/configkit"
)
// NewApplication declares the native command surface. Acquisition is deferred to
// the selected handler; construction performs no configuration or engine work.
func NewApplication(version string, options Options) (*commandkit.App, error) {
newState := func() *nativeLoaders { return &nativeLoaders{lookupEnv: options.LookupEnv} }
load := func(ctx context.Context, selection ckconfig.Selection, _ struct{}, state *nativeLoaders) (*configkit.Result[config.Document], error) {
return state.application(ctx, selection)
}
appScope := ckconfig.FromConfigKit("app", "Notarius application configuration.", load)
appScope.Features.Overrides = true
promptScope := ckconfig.FromConfigKitSubtree("promptkit", "Native PromptKit configuration.", configkit.Keys("promptkit"), load)
promptScope.Features.Overrides = true
return commandkit.New(commandkit.Identity{Name: "notarius", Version: version},
commandkit.Completion("notarius"),
ckconfig.Command(ckconfig.Suite[struct{}, *nativeLoaders]{
NewState: newState,
CheckInput: func(_ string, selection ckconfig.Selection, _ struct{}) error {
if selection.Config.Set && strings.TrimSpace(selection.Config.Value) == "" {
return fmt.Errorf("--config must not be empty")
}
return nil
},
Scopes: []ckconfig.Scope[struct{}, *nativeLoaders]{appScope, promptScope},
}),
)
}