...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package main
16
17 import (
18 "context"
19 "os"
20 "os/signal"
21
22 "github.com/google/go-containerregistry/cmd/crane/cmd"
23 gcmd "github.com/google/go-containerregistry/cmd/gcrane/cmd"
24 "github.com/google/go-containerregistry/pkg/crane"
25 "github.com/google/go-containerregistry/pkg/gcrane"
26 "github.com/google/go-containerregistry/pkg/logs"
27 "github.com/spf13/cobra"
28 )
29
30 func init() {
31 logs.Warn.SetOutput(os.Stderr)
32 logs.Progress.SetOutput(os.Stderr)
33 }
34
35 const (
36 use = "gcrane"
37 short = "gcrane is a tool for managing container images on gcr.io and pkg.dev"
38 )
39
40 func main() {
41 options := []crane.Option{crane.WithAuthFromKeychain(gcrane.Keychain)}
42
43 root := cmd.New(use, short, options)
44
45
46 gcraneCmds := []*cobra.Command{gcmd.NewCmdList(), gcmd.NewCmdGc(), gcmd.NewCmdCopy(), cmd.NewCmdAuth(options, "gcrane", "auth")}
47
48
49 used := make(map[string]bool)
50 for _, cmd := range gcraneCmds {
51 used[cmd.Use] = true
52 }
53
54
55 for _, cmd := range root.Commands() {
56 if _, ok := used[cmd.Use]; ok {
57 root.RemoveCommand(cmd)
58 }
59 }
60
61
62 for _, cmd := range gcraneCmds {
63 root.AddCommand(cmd)
64 }
65
66 ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
67 defer cancel()
68 if err := root.ExecuteContext(ctx); err != nil {
69 cancel()
70 os.Exit(1)
71 }
72 }
73
View as plain text