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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « appengine/cmd/milo/Makefile ('k') | common/flag/stringsetflag/stringsetflag_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Package stringsetflag provides a flag.Value implementation which resolves
6 // multiple args into a stringset.
7 package stringsetflag
8
9 import (
10 "flag"
11 "fmt"
12 "sort"
13 "strings"
14
15 "github.com/luci/luci-go/common/stringset"
16 )
17
18 // Flag is a flag.Value implementation which represents an unordered set of
19 // strings.
20 //
21 // For example, this allows you to construct a flag that would behave like:
22 // -myflag Foo
23 // -myflag Bar
24 // -myflag Bar
25 //
26 // And then myflag.Data.Has("Bar") would be true.
27 type Flag struct{ Data stringset.Set }
28
29 var _ flag.Value = (*Flag)(nil)
30
31 func (f Flag) String() string {
32 if f.Data == nil {
33 return ""
34 }
35 slc := f.Data.ToSlice()
36 sort.Strings(slc)
37 return strings.Join(slc, ",")
38 }
39
40 // Set implements flag.Value's Set function.
41 func (f *Flag) Set(val string) error {
42 if val == "" {
43 return fmt.Errorf("must have an argument value")
44 }
45
46 if f.Data == nil {
47 f.Data = stringset.NewFromSlice(val)
48 } else {
49 f.Data.Add(val)
50 }
51 return nil
52 }
OLDNEW
« 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