@@ -110,7 +110,54 @@ func ImageInspect(out io.Writer, app *types.App, argParameters map[string]string
110110 }
111111
112112 outputFormat := os .Getenv (internal .DockerInspectFormatEnvVar )
113- return printImageAppInfo (out , appInfo , outputFormat )
113+ return printImageAppInfo (out , appInfo , outputFormat , true )
114+ }
115+
116+ func ImageInspectCNAB (out io.Writer , bndl * bundle.Bundle , outputFormat string ) error {
117+ meta := metadata.AppMetadata {
118+ Description : bndl .Description ,
119+ Name : bndl .Name ,
120+ Version : bndl .Version ,
121+ Maintainers : []metadata.Maintainer {},
122+ }
123+ for _ , m := range bndl .Maintainers {
124+ meta .Maintainers = append (meta .Maintainers , metadata.Maintainer {
125+ Name : m .Name ,
126+ Email : m .Email ,
127+ })
128+ }
129+
130+ paramKeys := []string {}
131+ params := map [string ]string {}
132+ for _ , v := range bndl .Parameters {
133+ paramKeys = append (paramKeys , v .Definition )
134+ if d , ok := bndl .Definitions [v .Definition ]; ok && d .Default != nil {
135+ params [v .Definition ] = fmt .Sprint (d .Default )
136+ } else {
137+ params [v .Definition ] = ""
138+ }
139+ }
140+ sort .Strings (paramKeys )
141+
142+ services := []Service {}
143+ for k , v := range bndl .Images {
144+ services = append (services , Service {
145+ Name : k ,
146+ Image : v .Image ,
147+ })
148+ }
149+ sort .SliceStable (services , func (i , j int ) bool {
150+ return services [i ].Name < services [j ].Name
151+ })
152+
153+ appInfo := ImageAppInfo {
154+ Metadata : meta ,
155+ parametersKeys : paramKeys ,
156+ Parameters : params ,
157+ Services : services ,
158+ }
159+
160+ return printImageAppInfo (out , appInfo , outputFormat , false )
114161}
115162
116163func printAppInfo (out io.Writer , app AppInfo , format string ) error {
@@ -124,10 +171,10 @@ func printAppInfo(out io.Writer, app AppInfo, format string) error {
124171 }
125172}
126173
127- func printImageAppInfo (out io.Writer , app ImageAppInfo , format string ) error {
174+ func printImageAppInfo (out io.Writer , app ImageAppInfo , format string , isApp bool ) error {
128175 switch format {
129176 case "pretty" :
130- return printTable (out , app )
177+ return printTable (out , app , isApp )
131178 case "json" :
132179 return printJSON (out , app )
133180 default :
@@ -165,16 +212,24 @@ func printAppTable(out io.Writer, info AppInfo) error {
165212 return nil
166213}
167214
168- func printTable (out io.Writer , appInfo ImageAppInfo ) error {
215+ func printTable (out io.Writer , appInfo ImageAppInfo , isApp bool ) error {
169216 // Add Meta data
170217 printYAML (out , appInfo .Metadata )
171218
172219 // Add Service section
173- printSection (out , len (appInfo .Services ), func (w io.Writer ) {
174- for _ , service := range appInfo .Services {
175- fmt .Fprintf (w , "%s\t %d\t %s\t %s\n " , service .Name , service .Replicas , service .Ports , service .Image )
176- }
177- }, "SERVICE" , "REPLICAS" , "PORTS" , "IMAGE" )
220+ if isApp {
221+ printSection (out , len (appInfo .Services ), func (w io.Writer ) {
222+ for _ , service := range appInfo .Services {
223+ fmt .Fprintf (w , "%s\t %d\t %s\t %s\n " , service .Name , service .Replicas , service .Ports , service .Image )
224+ }
225+ }, "SERVICE" , "REPLICAS" , "PORTS" , "IMAGE" )
226+ } else {
227+ printSection (out , len (appInfo .Services ), func (w io.Writer ) {
228+ for _ , service := range appInfo .Services {
229+ fmt .Fprintf (w , "%s\t %s\n " , service .Name , service .Image )
230+ }
231+ }, "SERVICE" , "IMAGE" )
232+ }
178233
179234 // Add Network section
180235 printSection (out , len (appInfo .Networks ), func (w io.Writer ) {
@@ -325,7 +380,7 @@ func extractParameters(app *types.App, argParameters map[string]string) ([]strin
325380 for k := range allParameters {
326381 parametersKeys = append (parametersKeys , k )
327382 }
328- sort .Slice (parametersKeys , func ( i , j int ) bool { return parametersKeys [ i ] < parametersKeys [ j ] } )
383+ sort .Strings (parametersKeys )
329384 return parametersKeys , allParameters , nil
330385}
331386
0 commit comments