Adopt native configuration discovery and a single PromptKit entry file
This commit is contained in:
@@ -2,15 +2,11 @@ package cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
|
||||
appconfig "gitea.maximumdirect.net/eric/scriptorium/internal/config"
|
||||
"go.maximumdirect.net/ckconfig"
|
||||
"go.maximumdirect.net/ckprompt"
|
||||
"go.maximumdirect.net/commandkit"
|
||||
"go.maximumdirect.net/configkit"
|
||||
"go.maximumdirect.net/promptkit"
|
||||
)
|
||||
|
||||
// Execute composes the native CLI and returns its finalized outcome. The caller
|
||||
@@ -26,13 +22,16 @@ func Execute(ctx context.Context, identity commandkit.Identity, args []string, s
|
||||
func newApp(identity commandkit.Identity) (*commandkit.App, error) {
|
||||
application := ckconfig.FromConfigKit("app", "Scriptorium application configuration.", loadApplication)
|
||||
framework := ckprompt.ConfigScope(loadEngine)
|
||||
configuration := ckconfig.Command(ckconfig.Suite[struct{}, struct{}]{
|
||||
Scopes: []ckconfig.Scope[struct{}, struct{}]{application, framework},
|
||||
configuration := ckconfig.Command(ckconfig.Suite[applicationInput, struct{}]{
|
||||
NewInput: func() applicationInput { return applicationInput{} },
|
||||
Scopes: []ckconfig.Scope[applicationInput, struct{}]{application, framework},
|
||||
})
|
||||
definitions := ckprompt.FromEngine(loadEngine)
|
||||
declarations := []commandkit.Declaration{
|
||||
commandkit.NewCommand(commandkit.CommandSpec[struct{}]{Name: "run", Summary: "Run a stored prompt.", Run: commandNotImplemented}),
|
||||
commandkit.NewCommand(commandkit.CommandSpec[struct{}]{Name: "serve", Summary: "Serve the HTTP API.", Run: commandNotImplemented}),
|
||||
commandkit.NewCommand(commandkit.CommandSpec[serveInput]{Name: "serve", Summary: "Serve the HTTP API.", Flags: serveFlags(), Run: func(commandkit.Invocation, serveInput) commandkit.Outcome {
|
||||
return commandkit.Failure("Server startup is not implemented.")
|
||||
}}),
|
||||
configuration,
|
||||
commandkit.Completion("scriptorium"),
|
||||
}
|
||||
@@ -40,14 +39,14 @@ func newApp(identity commandkit.Identity) (*commandkit.App, error) {
|
||||
return commandkit.New(identity, declarations...)
|
||||
}
|
||||
|
||||
// Application acquisition and effects are filled in independently of command
|
||||
// declaration construction; metadata operations must never reach these callbacks.
|
||||
func loadApplication(context.Context, ckconfig.Selection, struct{}, struct{}) (*configkit.Result[appconfig.Document], error) {
|
||||
return nil, errors.New("application configuration acquisition is not implemented")
|
||||
type serveInput struct {
|
||||
Selection ckconfig.Selection
|
||||
Application applicationInput
|
||||
}
|
||||
|
||||
func loadEngine(context.Context, ckconfig.Selection, struct{}, struct{}) (*promptkit.Engine, error) {
|
||||
return nil, errors.New("engine acquisition is not implemented")
|
||||
func serveFlags() []commandkit.Flag[serveInput] {
|
||||
flags := configurationSelectors(func(input *serveInput) *ckconfig.Selection { return &input.Selection })
|
||||
return append(flags, serverSelectors(func(input *serveInput) *applicationInput { return &input.Application })...)
|
||||
}
|
||||
|
||||
func commandNotImplemented(commandkit.Invocation, struct{}) commandkit.Outcome {
|
||||
|
||||
Reference in New Issue
Block a user