11package inspect
22
33import (
4- "bytes"
54 "fmt"
65 "io"
76 "sort"
@@ -28,87 +27,70 @@ func Inspect(out io.Writer, app *types.App, argSettings map[string]string) error
2827 return err
2928 }
3029
31- var sections []* bytes.Buffer
32-
3330 // Add Meta data
34- addMetadata ( & sections , app )
31+ printMetadata ( out , app )
3532
3633 // Add Service section
37- addSection ( & sections , len (config .Services ), func (w io.Writer ) {
34+ printSection ( out , len (config .Services ), func (w io.Writer ) {
3835 for _ , service := range config .Services {
3936 fmt .Fprintf (w , "%s\t %d\t %s\t %s\n " , service .Name , getReplicas (service ), getPorts (service .Ports ), service .Image )
4037 }
4138 }, "Service" , "Replicas" , "Ports" , "Image" )
4239
4340 // Add Network section
44- addSection ( & sections , len (config .Networks ), func (w io.Writer ) {
41+ printSection ( out , len (config .Networks ), func (w io.Writer ) {
4542 for name := range config .Networks {
4643 fmt .Fprintln (w , name )
4744 }
4845 }, "Network" )
4946
5047 // Add Volume section
51- addSection ( & sections , len (config .Volumes ), func (w io.Writer ) {
48+ printSection ( out , len (config .Volumes ), func (w io.Writer ) {
5249 for name := range config .Volumes {
5350 fmt .Fprintln (w , name )
5451 }
5552 }, "Volume" )
5653
5754 // Add Secret section
58- addSection ( & sections , len (config .Secrets ), func (w io.Writer ) {
55+ printSection ( out , len (config .Secrets ), func (w io.Writer ) {
5956 for name := range config .Secrets {
6057 fmt .Fprintln (w , name )
6158 }
6259 }, "Secret" )
6360
6461 // Add Setting section
65- addSection ( & sections , len (settingsKeys ), func (w io.Writer ) {
62+ printSection ( out , len (settingsKeys ), func (w io.Writer ) {
6663 for _ , k := range settingsKeys {
6764 fmt .Fprintf (w , "%s\t %s\n " , k , allSettings [k ])
6865 }
6966 }, "Setting" , "Value" )
7067
71- // Print all sections
72- printSections (out , sections )
73-
7468 return nil
7569}
7670
77- func addMetadata (sections * []* bytes.Buffer , app * types.App ) {
78- buf := & bytes.Buffer {}
71+ func printMetadata (out io.Writer , app * types.App ) {
7972 meta := app .Metadata ()
80- fmt .Fprintln (buf , meta .Name , meta .Version )
73+ fmt .Fprintln (out , meta .Name , meta .Version )
8174 if maintainers := meta .Maintainers .String (); maintainers != "" {
82- fmt .Fprintln (buf )
83- fmt .Fprintln (buf , "Maintained by:" , maintainers )
75+ fmt .Fprintln (out )
76+ fmt .Fprintln (out , "Maintained by:" , maintainers )
8477 }
8578 if meta .Description != "" {
86- fmt .Fprintln (buf )
87- fmt .Fprintln (buf , meta .Description )
79+ fmt .Fprintln (out )
80+ fmt .Fprintln (out , meta .Description )
8881 }
89- * sections = append (* sections , buf )
9082}
9183
92- func addSection ( sections * [] * bytes. Buffer , len int , printer func (io.Writer ), headers ... string ) {
84+ func printSection ( out io. Writer , len int , printer func (io.Writer ), headers ... string ) {
9385 if len == 0 {
9486 return
9587 }
96- buf := & bytes. Buffer {}
97- w := tabwriter .NewWriter (buf , 0 , 0 , 1 , ' ' , 0 )
88+ fmt . Fprintln ( out )
89+ w := tabwriter .NewWriter (out , 0 , 0 , 1 , ' ' , 0 )
9890 headers [0 ] = fmt .Sprintf ("%s (%d)" , headers [0 ], len )
9991 printHeaders (w , headers ... )
10092 printer (w )
10193 w .Flush ()
102- * sections = append (* sections , buf )
103- }
104-
105- // printSections makes sure there isn't any extra line at the end of the command output
106- func printSections (out io.Writer , sections []* bytes.Buffer ) {
107- ss := make ([]string , len (sections ))
108- for i , section := range sections {
109- ss [i ] = section .String ()
110- }
111- fmt .Fprint (out , strings .Join (ss , "\n " ))
11294}
11395
11496func printHeaders (w io.Writer , headers ... string ) {
0 commit comments