39 lines
1.5 KiB
Go
39 lines
1.5 KiB
Go
|
|
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},
|
||
|
|
}),
|
||
|
|
)
|
||
|
|
}
|