mirror of
https://github.com/moby/buildkit.git
synced 2026-11-06 05:16:45 +00:00
client: generalize the filter passing
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
1 parent
0ba24f2a90
commit
70e0b64482
6 files changed
+39
-21
No files matched your search
+4
-8
@@ -25,7 +25,7 @@ type UsageInfo struct {
|
||||
func (c *Client) DiskUsage(ctx context.Context, opts ...DiskUsageOption) ([]*UsageInfo, error) {
|
||||
info := &DiskUsageInfo{}
|
||||
for _, o := range opts {
|
||||
o(info)
|
||||
o.SetDiskUsageOption(info)
|
||||
}
|
||||
|
||||
req := &controlapi.DiskUsageRequest{Filter: info.Filter}
|
||||
@@ -60,14 +60,10 @@ func (c *Client) DiskUsage(ctx context.Context, opts ...DiskUsageOption) ([]*Usa
|
||||
return du, nil
|
||||
}
|
||||
|
||||
type DiskUsageOption func(*DiskUsageInfo)
|
||||
type DiskUsageOption interface {
|
||||
SetDiskUsageOption(*DiskUsageInfo)
|
||||
}
|
||||
|
||||
type DiskUsageInfo struct {
|
||||
Filter []string
|
||||
}
|
||||
|
||||
func WithFilter(f []string) DiskUsageOption {
|
||||
return func(di *DiskUsageInfo) {
|
||||
di.Filter = f
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package client
|
||||
|
||||
func WithFilter(f []string) Filter {
|
||||
return Filter(f)
|
||||
}
|
||||
|
||||
type Filter []string
|
||||
|
||||
func (f Filter) SetDiskUsageOption(di *DiskUsageInfo) {
|
||||
di.Filter = f
|
||||
}
|
||||
|
||||
func (f Filter) SetPruneOption(pi *PruneInfo) {
|
||||
pi.Filter = f
|
||||
}
|
||||
|
||||
func (f Filter) SetListWorkersOption(lwi *ListWorkersInfo) {
|
||||
lwi.Filter = f
|
||||
}
|
||||
+6
-3
@@ -11,10 +11,10 @@ import (
|
||||
func (c *Client) Prune(ctx context.Context, ch chan UsageInfo, opts ...PruneOption) error {
|
||||
info := &PruneInfo{}
|
||||
for _, o := range opts {
|
||||
o(info)
|
||||
o.SetPruneOption(info)
|
||||
}
|
||||
|
||||
req := &controlapi.PruneRequest{}
|
||||
req := &controlapi.PruneRequest{Filter: info.Filter}
|
||||
cl, err := c.controlClient().Prune(ctx, req)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to call prune")
|
||||
@@ -44,7 +44,10 @@ func (c *Client) Prune(ctx context.Context, ch chan UsageInfo, opts ...PruneOpti
|
||||
}
|
||||
}
|
||||
|
||||
type PruneOption func(*PruneInfo)
|
||||
type PruneOption interface {
|
||||
SetPruneOption(*PruneInfo)
|
||||
}
|
||||
|
||||
type PruneInfo struct {
|
||||
Filter []string
|
||||
}
|
||||
+4
-8
@@ -18,7 +18,7 @@ type WorkerInfo struct {
|
||||
func (c *Client) ListWorkers(ctx context.Context, opts ...ListWorkersOption) ([]*WorkerInfo, error) {
|
||||
info := &ListWorkersInfo{}
|
||||
for _, o := range opts {
|
||||
o(info)
|
||||
o.SetListWorkersOption(info)
|
||||
}
|
||||
|
||||
req := &controlapi.ListWorkersRequest{Filter: info.Filter}
|
||||
@@ -40,14 +40,10 @@ func (c *Client) ListWorkers(ctx context.Context, opts ...ListWorkersOption) ([]
|
||||
return wi, nil
|
||||
}
|
||||
|
||||
type ListWorkersOption func(*ListWorkersInfo)
|
||||
type ListWorkersOption interface {
|
||||
SetListWorkersOption(*ListWorkersInfo)
|
||||
}
|
||||
|
||||
type ListWorkersInfo struct {
|
||||
Filter []string
|
||||
}
|
||||
|
||||
func WithWorkerFilter(f []string) ListWorkersOption {
|
||||
return func(wi *ListWorkersInfo) {
|
||||
wi.Filter = f
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,7 @@ func listWorkers(clicontext *cli.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
workers, err := c.ListWorkers(commandContext(clicontext), client.WithWorkerFilter(clicontext.StringSlice("filter")))
|
||||
workers, err := c.ListWorkers(commandContext(clicontext), client.WithFilter(clicontext.StringSlice("filter")))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -15,6 +15,10 @@ var pruneCommand = cli.Command{
|
||||
Usage: "clean up build cache",
|
||||
Action: prune,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringSliceFlag{
|
||||
Name: "filter, f",
|
||||
Usage: "Filter records",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "verbose, v",
|
||||
Usage: "Verbose output",
|
||||
@@ -52,7 +56,7 @@ func prune(clicontext *cli.Context) error {
|
||||
}
|
||||
}()
|
||||
|
||||
err = c.Prune(commandContext(clicontext), ch)
|
||||
err = c.Prune(commandContext(clicontext), ch, client.WithFilter(clicontext.StringSlice("filter")))
|
||||
close(ch)
|
||||
<-printed
|
||||
if err != nil {
|
||||
|
||||
Reference in new issue
Block a user