Back to

Package plugin

Latest Go to latest
Published: Jun 26, 2020 | License: MIT | Module:


Package Files

func AddFlags

func AddFlags(groupName string, longDescription string, data interface{})

AddFlags should be used by embedded modules to inject custom flags into `yab`. It adds a set of custom flags with heading `groupName`.

The `data` argument should be a pointer to a struct with one field for each command line flag. Each field should use tags like `description` to inform the parser of metadata about the flag. (tags are the same as supported by

type foo struct {
	Bar string `long:"bar" description:"Sets the 'bar' value."`

AddFlags("Foo Options", "", &foo{})

This would inject a custom flag group that looks like:

Foo Options
	--bar	Sets the 'bar' value.

In order to retrieve the mutated results of the set flag, users of AddFlags() should retain a reference to the `data` object and check its values after parsing is complete.

func AddToParser

func AddToParser(p Parser) error

AddToParser adds all registered flags to the passed Parser. This operation is not atomic, flags are applied on a best-effort basis (not "all-or-nothing") Returns a slice of errors indicating which flags groups failed to be added.

type Parser

type Parser interface {
	// AddFlagGroup adds an additional flag group to process during parsing.
	AddFlagGroup(groupName, longDescription string, data interface{}) error

Parser is any object that can add flag groups to itself before performing its parse.

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier