Skip to content

Commit 8ea5e0e

Browse files
authored
crane: support --omit-digest-tags in crane ls (#1528)
1 parent 4e95ae2 commit 8ea5e0e

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

cmd/crane/cmd/list.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package cmd
1616

1717
import (
1818
"fmt"
19+
"strings"
1920

2021
"github.com/google/go-containerregistry/pkg/crane"
2122
"github.com/google/go-containerregistry/pkg/name"
@@ -24,7 +25,7 @@ import (
2425

2526
// NewCmdList creates a new cobra.Command for the ls subcommand.
2627
func NewCmdList(options *[]crane.Option) *cobra.Command {
27-
var fullRef bool
28+
var fullRef, omitDigestTags bool
2829
cmd := &cobra.Command{
2930
Use: "ls REPO",
3031
Short: "List the tags in a repo",
@@ -42,6 +43,10 @@ func NewCmdList(options *[]crane.Option) *cobra.Command {
4243
}
4344

4445
for _, tag := range tags {
46+
if omitDigestTags && strings.HasPrefix(tag, "sha256-") {
47+
continue
48+
}
49+
4550
if fullRef {
4651
fmt.Println(r.Tag(tag))
4752
} else {
@@ -52,5 +57,6 @@ func NewCmdList(options *[]crane.Option) *cobra.Command {
5257
},
5358
}
5459
cmd.Flags().BoolVar(&fullRef, "full-ref", false, "(Optional) if true, print the full image reference")
60+
cmd.Flags().BoolVar(&omitDigestTags, "omit-digest-tags", false, "(Optional), if true, omit digest tags (e.g., ':sha256-...')")
5561
return cmd
5662
}

cmd/crane/doc/crane_ls.md

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)