mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-05-27 12:52:27 +02:00
refactor: replace direct newService calls with ServiceCommand pattern
- Replace all direct newService() calls with ServiceCommand initialization - Update command constructors to use ServiceCommand instead of ServiceManager - Simplify LogCommand and UpgradeCommand structs by removing serviceManager field - Remove unused global svcConfig variable from prog.go - Improve consistency and centralize service creation logic This change establishes a consistent pattern for service operations across the codebase, making it easier to maintain and extend service-related functionality.
This commit is contained in:
committed by
Cuong Manh Le
parent
33dd720d80
commit
a61cb1f5bf
+16
-11
@@ -14,17 +14,11 @@ import (
|
||||
|
||||
// LogCommand handles log-related operations
|
||||
type LogCommand struct {
|
||||
serviceManager *ServiceManager
|
||||
controlClient *controlClient
|
||||
controlClient *controlClient
|
||||
}
|
||||
|
||||
// NewLogCommand creates a new log command handler
|
||||
func NewLogCommand() (*LogCommand, error) {
|
||||
sm, err := NewServiceManager()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
dir, err := socketDir()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to find ctrld home dir: %w", err)
|
||||
@@ -32,8 +26,7 @@ func NewLogCommand() (*LogCommand, error) {
|
||||
|
||||
cc := newControlClient(filepath.Join(dir, ctrldControlUnixSock))
|
||||
return &LogCommand{
|
||||
serviceManager: sm,
|
||||
controlClient: cc,
|
||||
controlClient: cc,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -45,7 +38,13 @@ func (lc *LogCommand) warnRuntimeLoggingNotEnabled() {
|
||||
|
||||
// SendLogs sends runtime debug logs to ControlD
|
||||
func (lc *LogCommand) SendLogs(cmd *cobra.Command, args []string) error {
|
||||
status, err := lc.serviceManager.Status()
|
||||
sc := NewServiceCommand()
|
||||
s, _, err := sc.initializeServiceManager()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
status, err := s.Status()
|
||||
if errors.Is(err, service.ErrNotInstalled) {
|
||||
mainLog.Load().Warn().Msg("service not installed")
|
||||
return nil
|
||||
@@ -85,7 +84,13 @@ func (lc *LogCommand) SendLogs(cmd *cobra.Command, args []string) error {
|
||||
|
||||
// ViewLogs views current runtime debug logs
|
||||
func (lc *LogCommand) ViewLogs(cmd *cobra.Command, args []string) error {
|
||||
status, err := lc.serviceManager.Status()
|
||||
sc := NewServiceCommand()
|
||||
s, _, err := sc.initializeServiceManager()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
status, err := s.Status()
|
||||
if errors.Is(err, service.ErrNotInstalled) {
|
||||
mainLog.Load().Warn().Msg("service not installed")
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user