Fix print tree by startimage
Print tree nodes if only-labeled
This commit is contained in:
parent
c25c0eb801
commit
6eeb877c5e
1 changed files with 19 additions and 15 deletions
34
images.go
34
images.go
|
@ -92,37 +92,33 @@ func (x *ImagesCommand) Execute(args []string) error {
|
||||||
|
|
||||||
// attempt to find the start image, which can be specified as an
|
// attempt to find the start image, which can be specified as an
|
||||||
// image ID or a repository name
|
// image ID or a repository name
|
||||||
|
|
||||||
startImageArg := args[0]
|
startImageArg := args[0]
|
||||||
startImageRepo := args[0]
|
startImageRepo := args[0]
|
||||||
|
|
||||||
// in case a repo name was specified, append ":latest" if it isn't
|
// if tag is not defined, find by :latest tag
|
||||||
// already there
|
if strings.Index(startImageRepo, ":") == -1 {
|
||||||
if !strings.HasSuffix(startImageRepo, ":latest") {
|
|
||||||
startImageRepo = fmt.Sprintf("%s:latest", startImageRepo)
|
startImageRepo = fmt.Sprintf("%s:latest", startImageRepo)
|
||||||
}
|
}
|
||||||
|
|
||||||
IMAGES:
|
IMAGES:
|
||||||
for _, image := range *images {
|
for _, image := range *images {
|
||||||
// check if the start image arg matches an image id
|
// find by image id
|
||||||
if strings.Index(image.Id, startImageArg) == 0 {
|
if strings.Index(image.Id, startImageArg) == 0 {
|
||||||
startImage = image.Id
|
startImage = image.Id
|
||||||
break IMAGES
|
break IMAGES
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if the start image arg matches an repository name
|
// find by image name (name and tag)
|
||||||
if image.RepoTags[0] != "<none>:<none>" {
|
for _, repotag := range image.RepoTags {
|
||||||
for _, repotag := range image.RepoTags {
|
if repotag == startImageRepo {
|
||||||
if repotag == startImageRepo {
|
startImage = image.Id
|
||||||
startImage = image.Id
|
break IMAGES
|
||||||
break IMAGES
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if startImage == "" {
|
if startImage == "" {
|
||||||
return fmt.Errorf("Unable to find image %s.", startImageArg)
|
return fmt.Errorf("Unable to find image %s = %s.", startImageArg, startImageRepo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,7 +177,11 @@ func WalkTree(buffer *bytes.Buffer, noTrunc bool, onlyLabeled bool, images []Ima
|
||||||
if length > 1 {
|
if length > 1 {
|
||||||
for index, image := range images {
|
for index, image := range images {
|
||||||
var nextPrefix string = ""
|
var nextPrefix string = ""
|
||||||
var visible bool = onlyLabeled && image.RepoTags[0] != "<none>:<none>" || !onlyLabeled
|
// image is visible
|
||||||
|
// 1. it has a label
|
||||||
|
// 2. it is root
|
||||||
|
// 3. it is a node
|
||||||
|
var visible bool = onlyLabeled && image.RepoTags[0] != "<none>:<none>" || !onlyLabeled || image.ParentId == "" || len(byParent[image.Id]) > 1
|
||||||
if visible {
|
if visible {
|
||||||
if index+1 == length {
|
if index+1 == length {
|
||||||
PrintTreeNode(buffer, noTrunc, image, prefix+"└─")
|
PrintTreeNode(buffer, noTrunc, image, prefix+"└─")
|
||||||
|
@ -198,7 +198,11 @@ func WalkTree(buffer *bytes.Buffer, noTrunc bool, onlyLabeled bool, images []Ima
|
||||||
} else {
|
} else {
|
||||||
for _, image := range images {
|
for _, image := range images {
|
||||||
var nextPrefix string = ""
|
var nextPrefix string = ""
|
||||||
var visible bool = onlyLabeled && image.RepoTags[0] != "<none>:<none>" || !onlyLabeled
|
// image is visible
|
||||||
|
// 1. it has a label
|
||||||
|
// 2. it is root
|
||||||
|
// 3. it is a node
|
||||||
|
var visible bool = onlyLabeled && image.RepoTags[0] != "<none>:<none>" || !onlyLabeled || image.ParentId == "" || len(byParent[image.Id]) > 1
|
||||||
if visible {
|
if visible {
|
||||||
PrintTreeNode(buffer, noTrunc, image, prefix+"└─")
|
PrintTreeNode(buffer, noTrunc, image, prefix+"└─")
|
||||||
nextPrefix = " "
|
nextPrefix = " "
|
||||||
|
|
Loading…
Reference in a new issue