43 lines
1.5 KiB
Go
43 lines
1.5 KiB
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
|
|
"go.maximumdirect.net/ckconfig"
|
|
"go.maximumdirect.net/ckprompt"
|
|
"go.maximumdirect.net/commandkit"
|
|
)
|
|
|
|
// 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) {
|
|
definitions := promptSuite()
|
|
declarations := []commandkit.Declaration{
|
|
commandkit.NewCommand(commandkit.CommandSpec[serveInput]{Name: "serve", Summary: "Serve the HTTP API.", Flags: serveFlags(), Run: serveHTTP}),
|
|
configurationCommand(),
|
|
commandkit.Completion("scriptorium"),
|
|
}
|
|
declarations = append(declarations, runDeclarations()...)
|
|
declarations = append(declarations, ckprompt.Declarations(definitions)...)
|
|
return commandkit.New(identity, declarations...)
|
|
}
|
|
|
|
type serveInput struct {
|
|
Selection ckconfig.Selection
|
|
Application applicationInput
|
|
}
|
|
|
|
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 })...)
|
|
}
|