move filter into own function

This commit is contained in:
Bradley Cicenas
2017-02-20 10:23:17 +11:00
parent 8f8474e468
commit 549d4892eb
2 changed files with 22 additions and 13 deletions

View File

@@ -1,8 +1,6 @@
package main
import (
"fmt"
"regexp"
"sort"
"strings"
@@ -100,18 +98,7 @@ func (cm *ContainerMap) Del(ids ...string) {
func (cm *ContainerMap) All() []*Container {
var containers Containers
filter := config.GetVal("filterStr")
re := regexp.MustCompile(fmt.Sprintf(".*%s", filter))
for _, c := range cm.containers {
// Apply name filter
if re.FindAllString(c.name, 1) == nil {
continue
}
// Apply state filter
if !config.GetSwitchVal("allContainers") && c.state != "running" {
continue
}
containers = append(containers, c)
}