mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-02-03 22:18:39 +00:00
feat: add interfaces and types for command refactoring
Add CommandRunner interface and ServiceManager types to support dependency injection and better separation of concerns in command handling.
This commit is contained in:
committed by
Cuong Manh Le
parent
69b192c6fa
commit
b5f101f667
@@ -32,6 +32,46 @@ import (
|
||||
// dialSocketControlServerTimeout is the default timeout to wait when ping control server.
|
||||
const dialSocketControlServerTimeout = 30 * time.Second
|
||||
|
||||
// CommandRunner interface for dependency injection and testing
|
||||
type CommandRunner interface {
|
||||
RunServiceCommand(cmd *cobra.Command, args []string) error
|
||||
RunLogCommand(cmd *cobra.Command, args []string) error
|
||||
RunStatusCommand(cmd *cobra.Command, args []string) error
|
||||
RunUpgradeCommand(cmd *cobra.Command, args []string) error
|
||||
RunClientsCommand(cmd *cobra.Command, args []string) error
|
||||
RunInterfacesCommand(cmd *cobra.Command, args []string) error
|
||||
}
|
||||
|
||||
// ServiceManager handles service operations
|
||||
type ServiceManager struct {
|
||||
prog *prog
|
||||
svc service.Service
|
||||
}
|
||||
|
||||
// NewServiceManager creates a new service manager
|
||||
func NewServiceManager() (*ServiceManager, error) {
|
||||
p := &prog{}
|
||||
|
||||
// Create a proper service configuration
|
||||
svcConfig := &service.Config{
|
||||
Name: ctrldServiceName,
|
||||
DisplayName: "Control-D Helper Service",
|
||||
Description: "A highly configurable, multi-protocol DNS forwarding proxy",
|
||||
Option: service.KeyValue{},
|
||||
}
|
||||
|
||||
s, err := newService(p, svcConfig)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create service: %w", err)
|
||||
}
|
||||
return &ServiceManager{prog: p, svc: s}, nil
|
||||
}
|
||||
|
||||
// Status returns the current service status
|
||||
func (sm *ServiceManager) Status() (service.Status, error) {
|
||||
return sm.svc.Status()
|
||||
}
|
||||
|
||||
func initLogCmd() *cobra.Command {
|
||||
warnRuntimeLoggingNotEnabled := func() {
|
||||
mainLog.Load().Warn().Msg("runtime debug logging is not enabled")
|
||||
|
||||
Reference in New Issue
Block a user