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

Method handleListSessions

cli/cli_session.go:274–336  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

272}
273
274func (cli *ChatCLI) handleListSessions(ctx context.Context) {
275 if cli.isRemote {
276 rc := cli.getRemoteClient()
277
278 // Fetch both sources
279 localSessions, localErr := cli.sessionManager.ListSessions()
280 var remoteSessions []string
281 var remoteErr error
282 if rc != nil {
283 ctx, cancel := remoteSessionCtx(ctx)
284 defer cancel()
285 remoteSessions, remoteErr = rc.ListSessions(ctx)
286 }
287
288 hasLocal := localErr == nil && len(localSessions) > 0
289 hasRemote := remoteErr == nil && len(remoteSessions) > 0
290
291 if !hasLocal && !hasRemote {
292 if localErr != nil {
293 fmt.Println(i18n.T("session.error_list", localErr))
294 }
295 if remoteErr != nil {
296 fmt.Println(i18n.T("session.error_list", remoteErr))
297 }
298 if localErr == nil && remoteErr == nil {
299 fmt.Println(i18n.T("session.list_empty"))
300 }
301 return
302 }
303
304 if hasLocal {
305 fmt.Println(i18n.T("session.list_header_local"))
306 for _, s := range localSessions {
307 fmt.Printf(" - %s\n", s)
308 }
309 }
310 if hasRemote {
311 if hasLocal {
312 fmt.Println()
313 }
314 fmt.Println(i18n.T("session.list_header_remote"))
315 for _, s := range remoteSessions {
316 fmt.Printf(" - %s\n", s)
317 }
318 }
319 return
320 }
321
322 // Local only
323 sessions, err := cli.sessionManager.ListSessions()
324 if err != nil {
325 fmt.Println(i18n.T("session.error_list", err))
326 return
327 }
328 if len(sessions) == 0 {
329 fmt.Println(i18n.T("session.list_empty"))
330 return
331 }

Callers 1

handleSessionCommandMethod · 0.80

Calls 4

getRemoteClientMethod · 0.95
TFunction · 0.92
remoteSessionCtxFunction · 0.85
ListSessionsMethod · 0.65

Tested by

no test coverage detected