luci: go.chromium.org/luci/common/flag/stringsetflag Index | Examples | Files

package stringsetflag

import "go.chromium.org/luci/common/flag/stringsetflag"

Package stringsetflag provides a flag.Value implementation which resolves multiple args into a stringset.

Example demonstrates how to use stringlistflag.

Code:

sset := Flag{}

fs := flag.NewFlagSet("test", flag.ContinueOnError)
fs.Var(&sset, "color", "favorite color, may be repeated.")
fs.SetOutput(os.Stdout)

fs.PrintDefaults()

// Flag parsing.
fs.Parse([]string{"-color", "Violet", "-color", "Red", "-color", "Violet"})
fmt.Printf("Value is: %s\n", sset)

fmt.Println("Likes Blue:", sset.Data.Has("Blue"))
fmt.Println("Likes Red:", sset.Data.Has("Red"))

Output:

-color value
    	favorite color, may be repeated.
Value is: Red,Violet
Likes Blue: false
Likes Red: true

Index

Examples

Package Files

stringsetflag.go

type Flag Uses

type Flag struct{ Data stringset.Set }

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.

func (*Flag) Set Uses

func (f *Flag) Set(val string) error

Set implements flag.Value's Set function.

func (Flag) String Uses

func (f Flag) String() string

Package stringsetflag imports 5 packages (graph). Updated 2018-12-14. Refresh now. Tools for package owners.