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

Method handleMerge

cli/context_handler.go:342–379  ·  view source on GitHub ↗

handleMerge merges multiple contexts into a new one.

(args []string)

Source from the content-addressed store, hash-verified

340
341// handleMerge merges multiple contexts into a new one.
342func (h *ContextHandler) handleMerge(args []string) error {
343 if len(args) < 3 {
344 return fmt.Errorf("%s", i18n.T("context.merge.usage"))
345 }
346
347 newName := args[0]
348 contextNames := args[1:]
349
350 // Buscar IDs dos contextos
351 contextIDs := make([]string, 0, len(contextNames))
352 for _, name := range contextNames {
353 ctx, err := h.manager.GetContextByName(name)
354 if err != nil {
355 return fmt.Errorf("%s", i18n.T("context.merge.error.context_not_found", name))
356 }
357 contextIDs = append(contextIDs, ctx.ID)
358 }
359
360 // Opções de merge padrão
361 opts := ctxmgr.MergeOptions{
362 RemoveDuplicates: true,
363 SortByPath: true,
364 PreferNewer: true,
365 Tags: []string{"merged"},
366 }
367
368 fmt.Println(i18n.T("context.merge.processing"))
369
370 mergedCtx, err := h.manager.MergeContexts(newName, "", contextIDs, opts)
371 if err != nil {
372 return fmt.Errorf("%s", i18n.T("context.merge.error.failed", err))
373 }
374
375 fmt.Println(colorize(i18n.T("context.merge.success"), ColorGreen))
376 h.printContextInfo(mergedCtx, false)
377
378 return nil
379}
380
381// GetManager returns the underlying context manager.
382func (h *ContextHandler) GetManager() *ctxmgr.Manager {

Callers 1

HandleContextCommandMethod · 0.95

Calls 6

printContextInfoMethod · 0.95
TFunction · 0.92
colorizeFunction · 0.85
ErrorfMethod · 0.80
GetContextByNameMethod · 0.80
MergeContextsMethod · 0.80

Tested by

no test coverage detected