MCPcopy Create free account
hub / github.com/quay/clair / exportAction

Function exportAction

cmd/clairctl/export.go:55–154  ·  view source on GitHub ↗
(c *cli.Context)

Source from the content-addressed store, hash-verified

53}
54
55func exportAction(c *cli.Context) error {
56 ctx := c.Context
57 var out io.Writer
58
59 // Setup the output file.
60 args := c.Args()
61 switch args.Len() {
62 case 0:
63 out = os.Stdout
64 case 1:
65 f, err := os.Create(args.First())
66 if err != nil {
67 return err
68 }
69 defer f.Close()
70 out = f
71 switch {
72 case c.IsSet("zstd") || c.IsSet("gzip"):
73 break
74 case strings.HasSuffix(args.First(), ".zst"):
75 c.Set("zstd", "true")
76 case strings.HasSuffix(args.First(), ".gz"):
77 c.Set("gzip", "true")
78 }
79 default:
80 return errors.New("too many arguments (wanted at most one)")
81 }
82 switch {
83 case c.Bool("zstd"):
84 enc, err := zstd.NewWriter(out)
85 if err != nil {
86 return err
87 }
88 defer func() {
89 if err := enc.Close(); err != nil {
90 fmt.Fprintln(os.Stderr, err)
91 }
92 }()
93 out = enc
94 case c.Bool("gzip"):
95 enc := gzip.NewWriter(out)
96 defer func() {
97 if err := enc.Close(); err != nil {
98 fmt.Fprintln(os.Stderr, err)
99 }
100 }()
101 out = enc
102 }
103
104 // Read and process the config file.
105 cfg, err := loadConfig(c.String("config"))
106 if err != nil {
107 return err
108 }
109 cfgs := make(map[string]driver.ConfigUnmarshaler, len(cfg.Updaters.Config))
110 for name, node := range cfg.Updaters.Config {
111 node := node
112 cfgs[name] = func(v interface{}) error {

Callers

nothing calls this directly

Calls 8

NewClientFunction · 0.92
RateLimiterFunction · 0.92
loadConfigFunction · 0.85
CloseMethod · 0.65
SetMethod · 0.45
StringMethod · 0.45
RunMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected