From 7608808bb014f82b52b2c95a06c0061bd463ad9e Mon Sep 17 00:00:00 2001 From: Snider Date: Tue, 24 Mar 2026 21:32:50 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20Core.Run()=20=E2=80=94=20ServiceStartup?= =?UTF-8?q?=20=E2=86=92=20Cli=20=E2=86=92=20ServiceShutdown=20lifecycle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Virgil --- core.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/core.go b/core.go index a80e092..efb58b0 100644 --- a/core.go +++ b/core.go @@ -59,6 +59,27 @@ func (c *Core) Env(key string) string { return Env(key) } func (c *Core) Context() context.Context { return c.context } func (c *Core) Core() *Core { return c } +// --- Lifecycle --- + +// Run starts all services, runs the CLI, then shuts down. +// This is the standard application lifecycle for CLI apps. +// +// c := core.New(core.WithService(myService.Register)).Value.(*Core) +// c.Run() +func (c *Core) Run() Result { + r := c.ServiceStartup(c.context, nil) + if !r.OK { + return r + } + + if cli := c.Cli(); cli != nil { + r = cli.Run() + } + + c.ServiceShutdown(c.context) + return r +} + // --- IPC (uppercase aliases) --- func (c *Core) ACTION(msg Message) Result { return c.Action(msg) }