Skip to content

Commit e797859

Browse files
authored
crane: add digest --full (#1524)
* crane: add digest --full * --full-ref
1 parent 3986cf4 commit e797859

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

cmd/crane/cmd/digest.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ import (
1919
"fmt"
2020

2121
"github.com/google/go-containerregistry/pkg/crane"
22+
"github.com/google/go-containerregistry/pkg/name"
2223
"github.com/spf13/cobra"
2324
)
2425

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

4045
digest, err := getDigest(tarball, args, options)
4146
if err != nil {
4247
return err
4348
}
44-
fmt.Println(digest)
49+
if fullRef {
50+
ref, err := name.ParseReference(args[0])
51+
if err != nil {
52+
return err
53+
}
54+
fmt.Println(ref.Context().Digest(digest))
55+
} else {
56+
fmt.Println(digest)
57+
}
4558
return nil
4659
},
4760
}
4861

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

5165
return cmd
5266
}

cmd/crane/doc/crane_digest.md

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)