Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| ... | ... |
@@ -5,7 +5,6 @@ package filters // import "github.com/docker/docker/api/types/filters" |
| 5 | 5 |
|
| 6 | 6 |
import ( |
| 7 | 7 |
"encoding/json" |
| 8 |
- "errors" |
|
| 9 | 8 |
"regexp" |
| 10 | 9 |
"strings" |
| 11 | 10 |
|
| ... | ... |
@@ -37,41 +36,6 @@ func NewArgs(initialArgs ...KeyValuePair) Args {
|
| 37 | 37 |
return args |
| 38 | 38 |
} |
| 39 | 39 |
|
| 40 |
-// ParseFlag parses a key=value string and adds it to an Args. |
|
| 41 |
-// |
|
| 42 |
-// Deprecated: Use Args.Add() |
|
| 43 |
-func ParseFlag(arg string, prev Args) (Args, error) {
|
|
| 44 |
- filters := prev |
|
| 45 |
- if len(arg) == 0 {
|
|
| 46 |
- return filters, nil |
|
| 47 |
- } |
|
| 48 |
- |
|
| 49 |
- if !strings.Contains(arg, "=") {
|
|
| 50 |
- return filters, ErrBadFormat |
|
| 51 |
- } |
|
| 52 |
- |
|
| 53 |
- f := strings.SplitN(arg, "=", 2) |
|
| 54 |
- |
|
| 55 |
- name := strings.ToLower(strings.TrimSpace(f[0])) |
|
| 56 |
- value := strings.TrimSpace(f[1]) |
|
| 57 |
- |
|
| 58 |
- filters.Add(name, value) |
|
| 59 |
- |
|
| 60 |
- return filters, nil |
|
| 61 |
-} |
|
| 62 |
- |
|
| 63 |
-// ErrBadFormat is an error returned when a filter is not in the form key=value |
|
| 64 |
-// |
|
| 65 |
-// Deprecated: this error will be removed in a future version |
|
| 66 |
-var ErrBadFormat = errors.New("bad format of filter (expected name=value)")
|
|
| 67 |
- |
|
| 68 |
-// ToParam encodes the Args as args JSON encoded string |
|
| 69 |
-// |
|
| 70 |
-// Deprecated: use ToJSON |
|
| 71 |
-func ToParam(a Args) (string, error) {
|
|
| 72 |
- return ToJSON(a) |
|
| 73 |
-} |
|
| 74 |
- |
|
| 75 | 40 |
// MarshalJSON returns a JSON byte representation of the Args |
| 76 | 41 |
func (args Args) MarshalJSON() ([]byte, error) {
|
| 77 | 42 |
if len(args.fields) == 0 {
|
| ... | ... |
@@ -107,13 +71,6 @@ func ToParamWithVersion(version string, a Args) (string, error) {
|
| 107 | 107 |
return ToJSON(a) |
| 108 | 108 |
} |
| 109 | 109 |
|
| 110 |
-// FromParam decodes a JSON encoded string into Args |
|
| 111 |
-// |
|
| 112 |
-// Deprecated: use FromJSON |
|
| 113 |
-func FromParam(p string) (Args, error) {
|
|
| 114 |
- return FromJSON(p) |
|
| 115 |
-} |
|
| 116 |
- |
|
| 117 | 110 |
// FromJSON decodes a JSON encoded string into Args |
| 118 | 111 |
func FromJSON(p string) (Args, error) {
|
| 119 | 112 |
args := NewArgs() |
| ... | ... |
@@ -275,14 +232,6 @@ func (args Args) FuzzyMatch(key, source string) bool {
|
| 275 | 275 |
return false |
| 276 | 276 |
} |
| 277 | 277 |
|
| 278 |
-// Include returns true if the key exists in the mapping |
|
| 279 |
-// |
|
| 280 |
-// Deprecated: use Contains |
|
| 281 |
-func (args Args) Include(field string) bool {
|
|
| 282 |
- _, ok := args.fields[field] |
|
| 283 |
- return ok |
|
| 284 |
-} |
|
| 285 |
- |
|
| 286 | 278 |
// Contains returns true if the key exists in the mapping |
| 287 | 279 |
func (args Args) Contains(field string) bool {
|
| 288 | 280 |
_, ok := args.fields[field] |
| ... | ... |
@@ -8,40 +8,6 @@ import ( |
| 8 | 8 |
is "gotest.tools/assert/cmp" |
| 9 | 9 |
) |
| 10 | 10 |
|
| 11 |
-func TestParseArgs(t *testing.T) {
|
|
| 12 |
- // equivalent of `docker ps -f 'created=today' -f 'image.name=ubuntu*' -f 'image.name=*untu'` |
|
| 13 |
- flagArgs := []string{
|
|
| 14 |
- "created=today", |
|
| 15 |
- "image.name=ubuntu*", |
|
| 16 |
- "image.name=*untu", |
|
| 17 |
- } |
|
| 18 |
- var ( |
|
| 19 |
- args = NewArgs() |
|
| 20 |
- err error |
|
| 21 |
- ) |
|
| 22 |
- |
|
| 23 |
- for i := range flagArgs {
|
|
| 24 |
- args, err = ParseFlag(flagArgs[i], args) |
|
| 25 |
- assert.NilError(t, err) |
|
| 26 |
- } |
|
| 27 |
- assert.Check(t, is.Len(args.Get("created"), 1))
|
|
| 28 |
- assert.Check(t, is.Len(args.Get("image.name"), 2))
|
|
| 29 |
-} |
|
| 30 |
- |
|
| 31 |
-func TestParseArgsEdgeCase(t *testing.T) {
|
|
| 32 |
- var args Args |
|
| 33 |
- args, err := ParseFlag("", args)
|
|
| 34 |
- if err != nil {
|
|
| 35 |
- t.Fatal(err) |
|
| 36 |
- } |
|
| 37 |
- if args.Len() != 0 {
|
|
| 38 |
- t.Fatalf("Expected an empty Args (map), got %v", args)
|
|
| 39 |
- } |
|
| 40 |
- if args, err = ParseFlag("anything", args); err == nil || err != ErrBadFormat {
|
|
| 41 |
- t.Fatalf("Expected ErrBadFormat, got %v", err)
|
|
| 42 |
- } |
|
| 43 |
-} |
|
| 44 |
- |
|
| 45 | 11 |
func TestToJSON(t *testing.T) {
|
| 46 | 12 |
fields := map[string]map[string]bool{
|
| 47 | 13 |
"created": {"today": true},
|
| ... | ... |
@@ -347,17 +313,6 @@ func TestContains(t *testing.T) {
|
| 347 | 347 |
} |
| 348 | 348 |
} |
| 349 | 349 |
|
| 350 |
-func TestInclude(t *testing.T) {
|
|
| 351 |
- f := NewArgs() |
|
| 352 |
- if f.Include("status") {
|
|
| 353 |
- t.Fatal("Expected to not include a status key, got true")
|
|
| 354 |
- } |
|
| 355 |
- f.Add("status", "running")
|
|
| 356 |
- if !f.Include("status") {
|
|
| 357 |
- t.Fatal("Expected to include a status key, got false")
|
|
| 358 |
- } |
|
| 359 |
-} |
|
| 360 |
- |
|
| 361 | 350 |
func TestValidate(t *testing.T) {
|
| 362 | 351 |
f := NewArgs() |
| 363 | 352 |
f.Add("status", "running")
|
| ... | ... |
@@ -590,7 +590,7 @@ func toBuildkitPruneInfo(opts types.BuildCachePruneOptions) (client.PruneInfo, e |
| 590 | 590 |
|
| 591 | 591 |
bkFilter := make([]string, 0, opts.Filters.Len()) |
| 592 | 592 |
for cacheField := range cacheFields {
|
| 593 |
- if opts.Filters.Include(cacheField) {
|
|
| 593 |
+ if opts.Filters.Contains(cacheField) {
|
|
| 594 | 594 |
values := opts.Filters.Get(cacheField) |
| 595 | 595 |
switch len(values) {
|
| 596 | 596 |
case 0: |