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) {
if len(images) > 1 {
length := len(images)
var length = len(images)
if length > 1 {
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 onlyLabeled && image.RepoTags[0] != "<none>:<none>" || !onlyLabeled {
PrintTreeNode(buffer, noTrunc, image, prefix+"└─")
}
if subimages, exists := byParent[image.Id]; exists {
if onlyLabeled && image.RepoTags[0] != "<none>:<none>" || !onlyLabeled {
WalkTree(buffer, noTrunc, onlyLabeled, subimages, byParent, prefix+" ")
nextPrefix = " "
} else {
WalkTree(buffer, noTrunc, onlyLabeled, subimages, byParent, prefix)
}
}
} else {
if onlyLabeled && image.RepoTags[0] != "<none>:<none>" || !onlyLabeled {
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 {
WalkTree(buffer, noTrunc, onlyLabeled, subimages, byParent, prefix)
}
}
WalkTree(buffer, noTrunc, onlyLabeled, subimages, byParent, prefix+nextPrefix)
}
}
} else {
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+"└─")
nextPrefix = " "
}
if subimages, exists := byParent[image.Id]; exists {
if onlyLabeled && image.RepoTags[0] != "<none>:<none>" || !onlyLabeled {
WalkTree(buffer, noTrunc, onlyLabeled, subimages, byParent, prefix+" ")
} else {
WalkTree(buffer, noTrunc, onlyLabeled, subimages, byParent, prefix)
}
WalkTree(buffer, noTrunc, onlyLabeled, subimages, byParent, prefix+nextPrefix)
}
}
}