-
Notifications
You must be signed in to change notification settings - Fork 173
/
manifest.go
66 lines (54 loc) · 1.5 KB
/
manifest.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"context"
"encoding/json"
"flag"
"fmt"
"github.com/genuinetools/reg/registry"
)
const manifestHelp = `Get the json manifest for a repository.`
func (cmd *manifestCommand) Name() string { return "manifest" }
func (cmd *manifestCommand) Args() string { return "[OPTIONS] NAME[:TAG|@DIGEST]" }
func (cmd *manifestCommand) ShortHelp() string { return manifestHelp }
func (cmd *manifestCommand) LongHelp() string { return manifestHelp }
func (cmd *manifestCommand) Hidden() bool { return false }
func (cmd *manifestCommand) Register(fs *flag.FlagSet) {
fs.BoolVar(&cmd.v1, "v1", false, "force the version of the manifest retrieved to v1")
}
type manifestCommand struct {
v1 bool
}
func (cmd *manifestCommand) 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
}
var manifest interface{}
if cmd.v1 {
// Get the v1 manifest if it was explicitly asked for.
manifest, err = r.ManifestV1(ctx, image.Path, image.Reference())
if err != nil {
return err
}
} else {
// Get the v2 manifest.
manifest, err = r.Manifest(ctx, image.Path, image.Reference())
if err != nil {
return err
}
}
b, err := json.MarshalIndent(manifest, " ", " ")
if err != nil {
return err
}
fmt.Println(string(b))
return nil
}