summaryrefslogtreecommitdiff
path: root/cmd/podmanV2/report/diff.go
diff options
context:
space:
mode:
authorJhon Honce <jhonce@redhat.com>2020-04-06 16:40:32 -0700
committerJhon Honce <jhonce@redhat.com>2020-04-07 09:39:46 -0700
commit8ae28a55acc51a02597b23140916a690fbbdc3fc (patch)
tree735d876be3204dcd54c7e739083cc706dec83101 /cmd/podmanV2/report/diff.go
parent44f910c28cae178eab9ad439587355fa4927dab7 (diff)
downloadpodman-8ae28a55acc51a02597b23140916a690fbbdc3fc.tar.gz
podman-8ae28a55acc51a02597b23140916a690fbbdc3fc.tar.bz2
podman-8ae28a55acc51a02597b23140916a690fbbdc3fc.zip
V2 podman diff(changes) support
* Ported CLI command * Added API endpoint * Added bindings * Updated swagger (TODO: n endpoints, one handler) Signed-off-by: Jhon Honce <jhonce@redhat.com>
Diffstat (limited to 'cmd/podmanV2/report/diff.go')
-rw-r--r--cmd/podmanV2/report/diff.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/cmd/podmanV2/report/diff.go b/cmd/podmanV2/report/diff.go
new file mode 100644
index 000000000..b36189d75
--- /dev/null
+++ b/cmd/podmanV2/report/diff.go
@@ -0,0 +1,44 @@
+package report
+
+import (
+ "fmt"
+ "os"
+
+ "github.com/containers/libpod/pkg/domain/entities"
+ "github.com/containers/storage/pkg/archive"
+ jsoniter "github.com/json-iterator/go"
+ "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)
+ }
+ }
+
+ json := jsoniter.ConfigCompatibleWithStandardLibrary
+ 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
+}