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

Package stringmapflag

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 stringmapflag provides a flag.Value that, when parsed, augments a map[string]string with the supplied parameter. The parameter is expressed as a key[=value] option.

Example

Assuming the flag option, "opt", is bound to a stringmapflag.Value, and the following arguments are parsed:

-opt foo=bar
-opt baz

The resulting map would be equivalent to: map[string]string {"foo": "bar", "baz": ""}

Example

Code:

v := new(Value)
fs := flag.NewFlagSet("test", flag.ContinueOnError)
fs.Var(v, "option", "Appends a key[=value] option.")

// Simulate user input.
if err := fs.Parse([]string{
	"-option", "foo=bar",
	"-option", "baz",
}); err != nil {
	panic(err)
}

m, _ := json.MarshalIndent(v, "", "  ")
fmt.Println("Parsed options:", string(m))
Parsed options: {
  "baz": "",
  "foo": "bar"
}

Index

Examples

type Value

type Value map[string]string

Value is a flag.Value implementation that stores arbitrary "key[=value]" command-line flags as a string map.

func (*Value) Set

func (v *Value) Set(key string) error

Set implements flag.Value.

func (*Value) String

func (v *Value) 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