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:
Cuong Manh Le
2025-07-30 16:49:35 +07:00
committed by Cuong Manh Le
parent 33dd720d80
commit a61cb1f5bf
6 changed files with 39 additions and 44 deletions
+3 -2
View File
@@ -38,12 +38,13 @@ func NewClientsCommand() (*ClientsCommand, error) {
// ListClients lists all connected clients
func (cc *ClientsCommand) ListClients(cmd *cobra.Command, args []string) error {
// Check service status first
sm, err := NewServiceManager()
sc := NewServiceCommand()
s, _, err := sc.initializeServiceManager()
if err != nil {
return err
}
status, err := sm.Status()
status, err := s.Status()
if errors.Is(err, service.ErrNotInstalled) {
mainLog.Load().Warn().Msg("service not installed")
return nil