buildRoutes wires every command to its handler. Keeping this as data (not control flow) is what holds HandleCommand's complexity down.
()
| 164 | // buildRoutes wires every command to its handler. Keeping this as data (not |
| 165 | // control flow) is what holds HandleCommand's complexity down. |
| 166 | func (ch *CommandHandler) buildRoutes() { |
| 167 | c := ch.cli |
| 168 | exit := func(_ context.Context, _ string) bool { fmt.Println(i18n.T("status.exiting")); return true } |
| 169 | |
| 170 | ch.routes = &commandRoutes{} |
| 171 | ch.routes.exact = map[string]cmdFunc{ |
| 172 | "/exit": exit, "exit": exit, "/quit": exit, "quit": exit, |
| 173 | "/help": func(_ context.Context, _ string) bool { c.showHelp(); return false }, |
| 174 | "/nextchunk": func(ctx context.Context, _ string) bool { return c.handleNextChunk(ctx) }, |
| 175 | "/retry": func(ctx context.Context, _ string) bool { return c.handleRetryLastChunk(ctx) }, |
| 176 | "/retryall": func(_ context.Context, _ string) bool { return c.handleRetryAllChunks() }, |
| 177 | "/skipchunk": func(_ context.Context, _ string) bool { return c.handleSkipChunk() }, |
| 178 | "/disconnect": func(ctx context.Context, _ string) bool { ch.handleDisconnectCommand(ctx); return false }, |
| 179 | "/rewind": func(_ context.Context, _ string) bool { c.showRewindMenu(); return false }, |
| 180 | "/metrics": func(_ context.Context, _ string) bool { ch.handleMetricsCommand(); return false }, |
| 181 | "/cost": func(_ context.Context, _ string) bool { c.handleCostCommand(); return false }, |
| 182 | "/newsession": func(ctx context.Context, _ string) bool { |
| 183 | c.clearAllHistories() |
| 184 | c.currentSessionName = "" |
| 185 | // Rotate the shared cross-channel conversation too, so the new |
| 186 | // session propagates to Telegram/Slack and any other connected CLI. |
| 187 | if c.hubSync != nil { |
| 188 | if err := c.hubSync.newSession(ctx); err != nil { |
| 189 | c.logger.Warn("hub sync: new session failed: " + err.Error()) |
| 190 | } |
| 191 | } |
| 192 | fmt.Println(i18n.T("session.new_session_started")) |
| 193 | return false |
| 194 | }, |
| 195 | "/reset": ch.resetTerminal, |
| 196 | "/redraw": ch.resetTerminal, |
| 197 | "/clear": ch.resetTerminal, |
| 198 | } |
| 199 | |
| 200 | // Order preserved from the historical switch. word=true entries match |
| 201 | // "exact or +space"; word=false entries are raw-prefix sub-command groups. |
| 202 | ch.routes.prefixes = []prefixRoute{ |
| 203 | {"/switch", false, func(ctx context.Context, in string) bool { c.handleSwitchCommand(ctx, in); return false }}, |
| 204 | {"/provider", false, func(ctx context.Context, in string) bool { c.handleProviderCommand(ctx, in); return false }}, |
| 205 | // Must precede "/model" (raw-prefix) so it isn't shadowed by it. |
| 206 | {"/model-image", true, func(ctx context.Context, in string) bool { c.handleImageModelCommand(ctx, in); return false }}, |
| 207 | {"/model", false, func(ctx context.Context, in string) bool { c.handleModelCommand(ctx, in); return false }}, |
| 208 | {"/max-tokens", false, func(ctx context.Context, in string) bool { c.handleMaxTokensCommand(ctx, in); return false }}, |
| 209 | {"/config", true, ch.cmdConfig}, |
| 210 | {"/status", true, ch.cmdConfig}, |
| 211 | {"/settings", true, ch.cmdConfig}, |
| 212 | {"/session", false, func(ctx context.Context, in string) bool { ch.handleSessionCommand(ctx, in); return false }}, |
| 213 | {"/context", false, func(ctx context.Context, in string) bool { ch.handleContextCommand(ctx, in); return false }}, |
| 214 | {"/auth", false, func(ctx context.Context, in string) bool { ch.handleAuthCommand(ctx, in); return false }}, |
| 215 | {"/plugin", false, func(_ context.Context, in string) bool { ch.handlePluginCommand(in); return false }}, |
| 216 | {"/skill", false, func(ctx context.Context, in string) bool { ch.handleSkillCommand(ctx, in); return false }}, |
| 217 | {"/connect", false, func(ctx context.Context, in string) bool { ch.handleConnectCommand(ctx, in); return false }}, |
| 218 | {"/hub", false, func(ctx context.Context, in string) bool { c.handleHubCommand(ctx, in); return false }}, |
| 219 | {"/watch", false, func(ctx context.Context, in string) bool { ch.handleWatchCommand(ctx, in); return false }}, |
| 220 | {"/compact", false, func(ctx context.Context, in string) bool { c.handleCompactCommand(ctx, in); return false }}, |
| 221 | {"/memory", false, func(ctx context.Context, in string) bool { c.handleMemoryCommand(ctx, in); return false }}, |
| 222 | {"/graph", false, func(ctx context.Context, in string) bool { c.handleGraphCommand(ctx, in); return false }}, |
| 223 | {"/mcp", false, func(ctx context.Context, in string) bool { c.handleMCPCommand(ctx, in); return false }}, |
no test coverage detected