summaryrefslogtreecommitdiff
path: root/cmd/podman/report
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/podman/report')
-rw-r--r--cmd/podman/report/diff.go43
-rw-r--r--cmd/podman/report/format.go68
-rw-r--r--cmd/podman/report/format_test.go35
-rw-r--r--cmd/podman/report/report.go6
4 files changed, 0 insertions, 152 deletions
diff --git a/cmd/podman/report/diff.go b/cmd/podman/report/diff.go
deleted file mode 100644
index edd324bfe..000000000
--- a/cmd/podman/report/diff.go
+++ /dev/null
@@ -1,43 +0,0 @@
-package report
-
-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
-}
diff --git a/cmd/podman/report/format.go b/cmd/podman/report/format.go
deleted file mode 100644
index 32d92bec5..000000000
--- a/cmd/podman/report/format.go
+++ /dev/null
@@ -1,68 +0,0 @@
-package report
-
-import (
- "reflect"
- "strings"
-)
-
-// tableReplacer will remove 'table ' prefix and clean up tabs
-var tableReplacer = strings.NewReplacer(
- "table ", "",
- `\t`, "\t",
- `\n`, "\n",
- " ", "\t",
-)
-
-// escapedReplacer will clean up escaped characters from CLI
-var escapedReplacer = strings.NewReplacer(
- `\t`, "\t",
- `\n`, "\n",
-)
-
-// NormalizeFormat reads given go template format provided by CLI and munges it into what we need
-func NormalizeFormat(format string) string {
- f := format
- // two replacers used so we only remove the prefix keyword `table`
- if strings.HasPrefix(f, "table ") {
- f = tableReplacer.Replace(f)
- } else {
- f = escapedReplacer.Replace(format)
- }
-
- if !strings.HasSuffix(f, "\n") {
- f += "\n"
- }
-
- return f
-}
-
-// Headers queries the interface for field names
-func Headers(object interface{}, overrides map[string]string) []map[string]string {
- value := reflect.ValueOf(object)
- if value.Kind() == reflect.Ptr {
- value = value.Elem()
- }
-
- // Column header will be field name upper-cased.
- headers := make(map[string]string, value.NumField())
- for i := 0; i < value.Type().NumField(); i++ {
- field := value.Type().Field(i)
- // Recurse to find field names from promoted structs
- if field.Type.Kind() == reflect.Struct && field.Anonymous {
- h := Headers(reflect.New(field.Type).Interface(), nil)
- for k, v := range h[0] {
- headers[k] = v
- }
- continue
- }
- headers[field.Name] = strings.ToUpper(field.Name)
- }
-
- if len(overrides) > 0 {
- // Override column header as provided
- for k, v := range overrides {
- headers[k] = strings.ToUpper(v)
- }
- }
- return []map[string]string{headers}
-}
diff --git a/cmd/podman/report/format_test.go b/cmd/podman/report/format_test.go
deleted file mode 100644
index 7dd62e899..000000000
--- a/cmd/podman/report/format_test.go
+++ /dev/null
@@ -1,35 +0,0 @@
-package report
-
-import (
- "strings"
- "testing"
-)
-
-func TestNormalizeFormat(t *testing.T) {
- cases := []struct {
- format string
- expected string
- }{
- {"table {{.ID}}", "{{.ID}}\n"},
- {"table {{.ID}} {{.C}}", "{{.ID}}\t{{.C}}\n"},
- {"{{.ID}}", "{{.ID}}\n"},
- {"{{.ID}}\n", "{{.ID}}\n"},
- {"{{.ID}} {{.C}}", "{{.ID}} {{.C}}\n"},
- {"\t{{.ID}}", "\t{{.ID}}\n"},
- {`\t` + "{{.ID}}", "\t{{.ID}}\n"},
- {"table {{.ID}}\t{{.C}}", "{{.ID}}\t{{.C}}\n"},
- {"{{.ID}} table {{.C}}", "{{.ID}} table {{.C}}\n"},
- }
- for _, tc := range cases {
- tc := tc
-
- label := strings.ReplaceAll(tc.format, " ", "<sp>")
- t.Run("NormalizeFormat/"+label, func(t *testing.T) {
- t.Parallel()
- actual := NormalizeFormat(tc.format)
- if actual != tc.expected {
- t.Errorf("Expected %q, actual %q", tc.expected, actual)
- }
- })
- }
-}
diff --git a/cmd/podman/report/report.go b/cmd/podman/report/report.go
deleted file mode 100644
index 2c4f2e1fd..000000000
--- a/cmd/podman/report/report.go
+++ /dev/null
@@ -1,6 +0,0 @@
-package report
-
-import "github.com/containers/podman/v2/cmd/podman/registry"
-
-// Pull in configured json library
-var json = registry.JSONLibrary()