mirror of https://github.com/docker/cli.git
Migrate to non-deprecated functions of `api/types/filters`
- Use `Contains` instead of `Include` - Use `ToJSON` instead of `ToParam` - Remove usage of `ParseFlag` as it is deprecated too Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
parent
a3464c0a20
commit
55edeb497a
|
@ -140,7 +140,7 @@ loop:
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateNodeFilter(ctx context.Context, client client.APIClient, filter filters.Args) error {
|
func updateNodeFilter(ctx context.Context, client client.APIClient, filter filters.Args) error {
|
||||||
if filter.Include("node") {
|
if filter.Contains("node") {
|
||||||
nodeFilters := filter.Get("node")
|
nodeFilters := filter.Get("node")
|
||||||
for _, nodeFilter := range nodeFilters {
|
for _, nodeFilter := range nodeFilters {
|
||||||
nodeReference, err := node.Reference(ctx, client, nodeFilter)
|
nodeReference, err := node.Reference(ctx, client, nodeFilter)
|
||||||
|
|
|
@ -68,7 +68,7 @@ func runBuildCachePrune(dockerCli command.Cli, _ opts.FilterOpt) (uint64, string
|
||||||
|
|
||||||
func runPrune(dockerCli command.Cli, options pruneOptions) error {
|
func runPrune(dockerCli command.Cli, options pruneOptions) error {
|
||||||
// TODO version this once "until" filter is supported for volumes
|
// TODO version this once "until" filter is supported for volumes
|
||||||
if options.pruneVolumes && options.filter.Value().Include("until") {
|
if options.pruneVolumes && options.filter.Value().Contains("until") {
|
||||||
return fmt.Errorf(`ERROR: The "until" filter is not supported with "--volumes"`)
|
return fmt.Errorf(`ERROR: The "until" filter is not supported with "--volumes"`)
|
||||||
}
|
}
|
||||||
if versions.LessThan(dockerCli.Client().ClientVersion(), "1.31") {
|
if versions.LessThan(dockerCli.Client().ClientVersion(), "1.31") {
|
||||||
|
|
|
@ -102,14 +102,14 @@ func PruneFilters(dockerCli Cli, pruneFilters filters.Args) filters.Args {
|
||||||
// CLI label filter supersede config.json.
|
// CLI label filter supersede config.json.
|
||||||
// If CLI label filter conflict with config.json,
|
// If CLI label filter conflict with config.json,
|
||||||
// skip adding label! filter in config.json.
|
// skip adding label! filter in config.json.
|
||||||
if pruneFilters.Include("label!") && pruneFilters.ExactMatch("label!", parts[1]) {
|
if pruneFilters.Contains("label!") && pruneFilters.ExactMatch("label!", parts[1]) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
} else if parts[0] == "label!" {
|
} else if parts[0] == "label!" {
|
||||||
// CLI label! filter supersede config.json.
|
// CLI label! filter supersede config.json.
|
||||||
// If CLI label! filter conflict with config.json,
|
// If CLI label! filter conflict with config.json,
|
||||||
// skip adding label filter in config.json.
|
// skip adding label filter in config.json.
|
||||||
if pruneFilters.Include("label") && pruneFilters.ExactMatch("label", parts[1]) {
|
if pruneFilters.Contains("label") && pruneFilters.ExactMatch("label", parts[1]) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
18
opts/opts.go
18
opts/opts.go
|
@ -11,6 +11,7 @@ import (
|
||||||
|
|
||||||
"github.com/docker/docker/api/types/filters"
|
"github.com/docker/docker/api/types/filters"
|
||||||
units "github.com/docker/go-units"
|
units "github.com/docker/go-units"
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -318,7 +319,7 @@ func NewFilterOpt() FilterOpt {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *FilterOpt) String() string {
|
func (o *FilterOpt) String() string {
|
||||||
repr, err := filters.ToParam(o.filter)
|
repr, err := filters.ToJSON(o.filter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "invalid filters"
|
return "invalid filters"
|
||||||
}
|
}
|
||||||
|
@ -327,9 +328,18 @@ func (o *FilterOpt) String() string {
|
||||||
|
|
||||||
// Set sets the value of the opt by parsing the command line value
|
// Set sets the value of the opt by parsing the command line value
|
||||||
func (o *FilterOpt) Set(value string) error {
|
func (o *FilterOpt) Set(value string) error {
|
||||||
var err error
|
if value == "" {
|
||||||
o.filter, err = filters.ParseFlag(value, o.filter)
|
return nil
|
||||||
return err
|
}
|
||||||
|
if !strings.Contains(value, "=") {
|
||||||
|
return errors.New("bad format of filter (expected name=value)")
|
||||||
|
}
|
||||||
|
f := strings.SplitN(value, "=", 2)
|
||||||
|
name := strings.ToLower(strings.TrimSpace(f[0]))
|
||||||
|
value = strings.TrimSpace(f[1])
|
||||||
|
|
||||||
|
o.filter.Add(name, value)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Type returns the option type
|
// Type returns the option type
|
||||||
|
|
Loading…
Reference in New Issue