56 lines
2.3 KiB
Go
56 lines
2.3 KiB
Go
|
|
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
|
||
|
|
// owns the context, streams, and process exit.
|
||
|
|
func Execute(ctx context.Context, identity commandkit.Identity, args []string, stdout, stderr io.Writer) commandkit.Outcome {
|
||
|
|
app, err := newApp(identity)
|
||
|
|
if err != nil {
|
||
|
|
return commandkit.Failure("Could not compose application commands.").WithCause(err)
|
||
|
|
}
|
||
|
|
return app.Execute(ctx, args, commandkit.Streams{Out: stdout, Err: stderr})
|
||
|
|
}
|
||
|
|
|
||
|
|
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},
|
||
|
|
})
|
||
|
|
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}),
|
||
|
|
configuration,
|
||
|
|
commandkit.Completion("scriptorium"),
|
||
|
|
}
|
||
|
|
declarations = append(declarations, ckprompt.Declarations(definitions)...)
|
||
|
|
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")
|
||
|
|
}
|
||
|
|
|
||
|
|
func loadEngine(context.Context, ckconfig.Selection, struct{}, struct{}) (*promptkit.Engine, error) {
|
||
|
|
return nil, errors.New("engine acquisition is not implemented")
|
||
|
|
}
|
||
|
|
|
||
|
|
func commandNotImplemented(commandkit.Invocation, struct{}) commandkit.Outcome {
|
||
|
|
return commandkit.Failure("Application command is not implemented.")
|
||
|
|
}
|