@@ -125,11 +125,7 @@ var listImageCommand = cli.Command{
125
125
printHeader = false
126
126
fmt .Fprintln (w , "IMAGE\t TAG\t IMAGE ID\t SIZE" )
127
127
}
128
- repoTags := "<none>"
129
- if image .RepoTags != nil {
130
- repoTags = image .RepoTags [0 ]
131
- }
132
- repoTagsPair := strings .Split (repoTags , ":" )
128
+ repoTagsPair := normalizeRepoTagPair (image .RepoTags )
133
129
size := units .HumanSizeWithPrecision (float64 (image .GetSize_ ()), 3 )
134
130
trunctedImage := strings .TrimPrefix (image .Id , "sha256:" )[:truncatedImageIDLen ]
135
131
fmt .Fprintf (w , "%s\t %s\t %s\t %s\n " , repoTagsPair [0 ], repoTagsPair [1 ], trunctedImage , size )
@@ -270,6 +266,21 @@ func getAuth(creds string) (*pb.AuthConfig, error) {
270
266
}, nil
271
267
}
272
268
269
+ // Support these cases as below:
270
+ // "tag1:tag2", "tag1", "tag1:", ":tag2", ":", "", nil
271
+ func normalizeRepoTagPair (repoTags []string ) []string {
272
+ const defaultTag = "<none>"
273
+ if len (repoTags ) == 0 {
274
+ return []string {defaultTag , defaultTag }
275
+ }
276
+ repoTagsPair := strings .Split (repoTags [0 ]+ ":" + defaultTag , ":" )
277
+ // for ":tag2" case
278
+ if repoTagsPair [0 ] == "" {
279
+ repoTagsPair [0 ] = defaultTag
280
+ }
281
+ return repoTagsPair [0 :2 ]
282
+ }
283
+
273
284
// PullImage sends a PullImageRequest to the server, and parses
274
285
// the returned PullImageResponse.
275
286
func PullImage (client pb.ImageServiceClient , image string , auth * pb.AuthConfig ) (* pb.PullImageResponse , error ) {
0 commit comments