MCPcopy Create free account
hub / github.com/compozy/agh / mergeWorkspaceAddDirs

Function mergeWorkspaceAddDirs

internal/cli/workspace.go:599–633  ·  view source on GitHub ↗
(existing []string, add []string, remove []string)

Source from the content-addressed store, hash-verified

597}
598
599func mergeWorkspaceAddDirs(existing []string, add []string, remove []string) ([]string, error) {
600 addDirs := trimmedUniqueStrings(add)
601 removeDirs := trimmedUniqueStrings(remove)
602
603 removeSet := make(map[string]struct{}, len(removeDirs))
604 for _, dir := range removeDirs {
605 removeSet[dir] = struct{}{}
606 }
607 for _, dir := range addDirs {
608 if _, exists := removeSet[dir]; exists {
609 return nil, fmt.Errorf("cli: cannot add and remove the same directory: %s", dir)
610 }
611 }
612
613 merged := make([]string, 0, len(existing)+len(addDirs))
614 seen := make(map[string]struct{}, len(existing)+len(addDirs))
615 for _, dir := range trimmedUniqueStrings(existing) {
616 if _, removed := removeSet[dir]; removed {
617 continue
618 }
619 if _, exists := seen[dir]; exists {
620 continue
621 }
622 seen[dir] = struct{}{}
623 merged = append(merged, dir)
624 }
625 for _, dir := range addDirs {
626 if _, exists := seen[dir]; exists {
627 continue
628 }
629 seen[dir] = struct{}{}
630 merged = append(merged, dir)
631 }
632 return merged, nil
633}
634
635func trimmedUniqueStrings(values []string) []string {
636 out := make([]string, 0, len(values))

Callers 1

newWorkspaceEditCommandFunction · 0.85

Calls 2

trimmedUniqueStringsFunction · 0.85
appendFunction · 0.85

Tested by

no test coverage detected