...

Source file src/github.com/magiconair/properties/integrate.go

Documentation: github.com/magiconair/properties

     1  // Copyright 2013-2022 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  //
    14  //	flag.Parse()
    15  //	p.MustFlag(flag.CommandLine)
    16  func (p *Properties) MustFlag(dst *flag.FlagSet) {
    17  	m := make(map[string]*flag.Flag)
    18  	dst.VisitAll(func(f *flag.Flag) {
    19  		m[f.Name] = f
    20  	})
    21  	dst.Visit(func(f *flag.Flag) {
    22  		delete(m, f.Name) // overridden
    23  	})
    24  
    25  	for name, f := range m {
    26  		v, ok := p.Get(name)
    27  		if !ok {
    28  			continue
    29  		}
    30  
    31  		if err := f.Value.Set(v); err != nil {
    32  			ErrorHandler(err)
    33  		}
    34  	}
    35  }
    36  

View as plain text