Skip to content

Commit

Permalink
crane: support --omit-digest-tags in crane ls (#1528)
Browse files Browse the repository at this point in the history
  • Loading branch information
imjasonh authored Feb 24, 2023
1 parent 4e95ae2 commit 8ea5e0e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 7 additions & 1 deletion cmd/crane/cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package cmd

import (
"fmt"
"strings"

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

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

for _, tag := range tags {
if omitDigestTags && strings.HasPrefix(tag, "sha256-") {
continue
}

if fullRef {
fmt.Println(r.Tag(tag))
} else {
Expand All @@ -52,5 +57,6 @@ func NewCmdList(options *[]crane.Option) *cobra.Command {
},
}
cmd.Flags().BoolVar(&fullRef, "full-ref", false, "(Optional) if true, print the full image reference")
cmd.Flags().BoolVar(&omitDigestTags, "omit-digest-tags", false, "(Optional), if true, omit digest tags (e.g., ':sha256-...')")
return cmd
}
5 changes: 3 additions & 2 deletions cmd/crane/doc/crane_ls.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8ea5e0e

Please sign in to comment.