Back to godoc.org
github.com/luci/luci-go / common / flag / stringlistflag

Package stringlistflag

v0.0.0-...-d4769a7
Latest Go to latest

The latest major version is .

Published: Aug 1, 2020 | License: Apache-2.0 | Module: github.com/luci/luci-go

Overview

Package stringlistflag provides a flag.Value implementation which resolves multiple args into a []string.

Example

Example demonstrates how to use stringlistflag.

Code:

list := Flag{}

fs := flag.NewFlagSet("test", flag.ContinueOnError)
fs.Var(&list, "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", list)
-color value
    	favorite color, may be repeated.
Value is: Violet, Red, Violet

Index

Examples

type Flag

type Flag []string

Flag is a flag.Value implementation which represents an ordered 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 would be []string{"Foo", "Bar", "Bar"}

func (*Flag) Set

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

Set implements flag.Value's Set function.

func (Flag) String

func (f Flag) String() string

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier