Improve WalkTree

This commit is contained in:
gkovacs81 2015-10-11 12:52:26 +02:00
parent 071f77cbbc
commit c25c0eb801

View file

@ -177,44 +177,34 @@ func jsonToTree(images *[]Image, startImageArg string, noTrunc bool, onlyLabeled
} }
func WalkTree(buffer *bytes.Buffer, noTrunc bool, onlyLabeled bool, images []Image, byParent map[string][]Image, prefix string) { func WalkTree(buffer *bytes.Buffer, noTrunc bool, onlyLabeled bool, images []Image, byParent map[string][]Image, prefix string) {
if len(images) > 1 { var length = len(images)
length := len(images) if length > 1 {
for index, image := range images { for index, image := range images {
var nextPrefix string = ""
var visible bool = onlyLabeled && image.RepoTags[0] != "<none>:<none>" || !onlyLabeled
if visible {
if index+1 == length { if index+1 == length {
if onlyLabeled && image.RepoTags[0] != "<none>:<none>" || !onlyLabeled {
PrintTreeNode(buffer, noTrunc, image, prefix+"└─") PrintTreeNode(buffer, noTrunc, image, prefix+"└─")
} nextPrefix = " "
if subimages, exists := byParent[image.Id]; exists {
if onlyLabeled && image.RepoTags[0] != "<none>:<none>" || !onlyLabeled {
WalkTree(buffer, noTrunc, onlyLabeled, subimages, byParent, prefix+" ")
} else { } else {
WalkTree(buffer, noTrunc, onlyLabeled, subimages, byParent, prefix)
}
}
} else {
if onlyLabeled && image.RepoTags[0] != "<none>:<none>" || !onlyLabeled {
PrintTreeNode(buffer, noTrunc, image, prefix+"├─") PrintTreeNode(buffer, noTrunc, image, prefix+"├─")
nextPrefix = "│ "
}
} }
if subimages, exists := byParent[image.Id]; exists { if subimages, exists := byParent[image.Id]; exists {
if onlyLabeled && image.RepoTags[0] != "<none>:<none>" || !onlyLabeled { WalkTree(buffer, noTrunc, onlyLabeled, subimages, byParent, prefix+nextPrefix)
WalkTree(buffer, noTrunc, onlyLabeled, subimages, byParent, prefix+"│ ")
} else {
WalkTree(buffer, noTrunc, onlyLabeled, subimages, byParent, prefix)
}
}
} }
} }
} else { } else {
for _, image := range images { for _, image := range images {
if onlyLabeled && image.RepoTags[0] != "<none>:<none>" || !onlyLabeled { var nextPrefix string = ""
var visible bool = onlyLabeled && image.RepoTags[0] != "<none>:<none>" || !onlyLabeled
if visible {
PrintTreeNode(buffer, noTrunc, image, prefix+"└─") PrintTreeNode(buffer, noTrunc, image, prefix+"└─")
nextPrefix = " "
} }
if subimages, exists := byParent[image.Id]; exists { if subimages, exists := byParent[image.Id]; exists {
if onlyLabeled && image.RepoTags[0] != "<none>:<none>" || !onlyLabeled { WalkTree(buffer, noTrunc, onlyLabeled, subimages, byParent, prefix+nextPrefix)
WalkTree(buffer, noTrunc, onlyLabeled, subimages, byParent, prefix+" ")
} else {
WalkTree(buffer, noTrunc, onlyLabeled, subimages, byParent, prefix)
}
} }
} }
} }