forked from genuinetools/reg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
digest.go
48 lines (36 loc) · 1.03 KB
/
digest.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"context"
"flag"
"fmt"
"github.com/genuinetools/reg/registry"
)
const digestHelp = `Get the digest for a repository.`
func (cmd *digestCommand) Name() string { return "digest" }
func (cmd *digestCommand) Args() string { return "[OPTIONS] NAME[:TAG]" }
func (cmd *digestCommand) ShortHelp() string { return digestHelp }
func (cmd *digestCommand) LongHelp() string { return digestHelp }
func (cmd *digestCommand) Hidden() bool { return false }
func (cmd *digestCommand) Register(fs *flag.FlagSet) {}
type digestCommand struct{}
func (cmd *digestCommand) Run(ctx context.Context, args []string) error {
if len(args) < 1 {
return fmt.Errorf("pass the name of the repository")
}
image, err := registry.ParseImage(args[0])
if err != nil {
return err
}
// Create the registry client.
r, err := createRegistryClient(ctx, image.Domain)
if err != nil {
return err
}
// Get the digest.
digest, err := r.Digest(ctx, image)
if err != nil {
return err
}
fmt.Println(digest.String())
return nil
}