flag

package
v0.8.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 20, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Config

func Config(
	set *goflag.FlagSet,
	name string,
	usage string,
	opts ...ucfg.Option,
) *ucfg.Config

func ConfigVar

func ConfigVar(
	set *goflag.FlagSet,
	def *ucfg.Config,
	name string,
	usage string,
	opts ...ucfg.Option,
) *ucfg.Config

Types

type FileLoader

type FileLoader func(name string, opts ...ucfg.Option) (*ucfg.Config, error)

FileLoader is used by NewFlagFiles to define customer file loading functions for different file extensions.

type FlagValue

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

func ConfigFiles

func ConfigFiles(
	set *goflag.FlagSet,
	name string,
	usage string,
	extensions map[string]FileLoader,
	opts ...ucfg.Option,
) *FlagValue

func ConfigFilesExts

func ConfigFilesExts(
	set *goflag.FlagSet,
	name string,
	usage string,
	opts ...ucfg.Option,
) *FlagValue

func ConfigFilesExtsVar

func ConfigFilesExtsVar(
	set *goflag.FlagSet,
	def *ucfg.Config,
	name string,
	usage string,
	opts ...ucfg.Option,
) *FlagValue

func ConfigFilesVar

func ConfigFilesVar(
	set *goflag.FlagSet,
	def *ucfg.Config,
	name string,
	usage string,
	extensions map[string]FileLoader,
	opts ...ucfg.Option,
) *FlagValue

func ConfigJSONFiles

func ConfigJSONFiles(
	set *goflag.FlagSet,
	name string,
	usage string,
	opts ...ucfg.Option,
) *FlagValue

func ConfigJSONFilesVar

func ConfigJSONFilesVar(
	set *goflag.FlagSet,
	def *ucfg.Config,
	name string,
	usage string,
	opts ...ucfg.Option,
) *FlagValue

func ConfigYAMLFiles

func ConfigYAMLFiles(
	set *goflag.FlagSet,
	name string,
	usage string,
	opts ...ucfg.Option,
) *FlagValue

func ConfigYAMLFilesVar

func ConfigYAMLFilesVar(
	set *goflag.FlagSet,
	def *ucfg.Config,
	name string,
	usage string,
	opts ...ucfg.Option,
) *FlagValue

func NewFlagFiles

func NewFlagFiles(
	cfg *ucfg.Config,
	extensions map[string]FileLoader,
	opts ...ucfg.Option,
) *FlagValue

NewFlagFiles create a new flag, that will load external configurations file when being used. Configurations loaded from multiple files will be merged into one common Config object. If cfg is not nil, then the loaded configurations will be merged into cfg. The extensions parameter define custom file loaders for different file extensions. If extensions contains an entry with key "", then this loader will be used as default fallback.

func NewFlagKeyValue

func NewFlagKeyValue(cfg *ucfg.Config, autoBool bool, opts ...ucfg.Option) *FlagValue

NewFlagKeyValue implements the flag.Value interface for capturing ucfg.Config settings from command line arguments. Configuration options follow the argument name and must be in the form of "key=value". Using 'D' as command line flag for example, options on command line must be given as:

-D key1=value -D key=value

Note: the space between command line option and key is required by the flag package to parse command line flags correctly.

Note: it's valid to use a key multiple times. If keys are used multiple times, values get overwritten. The last known value for some key will be stored in the generated configuration.

The type of value must be any of bool, uint, int, float, or string. Any kind of array or object syntax is not supported.

If autoBool is enabled (default if Config or ConfigVar is used), keys without value are converted to bool variable with value being true.

func (*FlagValue) Config

func (v *FlagValue) Config() *ucfg.Config

func (*FlagValue) Error

func (v *FlagValue) Error() error

func (*FlagValue) Get

func (v *FlagValue) Get() interface{}

func (*FlagValue) Set

func (v *FlagValue) Set(arg string) error

func (*FlagValue) String

func (v *FlagValue) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL