MCPcopy Create free account
hub / github.com/diillson/chatcli / handleDisconnectCommand

Method handleDisconnectCommand

cli/command_handler_connect.go:219–255  ·  view source on GitHub ↗

handleDisconnectCommand handles the /disconnect command. It closes the remote connection and restores the local LLM client.

(ctx context.Context)

Source from the content-addressed store, hash-verified

217// handleDisconnectCommand handles the /disconnect command.
218// It closes the remote connection and restores the local LLM client.
219func (ch *CommandHandler) handleDisconnectCommand(ctx context.Context) {
220 if !ch.cli.isRemote {
221 fmt.Println(colorize(i18n.T("connect.error.not_connected"), ColorYellow))
222 return
223 }
224
225 // Clean up remote resources
226 if ch.cli.pluginManager != nil {
227 ch.cli.pluginManager.ClearRemotePlugins()
228 }
229 ch.cli.remoteAgents = nil
230 ch.cli.remoteSkills = nil
231
232 // Close remote connection
233 if ch.cli.remoteConn != nil {
234 _ = ch.cli.remoteConn.Close()
235 }
236
237 // Restore local state
238 ch.cli.Client = ch.cli.localClient
239 ch.cli.Provider = ch.cli.localProvider
240 ch.cli.Model = ch.cli.localModel
241 ch.cli.remoteConn = nil
242 ch.cli.isRemote = false
243 ch.cli.remoteAddress = ""
244 ch.cli.localClient = nil
245 ch.cli.localProvider = ""
246 ch.cli.localModel = ""
247 ch.cli.refreshModelCache(ctx)
248
249 fmt.Println(colorize(i18n.T("connect.status.disconnected"), ColorGreen))
250 if ch.cli.Client != nil {
251 fmt.Println(colorize(i18n.T("connect.status.back_to_local", ch.cli.Model, ch.cli.Provider), ColorCyan))
252 } else {
253 fmt.Println(colorize(i18n.T("connect.status.back_to_local_no_provider"), ColorYellow))
254 }
255}
256
257// resolveLocalAuth reads the local auth store and returns the API key/OAuth token.
258func (ch *CommandHandler) resolveLocalAuth(ctx context.Context, provider string) (apiKey string, resolvedProvider string, err error) {

Callers 1

buildRoutesMethod · 0.95

Calls 5

TFunction · 0.92
colorizeFunction · 0.85
ClearRemotePluginsMethod · 0.80
refreshModelCacheMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected