Skip to content

Commit 61b6f3c

Browse files
authored
Merge pull request #1727 from presztak/simplify_shorthand_filter
Simplify `evaluateShorthandFilter` by reducing nesting levels
2 parents 527996f + 3197770 commit 61b6f3c

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

cmd/incus/list.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -250,22 +250,23 @@ func (c *cmdList) evaluateShorthandFilter(key string, value string, inst *api.In
250250
const shorthandValueDelimiter = ","
251251
shorthandFilterFunction, isShorthandFilter := c.shorthandFilters[strings.ToLower(key)]
252252

253-
if isShorthandFilter {
254-
if strings.Contains(value, shorthandValueDelimiter) {
255-
matched := false
256-
for _, curValue := range strings.Split(value, shorthandValueDelimiter) {
257-
if shorthandFilterFunction(inst, state, curValue) {
258-
matched = true
259-
}
260-
}
261-
262-
return matched
263-
}
253+
if !isShorthandFilter {
254+
return false
255+
}
264256

257+
if !strings.Contains(value, shorthandValueDelimiter) {
265258
return shorthandFilterFunction(inst, state, value)
266259
}
267260

268-
return false
261+
matched := false
262+
for _, curValue := range strings.Split(value, shorthandValueDelimiter) {
263+
if shorthandFilterFunction(inst, state, curValue) {
264+
matched = true
265+
}
266+
}
267+
268+
return matched
269+
269270
}
270271

271272
func (c *cmdList) listInstances(d incus.InstanceServer, instances []api.Instance, filters []string, columns []column) error {

0 commit comments

Comments
 (0)