Skip to content

Commit

Permalink
crane: add digest --full (#1524)
Browse files Browse the repository at this point in the history
* crane: add digest --full

* --full-ref
  • Loading branch information
imjasonh authored Jan 4, 2023
1 parent 3986cf4 commit e797859
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
16 changes: 15 additions & 1 deletion cmd/crane/cmd/digest.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ import (
"fmt"

"github.com/google/go-containerregistry/pkg/crane"
"github.com/google/go-containerregistry/pkg/name"
"github.com/spf13/cobra"
)

// NewCmdDigest creates a new cobra.Command for the digest subcommand.
func NewCmdDigest(options *[]crane.Option) *cobra.Command {
var tarball string
var fullRef bool
cmd := &cobra.Command{
Use: "digest IMAGE",
Short: "Get the digest of an image",
Expand All @@ -36,17 +38,29 @@ func NewCmdDigest(options *[]crane.Option) *cobra.Command {
}
return errors.New("image reference required without --tarball")
}
if fullRef && tarball != "" {
return errors.New("cannot specify --full-ref with --tarball")
}

digest, err := getDigest(tarball, args, options)
if err != nil {
return err
}
fmt.Println(digest)
if fullRef {
ref, err := name.ParseReference(args[0])
if err != nil {
return err
}
fmt.Println(ref.Context().Digest(digest))
} else {
fmt.Println(digest)
}
return nil
},
}

cmd.Flags().StringVar(&tarball, "tarball", "", "(Optional) path to tarball containing the image")
cmd.Flags().BoolVar(&fullRef, "full-ref", false, "(Optional) if true, print the full image reference by digest")

return cmd
}
Expand Down
1 change: 1 addition & 0 deletions cmd/crane/doc/crane_digest.md

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

0 comments on commit e797859

Please sign in to comment.