Skip to content

Support '!=' operator in filters and record its usage #6035

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions cli/command/system/prune.go
Original file line number Diff line number Diff line change
@@ -144,9 +144,14 @@ func confirmationMessage(dockerCli command.Cli, options pruneOptions) string {
if pruneFilters.Len() > 0 {
// TODO remove fixed list of filters, and print all filters instead,
// because the list of filters that is supported by the engine may evolve over time.

for _, name := range []string{"label", "label!", "until"} {
for _, v := range pruneFilters.Get(name) {
filters = append(filters, name+"="+v)
for v, isEqualOp := range options.filter.Value().GetPair(name) {
op := "="
if !isEqualOp {
op = "!="
}
filters = append(filters, name+op+v)
}
}
sort.Slice(filters, func(i, j int) bool {
18 changes: 14 additions & 4 deletions opts/opts.go
Original file line number Diff line number Diff line change
@@ -345,15 +345,25 @@ func (o *FilterOpt) Set(value string) error {
if value == "" {
return nil
}
if !strings.Contains(value, "=") {
return errors.New("bad format of filter (expected name=value)")

var isEqualOp bool
// isEqualOp determines the comparison type:
// true => use ="
// false => use "!="
var sep string
if strings.Contains(value, "!=") {
isEqualOp, sep = false, "!="
} else if strings.Contains(value, "=") {
isEqualOp, sep = true, "="
} else {
return errors.New("bad format of filter (expected name=value or name!=value)")
}
name, val, _ := strings.Cut(value, "=")
name, val, _ := strings.Cut(value, sep)

// TODO(thaJeztah): these options should not be case-insensitive.
name = strings.ToLower(strings.TrimSpace(name))
val = strings.TrimSpace(val)
o.filter.Add(name, val)
o.filter.Add(name, val, isEqualOp)
return nil
}

17 changes: 14 additions & 3 deletions vendor/github.com/docker/docker/api/types/filters/parse.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Oops, something went wrong.