aboutsummaryrefslogtreecommitdiff
path: root/cmd/podman/common
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-10-21 17:59:56 -0400
committerGitHub <noreply@github.com>2020-10-21 17:59:56 -0400
commit2bd920b00540280696d19dc95ab6e562aebd6b7d (patch)
tree76e7bd0ff448253d4d4ec23f41865297161a973b /cmd/podman/common
parent61b276a05c1c8adc51c6d4f7c061b89ce39a803b (diff)
parentbab3cda0e81fa3ac3315601f5ec17724f3ad8ed5 (diff)
downloadpodman-2bd920b00540280696d19dc95ab6e562aebd6b7d.tar.gz
podman-2bd920b00540280696d19dc95ab6e562aebd6b7d.tar.bz2
podman-2bd920b00540280696d19dc95ab6e562aebd6b7d.zip
Merge pull request #8077 from jwhonce/wip/report
Refactor podman to use c/common/pkg/report
Diffstat (limited to 'cmd/podman/common')
-rw-r--r--cmd/podman/common/diffChanges.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/cmd/podman/common/diffChanges.go b/cmd/podman/common/diffChanges.go
new file mode 100644
index 000000000..4aa485acc
--- /dev/null
+++ b/cmd/podman/common/diffChanges.go
@@ -0,0 +1,43 @@
+package common
+
+import (
+ "fmt"
+ "os"
+
+ "github.com/containers/podman/v2/pkg/domain/entities"
+ "github.com/containers/storage/pkg/archive"
+ "github.com/pkg/errors"
+)
+
+type ChangesReportJSON struct {
+ Changed []string `json:"changed,omitempty"`
+ Added []string `json:"added,omitempty"`
+ Deleted []string `json:"deleted,omitempty"`
+}
+
+func ChangesToJSON(diffs *entities.DiffReport) error {
+ body := ChangesReportJSON{}
+ for _, row := range diffs.Changes {
+ switch row.Kind {
+ case archive.ChangeAdd:
+ body.Added = append(body.Added, row.Path)
+ case archive.ChangeDelete:
+ body.Deleted = append(body.Deleted, row.Path)
+ case archive.ChangeModify:
+ body.Changed = append(body.Changed, row.Path)
+ default:
+ return errors.Errorf("output kind %q not recognized", row.Kind)
+ }
+ }
+
+ // Pull in configured json library
+ enc := json.NewEncoder(os.Stdout)
+ return enc.Encode(body)
+}
+
+func ChangesToTable(diffs *entities.DiffReport) error {
+ for _, row := range diffs.Changes {
+ fmt.Fprintln(os.Stdout, row.String())
+ }
+ return nil
+}