klflag

package
v0.8.4 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2019 License: MIT Imports: 4 Imported by: 0

README

Flag Loader

Loads config values from command line flags

Usage

Basic usage with command line FlagSet

flagLoader := klflag.New(&klflag.Config{})

With a nstrings.Replacer for keys

flagLoader := klflag.New(&klflag.Config{
	Replacer: strings.NewReplacer(".", "-")
})

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Name is the name of the loader
	Name string
	// StopOnFailure tells whether a failure to load configs should closed the config and all registered closers
	StopOnFailure bool
	// FlagSet is the flag set from which to load flags in config
	// default value is flag.CommandLine
	FlagSet *flag.FlagSet
	// Prefix is the prefix to append before each flag to be added in the konfig.Store
	Prefix string
	// Replacer is a replacer to apply on flags to be added in the konfig.Store
	Replacer nstrings.Replacer
	// MaxRetry is the maximum number of times to retry
	MaxRetry int
	// RetryDelay is the delay between each retry
	RetryDelay time.Duration
}

Config is the config for the Flag Loader

type Loader

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

Loader is a loader for command line flags

func New

func New(cfg *Config) *Loader

New creates a new Loader with the given Config cfg

func (*Loader) Load

func (l *Loader) Load(s konfig.Values) error

Load implements konfig.Loader interface, it loads flags from the FlagSet given in config into the konfig.Store

func (*Loader) MaxRetry

func (l *Loader) MaxRetry() int

MaxRetry implements the konfig.Loader interface, it returns the max number of times a Load can be retried if it fails

func (*Loader) Name

func (l *Loader) Name() string

Name returns the name of the loader

func (*Loader) RetryDelay

func (l *Loader) RetryDelay() time.Duration

RetryDelay implements the konfig.Loader interface, is the delay between each retry

func (*Loader) StopOnFailure

func (l *Loader) StopOnFailure() bool

StopOnFailure returns whether a load failure should stop the config and the registered closers

Jump to

Keyboard shortcuts

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