Skip to content
This repository has been archived by the owner on Jun 13, 2021. It is now read-only.

Commit

Permalink
Remove App-only fields from CNAB image inspect out
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
zappy-shu committed Nov 20, 2019
1 parent db25844 commit 9af8789
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions internal/inspect/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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:
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 9af8789

Please sign in to comment.