Debian Codegraph @

vendor/github.com/magiconair/properties/integrate.go

raw
1 // Copyright 2018 Frank Schroeder. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package properties
6
7 import "flag"
8
9 // MustFlag sets flags that are skipped by dst.Parse when p contains
10 // the respective key for flag.Flag.Name.
11 //
12 // It's use is recommended with command line arguments as in:
13 // flag.Parse()
14 // p.MustFlag(flag.CommandLine)
15 func (p *Properties) MustFlag(dst *flag.FlagSet) {
16 m := make(map[string]*flag.Flag)
17 dst.VisitAll(func(f *flag.Flag) {
18 m[f.Name] = f
19 })
20 dst.Visit(func(f *flag.Flag) {
21 delete(m, f.Name) // overridden
22 })
23
24 for name, f := range m {
25 v, ok := p.Get(name)
26 if !ok {
27 continue
28 }
29
30 if err := f.Value.Set(v); err != nil {
31 ErrorHandler(err)
32 }
33 }
34 }