Skip to content

Commit 8348b75

Browse files
committed
Status: add DirectoryPath & ContentPath
Signed-off-by: Christophe de Vienne <christophe.devienne@orus.io>
1 parent 4851524 commit 8348b75

3 files changed

Lines changed: 18 additions & 13 deletions

File tree

pkg/vendir/cmd/status.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package cmd
22

33
import (
44
"fmt"
5-
"maps"
65
"os"
76

87
"github.com/cppforlife/go-cli-ui/ui"
@@ -90,8 +89,8 @@ func fullStatus(
9089
syncOpts ctldir.SyncOpts,
9190
existingLockConfig ctlconf.LockConfig,
9291
ui ui.UI,
93-
) (ctlstatus.StatusMap, error) {
94-
status := ctlstatus.StatusMap{}
92+
) (ctlstatus.StatusList, error) {
93+
status := ctlstatus.StatusList{}
9594
for _, dirConf := range conf.Directories {
9695
dirExistingLockConf, _ := existingLockConfig.FindDirectory(dirConf.Path)
9796
directory := ctldir.NewDirectory(dirConf, dirExistingLockConf, ui)
@@ -101,7 +100,7 @@ func fullStatus(
101100
return nil, fmt.Errorf("Reading directory '%s': %s", dirConf.Path, err)
102101
}
103102

104-
maps.Copy(status, dirStatus)
103+
status = append(status, dirStatus...)
105104
}
106105

107106
return status, nil

pkg/vendir/directory/status.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
ctlstatus "carvel.dev/vendir/pkg/vendir/status"
99
)
1010

11-
func (d *Directory) Status(syncOpts SyncOpts) (map[string]*ctlstatus.Status, error) {
12-
res := map[string]*ctlstatus.Status{}
11+
func (d *Directory) Status(syncOpts SyncOpts) (ctlstatus.StatusList, error) {
12+
var res ctlstatus.StatusList
1313

1414
for _, contents := range d.opts.Contents {
1515
path := path.Join(d.opts.Path, contents.Path)
@@ -23,7 +23,9 @@ func (d *Directory) Status(syncOpts SyncOpts) (map[string]*ctlstatus.Status, err
2323
}
2424

2525
if gitStatus != nil {
26-
res[path] = gitStatus
26+
gitStatus.DirectoryPath = d.opts.Path
27+
gitStatus.ContentPath = contents.Path
28+
res = append(res, gitStatus)
2729
}
2830
case contents.Hg != nil:
2931
hgSync := ctlhg.NewSync(
@@ -35,7 +37,9 @@ func (d *Directory) Status(syncOpts SyncOpts) (map[string]*ctlstatus.Status, err
3537
}
3638

3739
if hgStatus != nil {
38-
res[path] = hgStatus
40+
hgStatus.DirectoryPath = d.opts.Path
41+
hgStatus.ContentPath = contents.Path
42+
res = append(res, hgStatus)
3943
}
4044
}
4145
}

pkg/vendir/status/status.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ type CompleteReference struct {
1616
}
1717

1818
type Status struct {
19+
DirectoryPath string
20+
ContentPath string
1921
TargetRef string
2022
Ref CompleteReference
2123
UncommitedChanges []string
@@ -49,14 +51,14 @@ func (s Status) String() string {
4951
return strings.Join(messages, ", ")
5052
}
5153

52-
type StatusMap map[string]*Status
54+
type StatusList []*Status
5355

54-
func (sm StatusMap) String() string {
56+
func (sm StatusList) String() string {
5557
var s string
5658

5759
s += "Detailled status:\n"
58-
for dir, status := range sm {
59-
s += "- " + dir + ": " + status.String() + "\n"
60+
for _, status := range sm {
61+
s += "- " + status.DirectoryPath + "/" + status.ContentPath + ": " + status.String() + "\n"
6062
}
6163

6264
if !sm.IsSafe() {
@@ -66,7 +68,7 @@ func (sm StatusMap) String() string {
6668
return s
6769
}
6870

69-
func (sm StatusMap) IsSafe() bool {
71+
func (sm StatusList) IsSafe() bool {
7072
isSafe := true
7173
for _, status := range sm {
7274
if !status.IsSafe() {

0 commit comments

Comments
 (0)