Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(334)

Unified Diff: common/flag/stringsetflag/stringsetflag.go

Issue 1622553005: Remove log filtering and add stringsetflag. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@master
Patch Set: error on empty Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « appengine/cmd/milo/Makefile ('k') | common/flag/stringsetflag/stringsetflag_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: common/flag/stringsetflag/stringsetflag.go
diff --git a/common/flag/stringsetflag/stringsetflag.go b/common/flag/stringsetflag/stringsetflag.go
new file mode 100644
index 0000000000000000000000000000000000000000..bec866a2dcd12632651be197923a1510ed6256d7
--- /dev/null
+++ b/common/flag/stringsetflag/stringsetflag.go
@@ -0,0 +1,52 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Package stringsetflag provides a flag.Value implementation which resolves
+// multiple args into a stringset.
+package stringsetflag
+
+import (
+ "flag"
+ "fmt"
+ "sort"
+ "strings"
+
+ "github.com/luci/luci-go/common/stringset"
+)
+
+// Flag is a flag.Value implementation which represents an unordered set of
+// strings.
+//
+// For example, this allows you to construct a flag that would behave like:
+// -myflag Foo
+// -myflag Bar
+// -myflag Bar
+//
+// And then myflag.Data.Has("Bar") would be true.
+type Flag struct{ Data stringset.Set }
+
+var _ flag.Value = (*Flag)(nil)
+
+func (f Flag) String() string {
+ if f.Data == nil {
+ return ""
+ }
+ slc := f.Data.ToSlice()
+ sort.Strings(slc)
+ return strings.Join(slc, ",")
+}
+
+// Set implements flag.Value's Set function.
+func (f *Flag) Set(val string) error {
+ if val == "" {
+ return fmt.Errorf("must have an argument value")
+ }
+
+ if f.Data == nil {
+ f.Data = stringset.NewFromSlice(val)
+ } else {
+ f.Data.Add(val)
+ }
+ return nil
+}
« no previous file with comments | « appengine/cmd/milo/Makefile ('k') | common/flag/stringsetflag/stringsetflag_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698