forked from genuinetools/reg
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmanifest.go
66 lines (54 loc) · 1.52 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/ttys3/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.oci, "oci", false, "force the version of the manifest retrieved to oci (default is v2)")
}
type manifestCommand struct {
oci 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.oci {
// Get the oci manifest if it was explicitly asked for.
manifest, err = r.ManifestOCI(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
}