handleMerge merges multiple contexts into a new one.
(args []string)
| 340 | |
| 341 | // handleMerge merges multiple contexts into a new one. |
| 342 | func (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. |
| 382 | func (h *ContextHandler) GetManager() *ctxmgr.Manager { |
no test coverage detected