spiegel_podman/cmd/podman/common/diffChanges.go
Valentin Rothberg 5dded6fae7 bump go module to v3
We missed bumping the go module, so let's do it now :)

* Automated go code with github.com/sirkon/go-imports-rename
* Manually via `vgrep podman/v2` the rest

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-02-22 09:03:51 +01:00

43 lines
1 KiB
Go

package common
import (
"fmt"
"os"
"github.com/containers/podman/v3/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
}