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

Method handleDeleteSession

cli/cli_session.go:338–444  ·  view source on GitHub ↗
(ctx context.Context, name string)

Source from the content-addressed store, hash-verified

336}
337
338func (cli *ChatCLI) handleDeleteSession(ctx context.Context, name string) {
339 if cli.isRemote {
340 rc := cli.getRemoteClient()
341 if rc == nil {
342 fmt.Println(i18n.T("session.error_delete", fmt.Errorf("remote client unavailable")))
343 return
344 }
345
346 // Check both sources
347 _, localErr := cli.sessionManager.LoadSession(name)
348 ctx, cancel := remoteSessionCtx(ctx)
349 defer cancel()
350 _, remoteErr := rc.LoadSession(ctx, name)
351
352 foundLocal := localErr == nil
353 foundRemote := remoteErr == nil
354
355 switch {
356 case foundLocal && foundRemote:
357 fmt.Println(i18n.T("session.delete_found_both", name))
358 choice := askSessionChoice(
359 []string{"session.option_local", "session.option_remote", "session.option_both"},
360 map[string]string{"l": "local", "r": "remote", "b": "both"},
361 "local",
362 )
363 switch choice {
364 case "remote":
365 ctxDel, cancelDel := remoteSessionCtx(ctx)
366 defer cancelDel()
367 if err := rc.DeleteSession(ctxDel, name); err != nil {
368 fmt.Println(i18n.T("session.error_delete", err))
369 } else {
370 fmt.Println(i18n.T("session.delete_success_remote", name))
371 }
372 case "both":
373 localDelErr := cli.sessionManager.DeleteSession(name)
374 ctxDel, cancelDel := remoteSessionCtx(ctx)
375 defer cancelDel()
376 remoteDelErr := rc.DeleteSession(ctxDel, name)
377 if localDelErr != nil {
378 fmt.Println(i18n.T("session.error_delete", fmt.Errorf("local: %w", localDelErr)))
379 }
380 if remoteDelErr != nil {
381 fmt.Println(i18n.T("session.error_delete", fmt.Errorf("remote: %w", remoteDelErr)))
382 }
383 if localDelErr == nil && remoteDelErr == nil {
384 fmt.Println(i18n.T("session.delete_success_both", name))
385 if cli.currentSessionName == name {
386 cli.clearAllHistories()
387 cli.currentSessionName = ""
388 fmt.Println(i18n.T("session.delete_active_cleared"))
389 }
390 }
391 default: // "local"
392 if err := cli.sessionManager.DeleteSession(name); err != nil {
393 fmt.Println(i18n.T("session.error_delete", err))
394 } else {
395 fmt.Println(i18n.T("session.delete_success", name))

Callers 1

handleSessionCommandMethod · 0.80

Calls 8

getRemoteClientMethod · 0.95
clearAllHistoriesMethod · 0.95
TFunction · 0.92
remoteSessionCtxFunction · 0.85
askSessionChoiceFunction · 0.85
ErrorfMethod · 0.80
LoadSessionMethod · 0.65
DeleteSessionMethod · 0.65

Tested by

no test coverage detected