Documentation
¶
Index ¶
- Variables
- func Help(cmdline *flag.FlagSet, progname string, descriptors []*component.Descriptor)
- func LookupRequired(fs *flag.FlagSet, descriptors []*component.Descriptor) (missing []flag.Flag)
- func ParseFlags(cmdline *flag.FlagSet, descriptors []*component.Descriptor, multi bool) ([]*component.Descriptor, error)
- func RequiredFlag(fs *flag.FlagSet, name string, boundComponent *component.Descriptor)
- type ComponentSet
Constants ¶
This section is empty.
Variables ¶
var ErrNoComponents = errors.New("no enabled components")
ErrNoComponents is returned by ParseFlags when no components are enabled.
Functions ¶
func Help ¶
func Help(cmdline *flag.FlagSet, progname string, descriptors []*component.Descriptor)
Help implements the help subcommand for a loader main program. The optional args specify the services to describe. Help calls log.Fatal if no such service exists.
func LookupRequired ¶
LookupRequired returns the flags from the given flag-set that were required prior (by RequiredFlag) but have not been set by the command-line. The returned list is sorted lexicographically by the flag's name.
The lookup takes into account the provided set of component descriptors such that only some required flags are ignored if their bound components are not provided.
func ParseFlags ¶
func ParseFlags(cmdline *flag.FlagSet, descriptors []*component.Descriptor, multi bool) ([]*component.Descriptor, error)
ParseFlags defines a flag (on the provides flag-set) for each of the component's flags; including, in 'multi' mode, a flag to enable the component. Flag values are parsed from the command line and environment variables.
A 'help' command is added to the flag-set, which prints usage information for all components, and then exits. Otherwise, the parsed values are propagated into each component's flags and the enabled components are returned.
func RequiredFlag ¶
func RequiredFlag(fs *flag.FlagSet, name string, boundComponent *component.Descriptor)
RequiredFlag wraps the value of the named flag such that its help message shows "default required" and indicates to ParseFlags it should fail unless the flag has been set explicitly (ignoring its predefined default value).
Types ¶
type ComponentSet ¶
type ComponentSet map[*component.Descriptor]*triState
A ComponentSet tracks which of its registered components are enabled by command-line flags.
func (ComponentSet) Enabled ¶
func (cs ComponentSet) Enabled() []*component.Descriptor
Enabled returns the set of components that the given flags enable, in lexical order by component name.
If any "-NAME" flag is true, load only those components; otherwise, if any "-NAME" flag is false, load all but those components.
func (ComponentSet) Register ¶
func (cs ComponentSet) Register(fs *flag.FlagSet, d *component.Descriptor)
Register the given component as a tri-state flag on the given flag-set. The flag will be named after the component's name (see triStateFlag).
If the component is already registered, this is a no-op.