Documentation ¶
Overview ¶
Package goflagbuilder constructs command line flags and a file parser to manipulate a given structure. It uses reflection to traverse a potentially hierarchical object of structs and maps and install handlers in Go's standard flag package. Constructed parsers scan given documents line by line and apply any key/value pairs found.
Constructed flags have the form Foo=..., Bar=...,Obj.Field=... and so on. Maps and exposed fields of structs with primitive types are consumed, so in this case Foo and Bar might be map keys or public struct fields to a primitive. Nested maps and structs are followed, producing dot-notation hierarchical keys such as Obj.Field.
Primitive types understood by goflagbuilder include bool, float64, int64, int, string, uint64, and uint.
Primitive fields in the given object and sub-objects must be settable. In general this means structs should be passed in as pointers. Maps may also be set directly.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Strict = false
Functions ¶
This section is empty.
Types ¶
type FlagSet ¶
FlagSet is the interface for handling flags identified by GoFlagBuilder. FlagSet objects from Go's standard flag package meet this specification and are the intended primary target, in addition to an internal facade in front of the flag package's top level function, and the GoFlagBuilder Parser.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser objects are constructed to manipulate specific objects via reading key/value pairs from a document source.
func From ¶
From populates the top-level default flags with hierarchical fields from the given object. It simply calls Into() with configuration on a facade of the top-level flag package functions, and returns the resultant Parser or error.
func Into ¶
Into populates the given flag set with hierarchical fields from the given object. It returns a Parser that may be used to read those same flags from a configuration file.
func (*Parser) Parse ¶
Parse reads the given Reader line by line and parses key/value pairs to manipulate the associated object.
func (*Parser) ParseFile ¶
ParseFile reads the file indicated by filename line by line and parses key/value pairs to manipulate the associated object. It is identical to calling Parse on a File opened from filename. No error is returned if the file does not exist, on the theory that it is equivalent to a blank file which would set no flags.