From 9af87899b7f101eabab59696c466d91c100438f4 Mon Sep 17 00:00:00 2001 From: Nick Adcock Date: Wed, 20 Nov 2019 11:33:30 +0000 Subject: [PATCH] Remove App-only fields from CNAB image inspect out Removes the App-only SERVICE fields from the `app image inspect --pretty` output when inspecting a non-App CNAB: * REPLICAS * PORTS Signed-off-by: Nick Adcock --- internal/inspect/inspect.go | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/internal/inspect/inspect.go b/internal/inspect/inspect.go index 3d0235e01..2a4c6be15 100644 --- a/internal/inspect/inspect.go +++ b/internal/inspect/inspect.go @@ -111,7 +111,7 @@ func ImageInspect(out io.Writer, app *types.App, argParameters map[string]string } outputFormat := os.Getenv(internal.DockerInspectFormatEnvVar) - return printImageAppInfo(out, appInfo, outputFormat) + return printImageAppInfo(out, appInfo, outputFormat, true) } func ImageInspectCNAB(out io.Writer, bndl *bundle.Bundle, outputFormat string) error { @@ -154,7 +154,7 @@ func ImageInspectCNAB(out io.Writer, bndl *bundle.Bundle, outputFormat string) e Services: services, } - return printImageAppInfo(out, appInfo, outputFormat) + return printImageAppInfo(out, appInfo, outputFormat, false) } func printAppInfo(out io.Writer, app AppInfo, format string) error { @@ -168,10 +168,10 @@ func printAppInfo(out io.Writer, app AppInfo, format string) error { } } -func printImageAppInfo(out io.Writer, app ImageAppInfo, format string) error { +func printImageAppInfo(out io.Writer, app ImageAppInfo, format string, isApp bool) error { switch format { case "pretty": - return printTable(out, app) + return printTable(out, app, isApp) case "json": return printJSON(out, app) default: @@ -209,16 +209,24 @@ func printAppTable(out io.Writer, info AppInfo) error { return nil } -func printTable(out io.Writer, appInfo ImageAppInfo) error { +func printTable(out io.Writer, appInfo ImageAppInfo, isApp bool) error { // Add Meta data printYAML(out, appInfo.Metadata) // Add Service section - printSection(out, len(appInfo.Services), func(w io.Writer) { - 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") + if isApp { + printSection(out, len(appInfo.Services), func(w io.Writer) { + 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") + } else { + printSection(out, len(appInfo.Services), func(w io.Writer) { + for _, service := range appInfo.Services { + fmt.Fprintf(w, "%s\t%s\n", service.Name, service.Image) + } + }, "SERVICE", "IMAGE") + } // Add Network section printSection(out, len(appInfo.Networks), func(w io.Writer) {