SetRegistryEnabled enables or disables a registry by name, persists the change, and hot-reloads the registry manager so the change takes effect immediately.
(name string, enabled bool)
| 1098 | // SetRegistryEnabled enables or disables a registry by name, persists the change, |
| 1099 | // and hot-reloads the registry manager so the change takes effect immediately. |
| 1100 | func (sh *SkillHandler) SetRegistryEnabled(name string, enabled bool) { |
| 1101 | cfg, err := registry.LoadConfig() |
| 1102 | if err != nil { |
| 1103 | fmt.Printf("\n %s %s\n\n", colorize(i18n.T("skill.error")+":", ColorRed), err.Error()) |
| 1104 | return |
| 1105 | } |
| 1106 | |
| 1107 | found := false |
| 1108 | for i := range cfg.Registries { |
| 1109 | if strings.EqualFold(cfg.Registries[i].Name, name) { |
| 1110 | cfg.Registries[i].IsActive = enabled |
| 1111 | found = true |
| 1112 | break |
| 1113 | } |
| 1114 | } |
| 1115 | |
| 1116 | if !found { |
| 1117 | fmt.Printf("\n %s %q\n", colorize(i18n.T("skill.registry.not_found")+":", ColorYellow), name) |
| 1118 | fmt.Printf(" %s:", i18n.T("skill.registry.available")) |
| 1119 | for _, r := range cfg.Registries { |
| 1120 | fmt.Printf(" %s", colorize(r.Name, ColorCyan)) |
| 1121 | } |
| 1122 | fmt.Print("\n\n") |
| 1123 | return |
| 1124 | } |
| 1125 | |
| 1126 | if err := registry.SaveConfig(cfg); err != nil { |
| 1127 | fmt.Printf("\n %s %s\n\n", colorize(i18n.T("skill.error")+":", ColorRed), err.Error()) |
| 1128 | return |
| 1129 | } |
| 1130 | |
| 1131 | // Hot-reload: recreate the manager with the updated config |
| 1132 | newMgr, err := registry.NewRegistryManager(cfg, sh.logger) |
| 1133 | if err != nil { |
| 1134 | sh.logger.Warn("Failed to reload registry manager", zap.Error(err)) |
| 1135 | fmt.Printf("\n %s %s\n\n", colorize(i18n.T("skill.error")+":", ColorRed), err.Error()) |
| 1136 | return |
| 1137 | } |
| 1138 | sh.registryMgr = newMgr |
| 1139 | |
| 1140 | action := i18n.T("skill.registry.enabled") |
| 1141 | actionColor := ColorGreen |
| 1142 | if !enabled { |
| 1143 | action = i18n.T("skill.registry.disabled") |
| 1144 | actionColor = ColorYellow |
| 1145 | } |
| 1146 | |
| 1147 | fmt.Printf("\n %s %s\n", colorize(action, actionColor), colorize(name, ColorCyan)) |
| 1148 | fmt.Println() |
| 1149 | } |
| 1150 | |
| 1151 | // ShowHelp displays usage information. |
| 1152 | func (sh *SkillHandler) ShowHelp() { |
no test coverage detected