Skip to content

Commit

Permalink
Use bool var to indicate negation instead of splitting operation again
Browse files Browse the repository at this point in the history
Signed-off-by: rvandernoort <s.r.vandernoort@student.tudelft.nl>
  • Loading branch information
rvandernoort committed Mar 22, 2022
1 parent 44573af commit 473ad66
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions libimage/filters.go
Expand Up @@ -95,8 +95,11 @@ func (r *Runtime) compileImageFilters(ctx context.Context, options *ListImagesOp
for _, f := range options.Filters {
var key, value string
var filter filterFunc
negate := false
split := strings.SplitN(f, "!=", 2)
if len(split) != 2 {
if len(split) == 2 {
negate = true
} else {
split = strings.SplitN(f, "=", 2)
if len(split) != 2 {
return nil, errors.Errorf("invalid image filter %q: must be in the format %q", f, "filter=value or filter!=value")
Expand Down Expand Up @@ -185,7 +188,7 @@ func (r *Runtime) compileImageFilters(ctx context.Context, options *ListImagesOp
default:
return nil, errors.Errorf("unsupported image filter %q", key)
}
if len(strings.SplitN(f, "!=", 2)) == 2 {
if negate {
filter = negateFilter(filter)
}
filters[key] = append(filters[key], filter)
Expand Down

0 comments on commit 473ad66

Please sign in to comment.