refactor: swap pkg/framework imports to pkg/core
Some checks failed
Deploy / build (push) Failing after 4s
Security Scan / security (push) Successful in 19s

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Snider 2026-03-06 14:10:55 +00:00
parent 7f555c6f8a
commit 37a8ae8d31
5 changed files with 33 additions and 33 deletions

View file

@ -6,7 +6,7 @@ import (
"runtime/debug" "runtime/debug"
"forge.lthn.ai/core/go-crypt/crypt/openpgp" "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-log"
"forge.lthn.ai/core/go-io/workspace" "forge.lthn.ai/core/go-io/workspace"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -66,7 +66,7 @@ func WithAppName(name string) {
// ) // )
// //
// Exits with code 1 on error or panic. // Exits with code 1 on error or panic.
func Main(commands ...framework.Option) { func Main(commands ...core.Option) {
// Recovery from panics // Recovery from panics
defer func() { defer func() {
if r := recover(); r != nil { if r := recover(); r != nil {
@ -77,13 +77,13 @@ func Main(commands ...framework.Option) {
}() }()
// Core services load first, then command services // Core services load first, then command services
services := []framework.Option{ services := []core.Option{
framework.WithName("i18n", NewI18nService(I18nOptions{})), core.WithName("i18n", NewI18nService(I18nOptions{})),
framework.WithName("log", NewLogService(log.Options{ core.WithName("log", NewLogService(log.Options{
Level: log.LevelInfo, Level: log.LevelInfo,
})), })),
framework.WithName("crypt", openpgp.New), core.WithName("crypt", openpgp.New),
framework.WithName("workspace", workspace.New), core.WithName("workspace", workspace.New),
} }
services = append(services, commands...) services = append(services, commands...)

View file

@ -6,7 +6,7 @@ import (
"iter" "iter"
"sync" "sync"
"forge.lthn.ai/core/go/pkg/framework" "forge.lthn.ai/core/go/pkg/core"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -18,14 +18,14 @@ import (
// cli.WithCommands("config", config.AddConfigCommands), // cli.WithCommands("config", config.AddConfigCommands),
// cli.WithCommands("doctor", doctor.AddDoctorCommands), // cli.WithCommands("doctor", doctor.AddDoctorCommands),
// ) // )
func WithCommands(name string, register func(root *Command)) framework.Option { func WithCommands(name string, register func(root *Command)) core.Option {
return framework.WithName("cmd."+name, func(c *framework.Core) (any, error) { return core.WithName("cmd."+name, func(c *core.Core) (any, error) {
return &commandService{core: c, register: register}, nil return &commandService{core: c, register: register}, nil
}) })
} }
type commandService struct { type commandService struct {
core *framework.Core core *core.Core
register func(root *Command) register func(root *Command)
} }

View file

@ -4,13 +4,13 @@ import (
"context" "context"
"sync" "sync"
"forge.lthn.ai/core/go/pkg/framework" "forge.lthn.ai/core/go/pkg/core"
"forge.lthn.ai/core/go-i18n" "forge.lthn.ai/core/go-i18n"
) )
// I18nService wraps i18n as a Core service. // I18nService wraps i18n as a Core service.
type I18nService struct { type I18nService struct {
*framework.ServiceRuntime[I18nOptions] *core.ServiceRuntime[I18nOptions]
svc *i18n.Service svc *i18n.Service
// Collect mode state // Collect mode state
@ -27,8 +27,8 @@ type I18nOptions struct {
} }
// NewI18nService creates an i18n service factory. // NewI18nService creates an i18n service factory.
func NewI18nService(opts I18nOptions) func(*framework.Core) (any, error) { func NewI18nService(opts I18nOptions) func(*core.Core) (any, error) {
return func(c *framework.Core) (any, error) { return func(c *core.Core) (any, error) {
svc, err := i18n.New() svc, err := i18n.New()
if err != nil { if err != nil {
return nil, err return nil, err
@ -45,7 +45,7 @@ func NewI18nService(opts I18nOptions) func(*framework.Core) (any, error) {
i18n.SetDefault(svc) i18n.SetDefault(svc)
return &I18nService{ return &I18nService{
ServiceRuntime: framework.NewServiceRuntime(c, opts), ServiceRuntime: core.NewServiceRuntime(c, opts),
svc: svc, svc: svc,
missingKeys: make([]i18n.MissingKey, 0), missingKeys: make([]i18n.MissingKey, 0),
}, nil }, nil
@ -113,7 +113,7 @@ type QueryTranslate struct {
Args map[string]any 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) { switch m := q.(type) {
case QueryTranslate: case QueryTranslate:
return s.svc.T(m.Key, m.Args), true, nil 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) return i18n.T(key)
} }
svc, err := framework.ServiceFor[*I18nService](instance.core, "i18n") svc, err := core.ServiceFor[*I18nService](instance.core, "i18n")
if err != nil { if err != nil {
// i18n service not registered, use global // i18n service not registered, use global
if len(args) > 0 { if len(args) > 0 {

View file

@ -1,7 +1,7 @@
package cli package cli
import ( import (
"forge.lthn.ai/core/go/pkg/framework" "forge.lthn.ai/core/go/pkg/core"
"forge.lthn.ai/core/go/pkg/log" "forge.lthn.ai/core/go/pkg/log"
) )
@ -31,8 +31,8 @@ type LogService struct {
type LogOptions = log.Options type LogOptions = log.Options
// NewLogService creates a log service factory with CLI styling. // NewLogService creates a log service factory with CLI styling.
func NewLogService(opts LogOptions) func(*framework.Core) (any, error) { func NewLogService(opts LogOptions) func(*core.Core) (any, error) {
return func(c *framework.Core) (any, error) { return func(c *core.Core) (any, error) {
// Create the underlying service // Create the underlying service
factory := log.NewService(opts) factory := log.NewService(opts)
svc, err := factory(c) svc, err := factory(c)
@ -61,7 +61,7 @@ func Log() *LogService {
if instance == nil { if instance == nil {
return nil return nil
} }
svc, err := framework.ServiceFor[*LogService](instance.core, "log") svc, err := core.ServiceFor[*LogService](instance.core, "log")
if err != nil { if err != nil {
return nil return nil
} }

View file

@ -20,7 +20,7 @@ import (
"sync" "sync"
"syscall" "syscall"
"forge.lthn.ai/core/go/pkg/framework" "forge.lthn.ai/core/go/pkg/core"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -31,7 +31,7 @@ var (
// runtime is the CLI's internal Core runtime. // runtime is the CLI's internal Core runtime.
type runtime struct { type runtime struct {
core *framework.Core core *core.Core
root *cobra.Command root *cobra.Command
ctx context.Context ctx context.Context
cancel context.CancelFunc cancel context.CancelFunc
@ -41,7 +41,7 @@ type runtime struct {
type Options struct { type Options struct {
AppName string AppName string
Version 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). // OnReload is called when SIGHUP is received (daemon mode).
// Use for configuration reloading. Leave nil to ignore SIGHUP. // 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 // Build options: app, signal service + any additional services
coreOpts := []framework.Option{ coreOpts := []core.Option{
framework.WithApp(rootCmd), core.WithApp(rootCmd),
framework.WithName("signal", newSignalService(cancel, signalOpts...)), core.WithName("signal", newSignalService(cancel, signalOpts...)),
} }
coreOpts = append(coreOpts, opts.Services...) 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 { if err != nil {
initErr = err initErr = err
cancel() cancel()
@ -111,7 +111,7 @@ func mustInit() {
// --- Core Access --- // --- Core Access ---
// Core returns the CLI's framework Core instance. // Core returns the CLI's framework Core instance.
func Core() *framework.Core { func Core() *core.Core {
mustInit() mustInit()
return instance.core 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) { func newSignalService(cancel context.CancelFunc, opts ...SignalOption) func(*core.Core) (any, error) {
return func(c *framework.Core) (any, error) { return func(c *core.Core) (any, error) {
svc := &signalService{ svc := &signalService{
cancel: cancel, cancel: cancel,
sigChan: make(chan os.Signal, 1), sigChan: make(chan os.Signal, 1),