make calls consistent, move options to end
This commit is contained in:
parent
20d1b3797a
commit
80970dcee2
2 changed files with 11 additions and 11 deletions
20
images.go
20
images.go
|
@ -110,7 +110,7 @@ func (x *ImagesCommand) Execute(args []string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if imagesCommand.Tree {
|
if imagesCommand.Tree {
|
||||||
fmt.Print(jsonToTree(imagesCommand.NoTruncate, roots, imagesByParent))
|
fmt.Print(jsonToTree(roots, imagesByParent, imagesCommand.NoTruncate))
|
||||||
}
|
}
|
||||||
if imagesCommand.Dot {
|
if imagesCommand.Dot {
|
||||||
fmt.Print(jsonToDot(roots, imagesByParent))
|
fmt.Print(jsonToDot(roots, imagesByParent))
|
||||||
|
@ -163,10 +163,10 @@ IMAGES:
|
||||||
return startImage, nil
|
return startImage, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func jsonToTree(noTrunc bool, images []Image, byParent map[string][]Image) string {
|
func jsonToTree(images []Image, byParent map[string][]Image, noTrunc bool) string {
|
||||||
var buffer bytes.Buffer
|
var buffer bytes.Buffer
|
||||||
|
|
||||||
jsonToText(&buffer, noTrunc, images, byParent, "")
|
jsonToText(&buffer, images, byParent, noTrunc, "")
|
||||||
|
|
||||||
return buffer.String()
|
return buffer.String()
|
||||||
}
|
}
|
||||||
|
@ -235,33 +235,33 @@ func filterImages(images *[]Image, byParent *map[string][]Image) (filteredImages
|
||||||
return filteredImages, filteredChildren
|
return filteredImages, filteredChildren
|
||||||
}
|
}
|
||||||
|
|
||||||
func jsonToText(buffer *bytes.Buffer, noTrunc bool, images []Image, byParent map[string][]Image, prefix string) {
|
func jsonToText(buffer *bytes.Buffer, images []Image, byParent map[string][]Image, noTrunc bool, prefix string) {
|
||||||
var length = len(images)
|
var length = len(images)
|
||||||
if length > 1 {
|
if length > 1 {
|
||||||
for index, image := range images {
|
for index, image := range images {
|
||||||
var nextPrefix string = ""
|
var nextPrefix string = ""
|
||||||
if index+1 == length {
|
if index+1 == length {
|
||||||
PrintTreeNode(buffer, noTrunc, image, prefix+"└─")
|
PrintTreeNode(buffer, image, noTrunc, prefix+"└─")
|
||||||
nextPrefix = " "
|
nextPrefix = " "
|
||||||
} else {
|
} else {
|
||||||
PrintTreeNode(buffer, noTrunc, image, prefix+"├─")
|
PrintTreeNode(buffer, image, noTrunc, prefix+"├─")
|
||||||
nextPrefix = "│ "
|
nextPrefix = "│ "
|
||||||
}
|
}
|
||||||
if subimages, exists := byParent[image.Id]; exists {
|
if subimages, exists := byParent[image.Id]; exists {
|
||||||
jsonToText(buffer, noTrunc, subimages, byParent, prefix+nextPrefix)
|
jsonToText(buffer, subimages, byParent, noTrunc, prefix+nextPrefix)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for _, image := range images {
|
for _, image := range images {
|
||||||
PrintTreeNode(buffer, noTrunc, image, prefix+"└─")
|
PrintTreeNode(buffer, image, noTrunc, prefix+"└─")
|
||||||
if subimages, exists := byParent[image.Id]; exists {
|
if subimages, exists := byParent[image.Id]; exists {
|
||||||
jsonToText(buffer, noTrunc, subimages, byParent, prefix+" ")
|
jsonToText(buffer, subimages, byParent, noTrunc, prefix+" ")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func PrintTreeNode(buffer *bytes.Buffer, noTrunc bool, image Image, prefix string) {
|
func PrintTreeNode(buffer *bytes.Buffer, image Image, noTrunc bool, prefix string) {
|
||||||
var imageID string
|
var imageID string
|
||||||
if noTrunc {
|
if noTrunc {
|
||||||
imageID = image.Id
|
imageID = image.Id
|
||||||
|
|
|
@ -123,7 +123,7 @@ func Test_Tree(t *testing.T) {
|
||||||
} else {
|
} else {
|
||||||
roots = collectRoots(im)
|
roots = collectRoots(im)
|
||||||
}
|
}
|
||||||
result := jsonToTree(treeTest.noTrunc, roots, byParent)
|
result := jsonToTree(roots, byParent, treeTest.noTrunc)
|
||||||
|
|
||||||
for _, regexp := range compileRegexps(t, treeTest.regexps) {
|
for _, regexp := range compileRegexps(t, treeTest.regexps) {
|
||||||
if !regexp.MatchString(result) {
|
if !regexp.MatchString(result) {
|
||||||
|
|
Loading…
Reference in a new issue