Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
gobwas committed Sep 30, 2020
1 parent 35e0775 commit b4384af
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ func main() {
}
```

However, `flagutil` provides ability to define so called flag subsets:
## Subsets

`flagutil` provides ability to define so called flag subsets:

```go
package main
Expand Down Expand Up @@ -176,6 +178,35 @@ program as follows:
$ app --database.endpoint 4055
```

## Allowing name collisions

It's rare, but still possible, when you want to receive single flag value from
multiple places in code. To avoid panics with "flag redefined" reason you can
(if you _really_ need to) _merge_ two flag values into single by using
`flagutil.Merge()` function:

```go
var (
s0 string
s1 string
)
flag.StringVar(&s0,
"foo", "default",
"foo flag usage",
)
flagutil.Merge(flag.CommandLine, func(safe *flag.FlagSet) {
safe.StringVar(&s1,
"foo", "",
"foo flag another usage", // This usage will be joined with previous.
)
})

// After parsing, s0 and s1 will be filled with single `-foo` flag value.
// If value is not provided, both s0 and s1 will have its default values (which
// may be _different_).
```


# Conventions and limitations

Any structure from parsed configuration is converted into a pairs of a flat key
Expand Down

0 comments on commit b4384af

Please sign in to comment.