From 17f66a57e21dcf3f8aa601f0c399781d8d7204dd Mon Sep 17 00:00:00 2001 From: Djordje Lukic Date: Fri, 18 Oct 2019 15:33:01 +0200 Subject: [PATCH] Make image inspect more in line with other tables Signed-off-by: Djordje Lukic --- internal/inspect/inspect.go | 28 +++++-------------- internal/inspect/testdata/inspect-full.golden | 28 ++++++++----------- .../testdata/inspect-overridden.golden | 10 +++---- 3 files changed, 22 insertions(+), 44 deletions(-) diff --git a/internal/inspect/inspect.go b/internal/inspect/inspect.go index 1c6f9aec5..87e522819 100644 --- a/internal/inspect/inspect.go +++ b/internal/inspect/inspect.go @@ -92,35 +92,35 @@ func printTable(out io.Writer, appInfo appInfo) error { for _, service := range appInfo.Services { fmt.Fprintf(w, "%s\t%d\t%s\t%s\n", service.Name, service.Replicas, service.Ports, service.Image) } - }, "Service", "Replicas", "Ports", "Image") + }, "SERVICE", "REPLICAS", "PORTS", "IMAGE") // Add Network section printSection(out, len(appInfo.Networks), func(w io.Writer) { for _, name := range appInfo.Networks { fmt.Fprintln(w, name) } - }, "Network") + }, "NETWORK") // Add Volume section printSection(out, len(appInfo.Volumes), func(w io.Writer) { for _, name := range appInfo.Volumes { fmt.Fprintln(w, name) } - }, "Volume") + }, "VOLUME") // Add Secret section printSection(out, len(appInfo.Secrets), func(w io.Writer) { for _, name := range appInfo.Secrets { fmt.Fprintln(w, name) } - }, "Secret") + }, "SECRET") // Add Parameter section printSection(out, len(appInfo.parametersKeys), func(w io.Writer) { for _, k := range appInfo.parametersKeys { fmt.Fprintf(w, "%s\t%s\n", k, appInfo.Parameters[k]) } - }, "Parameter", "Value") + }, "PARAMETER", "VALUE") // Add Attachments section printSection(out, len(appInfo.Attachments), func(w io.Writer) { @@ -128,7 +128,7 @@ func printTable(out io.Writer, appInfo appInfo) error { sizeString := units.HumanSize(float64(attachment.Size)) fmt.Fprintf(w, "%s\t%s\n", attachment.Path, sizeString) } - }, "Attachment", "Size") + }, "ATTACHMENT", "SIZE") return nil } @@ -146,25 +146,11 @@ func printSection(out io.Writer, len int, printer func(io.Writer), headers ...st } fmt.Fprintln(out) w := tabwriter.NewWriter(out, 0, 0, 1, ' ', 0) - var plural string - if len > 1 { - plural = "s" - } - headers[0] = fmt.Sprintf("%s%s (%d)", headers[0], plural, len) - printHeaders(w, headers...) + fmt.Fprintln(w, strings.Join(headers, "\t")) printer(w) w.Flush() } -func printHeaders(w io.Writer, headers ...string) { - fmt.Fprintln(w, strings.Join(headers, "\t")) - dashes := make([]string, len(headers)) - for i, h := range headers { - dashes[i] = strings.Repeat("-", len(h)) - } - fmt.Fprintln(w, strings.Join(dashes, "\t")) -} - func getAppInfo(app *types.App, config *composetypes.Config, argParameters map[string]string) (appInfo, error) { services := []service{} for _, s := range config.Services { diff --git a/internal/inspect/testdata/inspect-full.golden b/internal/inspect/testdata/inspect-full.golden index a24869939..daa95c290 100644 --- a/internal/inspect/testdata/inspect-full.golden +++ b/internal/inspect/testdata/inspect-full.golden @@ -6,31 +6,25 @@ maintainers: email: dev@example.com -Services (2) Replicas Ports Image ------------- -------- ----- ----- -web1 2 8080-8100 nginx:latest -web2 2 9080-9100 nginx:latest +SERVICE REPLICAS PORTS IMAGE +web1 2 8080-8100 nginx:latest +web2 2 9080-9100 nginx:latest -Networks (2) ------------- +NETWORK my-network1 my-network2 -Volumes (2) ------------ +VOLUME my-volume1 my-volume2 -Secrets (2) ------------ +SECRET my-secret1 my-secret2 -Parameters (2) Value --------------- ----- -port 8080 -text hello +PARAMETER VALUE +port 8080 +text hello -Attachment (1) Size --------------- ---- -config.cfg 9B +ATTACHMENT SIZE +config.cfg 9B diff --git a/internal/inspect/testdata/inspect-overridden.golden b/internal/inspect/testdata/inspect-overridden.golden index 7200e82c0..08f1ca460 100644 --- a/internal/inspect/testdata/inspect-overridden.golden +++ b/internal/inspect/testdata/inspect-overridden.golden @@ -4,10 +4,8 @@ description: "" maintainers: [] -Service (1) Replicas Ports Image ------------ -------- ----- ----- -web 1 80 nginx +SERVICE REPLICAS PORTS IMAGE +web 1 80 nginx -Parameter (1) Value -------------- ----- -web.port 80 +PARAMETER VALUE +web.port 80