From 37a8ae8d313c963d856fde0536bab9257ceadf30 Mon Sep 17 00:00:00 2001 From: Snider Date: Fri, 6 Mar 2026 14:10:55 +0000 Subject: [PATCH] refactor: swap pkg/framework imports to pkg/core Co-Authored-By: Virgil --- pkg/cli/app.go | 14 +++++++------- pkg/cli/commands.go | 8 ++++---- pkg/cli/i18n.go | 14 +++++++------- pkg/cli/log.go | 8 ++++---- pkg/cli/runtime.go | 22 +++++++++++----------- 5 files changed, 33 insertions(+), 33 deletions(-) diff --git a/pkg/cli/app.go b/pkg/cli/app.go index 1a3d8d6..cdcdfeb 100644 --- a/pkg/cli/app.go +++ b/pkg/cli/app.go @@ -6,7 +6,7 @@ import ( "runtime/debug" "forge.lthn.ai/core/go-crypt/crypt/openpgp" - "forge.lthn.ai/core/go/pkg/framework" + "forge.lthn.ai/core/go/pkg/core" "forge.lthn.ai/core/go-log" "forge.lthn.ai/core/go-io/workspace" "github.com/spf13/cobra" @@ -66,7 +66,7 @@ func WithAppName(name string) { // ) // // Exits with code 1 on error or panic. -func Main(commands ...framework.Option) { +func Main(commands ...core.Option) { // Recovery from panics defer func() { if r := recover(); r != nil { @@ -77,13 +77,13 @@ func Main(commands ...framework.Option) { }() // Core services load first, then command services - services := []framework.Option{ - framework.WithName("i18n", NewI18nService(I18nOptions{})), - framework.WithName("log", NewLogService(log.Options{ + services := []core.Option{ + core.WithName("i18n", NewI18nService(I18nOptions{})), + core.WithName("log", NewLogService(log.Options{ Level: log.LevelInfo, })), - framework.WithName("crypt", openpgp.New), - framework.WithName("workspace", workspace.New), + core.WithName("crypt", openpgp.New), + core.WithName("workspace", workspace.New), } services = append(services, commands...) diff --git a/pkg/cli/commands.go b/pkg/cli/commands.go index 083fdde..5709fdd 100644 --- a/pkg/cli/commands.go +++ b/pkg/cli/commands.go @@ -6,7 +6,7 @@ import ( "iter" "sync" - "forge.lthn.ai/core/go/pkg/framework" + "forge.lthn.ai/core/go/pkg/core" "github.com/spf13/cobra" ) @@ -18,14 +18,14 @@ import ( // cli.WithCommands("config", config.AddConfigCommands), // cli.WithCommands("doctor", doctor.AddDoctorCommands), // ) -func WithCommands(name string, register func(root *Command)) framework.Option { - return framework.WithName("cmd."+name, func(c *framework.Core) (any, error) { +func WithCommands(name string, register func(root *Command)) core.Option { + return core.WithName("cmd."+name, func(c *core.Core) (any, error) { return &commandService{core: c, register: register}, nil }) } type commandService struct { - core *framework.Core + core *core.Core register func(root *Command) } diff --git a/pkg/cli/i18n.go b/pkg/cli/i18n.go index f6d9d24..0a54af6 100644 --- a/pkg/cli/i18n.go +++ b/pkg/cli/i18n.go @@ -4,13 +4,13 @@ import ( "context" "sync" - "forge.lthn.ai/core/go/pkg/framework" + "forge.lthn.ai/core/go/pkg/core" "forge.lthn.ai/core/go-i18n" ) // I18nService wraps i18n as a Core service. type I18nService struct { - *framework.ServiceRuntime[I18nOptions] + *core.ServiceRuntime[I18nOptions] svc *i18n.Service // Collect mode state @@ -27,8 +27,8 @@ type I18nOptions struct { } // NewI18nService creates an i18n service factory. -func NewI18nService(opts I18nOptions) func(*framework.Core) (any, error) { - return func(c *framework.Core) (any, error) { +func NewI18nService(opts I18nOptions) func(*core.Core) (any, error) { + return func(c *core.Core) (any, error) { svc, err := i18n.New() if err != nil { return nil, err @@ -45,7 +45,7 @@ func NewI18nService(opts I18nOptions) func(*framework.Core) (any, error) { i18n.SetDefault(svc) return &I18nService{ - ServiceRuntime: framework.NewServiceRuntime(c, opts), + ServiceRuntime: core.NewServiceRuntime(c, opts), svc: svc, missingKeys: make([]i18n.MissingKey, 0), }, nil @@ -113,7 +113,7 @@ type QueryTranslate struct { Args map[string]any } -func (s *I18nService) handleQuery(c *framework.Core, q framework.Query) (any, bool, error) { +func (s *I18nService) handleQuery(c *core.Core, q core.Query) (any, bool, error) { switch m := q.(type) { case QueryTranslate: return s.svc.T(m.Key, m.Args), true, nil @@ -157,7 +157,7 @@ func T(key string, args ...map[string]any) string { return i18n.T(key) } - svc, err := framework.ServiceFor[*I18nService](instance.core, "i18n") + svc, err := core.ServiceFor[*I18nService](instance.core, "i18n") if err != nil { // i18n service not registered, use global if len(args) > 0 { diff --git a/pkg/cli/log.go b/pkg/cli/log.go index 893df2e..c752f5a 100644 --- a/pkg/cli/log.go +++ b/pkg/cli/log.go @@ -1,7 +1,7 @@ package cli import ( - "forge.lthn.ai/core/go/pkg/framework" + "forge.lthn.ai/core/go/pkg/core" "forge.lthn.ai/core/go/pkg/log" ) @@ -31,8 +31,8 @@ type LogService struct { type LogOptions = log.Options // NewLogService creates a log service factory with CLI styling. -func NewLogService(opts LogOptions) func(*framework.Core) (any, error) { - return func(c *framework.Core) (any, error) { +func NewLogService(opts LogOptions) func(*core.Core) (any, error) { + return func(c *core.Core) (any, error) { // Create the underlying service factory := log.NewService(opts) svc, err := factory(c) @@ -61,7 +61,7 @@ func Log() *LogService { if instance == nil { return nil } - svc, err := framework.ServiceFor[*LogService](instance.core, "log") + svc, err := core.ServiceFor[*LogService](instance.core, "log") if err != nil { return nil } diff --git a/pkg/cli/runtime.go b/pkg/cli/runtime.go index 08636f1..e5a3a47 100644 --- a/pkg/cli/runtime.go +++ b/pkg/cli/runtime.go @@ -20,7 +20,7 @@ import ( "sync" "syscall" - "forge.lthn.ai/core/go/pkg/framework" + "forge.lthn.ai/core/go/pkg/core" "github.com/spf13/cobra" ) @@ -31,7 +31,7 @@ var ( // runtime is the CLI's internal Core runtime. type runtime struct { - core *framework.Core + core *core.Core root *cobra.Command ctx context.Context cancel context.CancelFunc @@ -41,7 +41,7 @@ type runtime struct { type Options struct { AppName string Version string - Services []framework.Option // Additional services to register + Services []core.Option // Additional services to register // OnReload is called when SIGHUP is received (daemon mode). // Use for configuration reloading. Leave nil to ignore SIGHUP. @@ -73,14 +73,14 @@ func Init(opts Options) error { } // Build options: app, signal service + any additional services - coreOpts := []framework.Option{ - framework.WithApp(rootCmd), - framework.WithName("signal", newSignalService(cancel, signalOpts...)), + coreOpts := []core.Option{ + core.WithApp(rootCmd), + core.WithName("signal", newSignalService(cancel, signalOpts...)), } coreOpts = append(coreOpts, opts.Services...) - coreOpts = append(coreOpts, framework.WithServiceLock()) + coreOpts = append(coreOpts, core.WithServiceLock()) - c, err := framework.New(coreOpts...) + c, err := core.New(coreOpts...) if err != nil { initErr = err cancel() @@ -111,7 +111,7 @@ func mustInit() { // --- Core Access --- // Core returns the CLI's framework Core instance. -func Core() *framework.Core { +func Core() *core.Core { mustInit() return instance.core } @@ -164,8 +164,8 @@ func WithReloadHandler(fn func() error) SignalOption { } } -func newSignalService(cancel context.CancelFunc, opts ...SignalOption) func(*framework.Core) (any, error) { - return func(c *framework.Core) (any, error) { +func newSignalService(cancel context.CancelFunc, opts ...SignalOption) func(*core.Core) (any, error) { + return func(c *core.Core) (any, error) { svc := &signalService{ cancel: cancel, sigChan: make(chan os.Signal, 1),