Skip to content

Commit 5eba253

Browse files
add merged source for diff (#36)
* add merged source for diff * try float as string * revert: try float as string * update readme * update readme * revert some unnecesary changes * sort slices comment * apply defaults from root config to profiles * revert
1 parent 8997576 commit 5eba253

4 files changed

Lines changed: 43 additions & 3 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ Global Flags:
221221
--profile string Configuration profile
222222
```
223223

224+
> **Note:** Use `--source merged` flag to show only the changes that will be applied to the remote branch, instead of displaying the complete configuration difference. It ignores all skipped entities and fields.
225+
224226
Sample execution
225227

226228
```

internal/cac/api/source.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ var ErrUnknownSource = errors.New("unknown source")
1313
const (
1414
SourceLocal SourceType = "local"
1515
SourceRemote SourceType = "remote"
16+
SourceMerged SourceType = "merged"
1617
)
1718

1819
func SourceFromString(s string) (SourceType, error) {
@@ -21,6 +22,8 @@ func SourceFromString(s string) (SourceType, error) {
2122
return SourceLocal, nil
2223
case "remote":
2324
return SourceRemote, nil
25+
case "merged":
26+
return SourceMerged, nil
2427
}
2528

2629
return "", ErrUnknownSource

internal/cac/app.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,34 @@ func (a *Application) PickSource(source string, tenant bool) (api.Source, error)
117117
}
118118

119119
return c, nil
120+
case api.SourceMerged:
121+
var (
122+
c *client.Client
123+
err error
124+
)
125+
126+
ms, err := storage.InitMultiStorage(conf.Storage, constructor)
127+
128+
if err != nil {
129+
return nil, err
130+
}
131+
132+
storages := ms.Storages
133+
134+
if c, err = client.InitClient(conf.Client); err != nil {
135+
return nil, err
136+
}
137+
138+
if !tenant {
139+
storages = append(storages, c)
140+
} else {
141+
storages = append(storages, c.Tenant())
142+
}
143+
144+
return &storage.MultiStorage{
145+
Storages: storages,
146+
Config: ms.Config,
147+
}, nil
120148
}
121149

122150
return nil, api.ErrUnknownSource

internal/cac/diff/diff.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ package diff
22

33
import (
44
"context"
5+
"regexp"
6+
57
"github.com/cloudentity/acp-client-go/clients/hub/models"
68
"github.com/cloudentity/cac/internal/cac/api"
79
"github.com/cloudentity/cac/internal/cac/utils"
810
"github.com/google/go-cmp/cmp"
11+
"github.com/google/go-cmp/cmp/cmpopts"
912
"golang.org/x/exp/slog"
10-
"regexp"
1113
)
1214

1315
type Options struct {
@@ -162,10 +164,15 @@ func Tree(source models.Rfc7396PatchOperation, target models.Rfc7396PatchOperati
162164
diffOpts = append(diffOpts, filterSecretFields)
163165
}
164166

165-
var out = cmp.Diff(target, source, diffOpts)
167+
// sorting slices to avoid diffs due to different order
168+
diffOpts = append(diffOpts, cmpopts.SortSlices(func(a, b string) bool {
169+
return a < b
170+
}))
171+
172+
out := cmp.Diff(target, source, diffOpts)
166173

167174
if options.Color {
168-
return colorize(out), nil
175+
out = colorize(out)
169176
}
170177

171178
return out, nil

0 commit comments

Comments
 (0)