mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-07-29 01:18:48 +02:00
refactor: split ServiceCommand methods into dedicated files
- Move ServiceCommand.Start to commands_service_start.go - Move ServiceCommand.Stop to commands_service_stop.go - Move ServiceCommand.Restart to commands_service_restart.go - Move ServiceCommand.Reload to commands_service_reload.go - Move ServiceCommand.Status to commands_service_status.go - Move ServiceCommand.Uninstall to commands_service_uninstall.go - Move createStartCommands to commands_service_start.go - Clean up imports in commands_service.go - Remove all method implementations from main service file This refactoring improves code organization by: - Separating concerns into focused files - Making navigation easier for developers - Reducing merge conflicts between different commands - Following consistent modular patterns - Reducing commands_service.go from ~650 lines to ~50 lines Each method is now co-located with its related functionality, making the codebase more maintainable and easier to understand.
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/kardianos/service"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// Status implements the logic from cmdStatus.Run
|
||||
func (sc *ServiceCommand) Status(cmd *cobra.Command, args []string) error {
|
||||
status, err := sc.serviceManager.svc.Status()
|
||||
if err != nil {
|
||||
mainLog.Load().Error().Msg(err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
switch status {
|
||||
case service.StatusUnknown:
|
||||
mainLog.Load().Notice().Msg("Unknown status")
|
||||
os.Exit(2)
|
||||
case service.StatusRunning:
|
||||
mainLog.Load().Notice().Msg("Service is running")
|
||||
os.Exit(0)
|
||||
case service.StatusStopped:
|
||||
mainLog.Load().Notice().Msg("Service is stopped")
|
||||
os.Exit(1)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user