From f8106ccec6bab9a6c4a58a1b329e219fb0a3e79d Mon Sep 17 00:00:00 2001 From: Nate Jones Date: Sat, 7 Nov 2015 18:32:49 -0800 Subject: [PATCH] go fmt --- images.go | 50 ++++++++++++++++++++------------------------------ 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/images.go b/images.go index 37525ff..31f6ae3 100644 --- a/images.go +++ b/images.go @@ -30,7 +30,6 @@ type ImagesCommand struct { var imagesCommand ImagesCommand - func (x *ImagesCommand) Execute(args []string) error { var images *[]Image @@ -83,7 +82,7 @@ func (x *ImagesCommand) Execute(args []string) error { images = &ims } - if imagesCommand.Tree || imagesCommand.Dot { + if imagesCommand.Tree || imagesCommand.Dot { var startImage *Image if len(args) > 0 { @@ -118,7 +117,7 @@ func (x *ImagesCommand) Execute(args []string) error { return fmt.Errorf("Unable to find image %s = %s.", startImageArg, startImageRepo) } } - + // select the start image of the tree var roots []Image if startImage == nil { @@ -127,23 +126,23 @@ func (x *ImagesCommand) Execute(args []string) error { startImage.ParentId = "" roots = []Image{*startImage} } - + // build helper map (image -> children) var imagesByParent = make(map[string][]Image) - imagesByParent = collectChildren(images); - + imagesByParent = collectChildren(images) + // image ids truncate // initialize image informations - + // filter images - if imagesCommand.OnlyLabelled{ + if imagesCommand.OnlyLabelled { *images, imagesByParent = filterImages(images, &imagesByParent) } - + var buffer bytes.Buffer - + if imagesCommand.Tree { - jsonToText(&buffer, imagesCommand.NoTruncate, roots, imagesByParent, "") + jsonToText(&buffer, imagesCommand.NoTruncate, roots, imagesByParent, "") } if imagesCommand.Dot { buffer.WriteString("digraph docker {\n") @@ -151,7 +150,7 @@ func (x *ImagesCommand) Execute(args []string) error { buffer.WriteString(" base [style=invisible]\n}\n") buffer.String() } - + fmt.Print(buffer.String()) } else if imagesCommand.Short { fmt.Printf(jsonToShort(images)) @@ -162,7 +161,6 @@ func (x *ImagesCommand) Execute(args []string) error { return nil } - func collectChildren(images *[]Image) map[string][]Image { var imagesByParent = make(map[string][]Image) for _, image := range *images { @@ -172,11 +170,10 @@ func collectChildren(images *[]Image) map[string][]Image { imagesByParent[image.ParentId] = []Image{image} } } - + return imagesByParent } - func collectRoots(images *[]Image) []Image { var roots []Image for _, image := range *images { @@ -184,29 +181,28 @@ func collectRoots(images *[]Image) []Image { roots = append(roots, image) } } - + return roots } - -func filterImages (images *[]Image, byParent *map[string][]Image) (filteredImages []Image, filteredChildren map[string][]Image) { - for i := 0; i 1 if visible { filteredImages = append(filteredImages, (*images)[i]) } else { // change childs parent id // if items are filtered with only one child - for j := 0; j