Adds seperate options for filter. See https://github.com/alexflint/go-arg/issues/155 and should fix bug in #293 (#1200)

This commit is contained in:
Amir Raminfar
2021-05-05 11:50:02 -07:00
committed by GitHub
parent ae1cbecfc4
commit 8238620360
2 changed files with 29 additions and 18 deletions

View File

@@ -40,16 +40,13 @@ type Client interface {
ContainerStats(context.Context, string, chan<- ContainerStat) error
}
// NewClient creates a new instance of Client
func NewClient() Client {
return NewClientWithFilters(map[string]string{})
}
// NewClientWithFilters creates a new instance of Client with docker filters
func NewClientWithFilters(f map[string]string) Client {
func NewClientWithFilters(f map[string][]string) Client {
filterArgs := filters.NewArgs()
for k, v := range f {
filterArgs.Add(k, v)
for key, values := range f {
for _, value := range values {
filterArgs.Add(key, value)
}
}
log.Debugf("filterArgs = %v", filterArgs)

34
main.go
View File

@@ -8,6 +8,7 @@ import (
_ "net/http/pprof"
"os"
"os/signal"
"strings"
"syscall"
"time"
@@ -24,15 +25,16 @@ var (
)
type args struct {
Addr string `arg:"env:DOZZLE_ADDR" default:":8080"`
Base string `arg:"env:DOZZLE_BASE" default:"/"`
Level string `arg:"env:DOZZLE_LEVEL" default:"info"`
TailSize int `arg:"env:DOZZLE_TAILSIZE" default:"300"`
Filter map[string]string `arg:"env:DOZZLE_FILTER"`
Key string `arg:"env:DOZZLE_KEY"`
Username string `arg:"env:DOZZLE_USERNAME"`
Password string `arg:"env:DOZZLE_PASSWORD"`
NoAnalytics bool `arg:"--no-analytics,env:DOZZLE_NO_ANALYTICS"`
Addr string `arg:"env:DOZZLE_ADDR" default:":8080"`
Base string `arg:"env:DOZZLE_BASE" default:"/"`
Level string `arg:"env:DOZZLE_LEVEL" default:"info"`
TailSize int `arg:"env:DOZZLE_TAILSIZE" default:"300"`
Key string `arg:"env:DOZZLE_KEY"`
Username string `arg:"env:DOZZLE_USERNAME"`
Password string `arg:"env:DOZZLE_PASSWORD"`
NoAnalytics bool `arg:"--no-analytics,env:DOZZLE_NO_ANALYTICS"`
FilterStrings []string `arg:"env:DOZZLE_FILTER,--filter,separate"`
Filter map[string][]string `arg:"-"`
}
func (args) Version() string {
@@ -44,7 +46,19 @@ var content embed.FS
func main() {
var args args
arg.MustParse(&args)
parser := arg.MustParse(&args)
args.Filter = make(map[string][]string)
for _, filter := range args.FilterStrings {
pos := strings.Index(filter, "=")
if pos == -1 {
parser.Fail("each filter should be of the form key=value")
}
key := filter[:pos]
val := filter[pos+1:]
args.Filter[key] = append(args.Filter[key], val)
}
level, _ := log.ParseLevel(args.Level)
log.SetLevel(level)