easyconfig.v1: gopkg.in/hlandau/easyconfig.v1/cflag Index | Examples | Files

package cflag

import "gopkg.in/hlandau/easyconfig.v1/cflag"

Package cflag provides a flag-like means of declaring configurables.

The functions in this package which take a Registerable argument can have that argument passed as non-nil, in which case the configurable becomes a child of the configurable passed, or nil, in which case the configurable is registered at the top level.

You should call Value() to get the value of a flag configurable.

Code:

var (
    g           = cflag.NewGroup(nil, "Program Options")
    bindFlag    = cflag.String(g, "bind", ":80", "Address to bind server to (e.g. :80)")
    fooFlag     = cflag.String(g, "foo", "", "Some flag")
    barFlag     = cflag.Int(g, "bar", 42, "Some other flag")
    doStuffFlag = cflag.Bool(g, "doStuff", false, "Do stuff?")
)

adaptflag.Adapt()
flag.Parse()

fmt.Printf("Bind: %s\n", bindFlag.Value())
fmt.Printf("Foo:  %s\n", fooFlag.Value())
fmt.Printf("Bar:  %d\n", barFlag.Value())
fmt.Printf("Do Stuff: %v\n", doStuffFlag.Value())

Index

Examples

Package Files

cflag.go

Variables

var NoReg noReg

Dummy Registerable implementation which does not do anything.

Can be used to inhibit autoregistration.

type BoolFlag Uses

type BoolFlag struct {
    // contains filtered or unexported fields
}

func Bool Uses

func Bool(reg Registerable, name string, defaultValue bool, summaryLine string) *BoolFlag

Creates a flag of type bool.

reg: See package-level documentation.

summaryLine: One-line usage summary.

func BoolVar Uses

func BoolVar(reg Registerable, v *bool, name string, defaultValue bool, summaryLine string) *BoolFlag

Creates a flag of type bool. The variable referenced by pointer v is used as the storage location for the value of the configurable.

func (*BoolFlag) CfDefaultValue Uses

func (sf *BoolFlag) CfDefaultValue() interface{}

func (*BoolFlag) CfGetPriority Uses

func (sf *BoolFlag) CfGetPriority() configurable.Priority

func (*BoolFlag) CfName Uses

func (sf *BoolFlag) CfName() string

func (*BoolFlag) CfSetPriority Uses

func (sf *BoolFlag) CfSetPriority(priority configurable.Priority)

func (*BoolFlag) CfSetValue Uses

func (sf *BoolFlag) CfSetValue(v interface{}) error

func (*BoolFlag) CfUsageSummaryLine Uses

func (sf *BoolFlag) CfUsageSummaryLine() string

func (*BoolFlag) CfValue Uses

func (sf *BoolFlag) CfValue() interface{}

func (*BoolFlag) RegisterOnChange Uses

func (sf *BoolFlag) RegisterOnChange(f func(*BoolFlag))

func (*BoolFlag) SetValue Uses

func (sf *BoolFlag) SetValue(value bool)

Set the flag's current value.

func (*BoolFlag) String Uses

func (sf *BoolFlag) String() string

func (*BoolFlag) Value Uses

func (sf *BoolFlag) Value() bool

Call to get the flag's current value.

type Group Uses

type Group struct {
    // contains filtered or unexported fields
}

func NewGroup Uses

func NewGroup(reg Registerable, name string) *Group

Creates a flag group. A Group is itself a configurable and can hold multiple flags.

func (*Group) CfChildren Uses

func (ig *Group) CfChildren() []configurable.Configurable

func (*Group) CfName Uses

func (ig *Group) CfName() string

func (*Group) Register Uses

func (ig *Group) Register(cfg configurable.Configurable)

Register a child configurable to the group.

func (*Group) String Uses

func (ig *Group) String() string

type IntFlag Uses

type IntFlag struct {
    // contains filtered or unexported fields
}

func Int Uses

func Int(reg Registerable, name string, defaultValue int, summaryLine string) *IntFlag

Creates a flag of type int.

reg: See package-level documentation.

summaryLine: One-line usage summary.

func IntVar Uses

func IntVar(reg Registerable, v *int, name string, defaultValue int, summaryLine string) *IntFlag

Creates a flag of type int. The variable referenced by pointer v is used as the storage location for the value of the configurable.

func (*IntFlag) CfDefaultValue Uses

func (sf *IntFlag) CfDefaultValue() interface{}

func (*IntFlag) CfGetPriority Uses

func (sf *IntFlag) CfGetPriority() configurable.Priority

func (*IntFlag) CfName Uses

func (sf *IntFlag) CfName() string

func (*IntFlag) CfSetPriority Uses

func (sf *IntFlag) CfSetPriority(priority configurable.Priority)

func (*IntFlag) CfSetValue Uses

func (sf *IntFlag) CfSetValue(v interface{}) error

func (*IntFlag) CfUsageSummaryLine Uses

func (sf *IntFlag) CfUsageSummaryLine() string

func (*IntFlag) CfValue Uses

func (sf *IntFlag) CfValue() interface{}

func (*IntFlag) RegisterOnChange Uses

func (sf *IntFlag) RegisterOnChange(f func(*IntFlag))

func (*IntFlag) SetValue Uses

func (sf *IntFlag) SetValue(value int)

Set the flag's current value.

func (*IntFlag) String Uses

func (sf *IntFlag) String() string

func (*IntFlag) Value Uses

func (sf *IntFlag) Value() int

Get the flag's current value.

type Registerable Uses

type Registerable interface {
    Register(configurable configurable.Configurable)
}

type StringFlag Uses

type StringFlag struct {
    // contains filtered or unexported fields
}

func String Uses

func String(reg Registerable, name, defaultValue, summaryLine string) *StringFlag

Creates a flag of type string.

reg: See package-level documentation.

summaryLine: One-line usage summary.

func StringVar Uses

func StringVar(reg Registerable, v *string, name, defaultValue, summaryLine string) *StringFlag

Creates a flag of type string. The variable referenced by pointer v is used as the storage location for the value of the configurable.

func (*StringFlag) CfDefaultValue Uses

func (sf *StringFlag) CfDefaultValue() interface{}

func (*StringFlag) CfGetPriority Uses

func (sf *StringFlag) CfGetPriority() configurable.Priority

func (*StringFlag) CfName Uses

func (sf *StringFlag) CfName() string

func (*StringFlag) CfSetPriority Uses

func (sf *StringFlag) CfSetPriority(priority configurable.Priority)

func (*StringFlag) CfSetValue Uses

func (sf *StringFlag) CfSetValue(v interface{}) error

func (*StringFlag) CfUsageSummaryLine Uses

func (sf *StringFlag) CfUsageSummaryLine() string

func (*StringFlag) CfValue Uses

func (sf *StringFlag) CfValue() interface{}

func (*StringFlag) RegisterOnChange Uses

func (sf *StringFlag) RegisterOnChange(f func(*StringFlag))

func (*StringFlag) SetValue Uses

func (sf *StringFlag) SetValue(value string)

Set the flag's current value.

func (*StringFlag) String Uses

func (sf *StringFlag) String() string

func (*StringFlag) Value Uses

func (sf *StringFlag) Value() string

Get the flag's current value.

Package cflag imports 5 packages (graph) and is imported by 35 packages. Updated 2018-08-25. Refresh now. Tools for package owners.