refactor: pass rootCmd as parameter to Init*Cmd functions

- Update all Init*Cmd function signatures to accept rootCmd parameter:
  * InitServiceCmd(rootCmd *cobra.Command)
  * InitClientsCmd(rootCmd *cobra.Command)
  * InitLogCmd(rootCmd *cobra.Command)
  * InitUpgradeCmd(rootCmd *cobra.Command)
  * InitRunCmd(rootCmd *cobra.Command)
  * InitInterfacesCmd(rootCmd *cobra.Command)

- Update function calls in cli.go to pass rootCmd parameter
- Update InitInterfacesCmd call in commands_service.go

Benefits:
- Eliminates global state dependency on rootCmd variable
- Makes dependencies explicit in function signatures
- Improves testability by allowing different root commands
- Better encapsulation and modularity
This commit is contained in:
Cuong Manh Le
2025-07-30 17:01:03 +07:00
committed by Cuong Manh Le
parent a61cb1f5bf
commit bfe6060df1
7 changed files with 12 additions and 12 deletions
+2 -2
View File
@@ -69,7 +69,7 @@ func (sc *ServiceCommand) createServiceConfig() *service.Config {
}
// InitServiceCmd creates the service command with proper logic and aliases
func InitServiceCmd() *cobra.Command {
func InitServiceCmd(rootCmd *cobra.Command) *cobra.Command {
// Create service command handlers
sc := NewServiceCommand()
@@ -141,7 +141,7 @@ NOTE: Uninstalling will set DNS to values provided by DHCP.`,
}
// Interfaces command - use the existing InitInterfacesCmd function
interfacesCmd := InitInterfacesCmd()
interfacesCmd := InitInterfacesCmd(rootCmd)
stopCmdAlias := &cobra.Command{
PreRun: func(cmd *cobra.Command, args []string) {