config

package module
v2.3.8 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: MIT Imports: 25 Imported by: 9

README

config

cross plattform configuration tool.

It is meant as an alternative to the flags package in the standard library.

The Idea

  • Commandline arguments (also known as Flags) can be saved in configuration files.
  • There are different priorities of configuration files, depending if it is for a local folder, for the user or for the machine
  • also environmental variables should be able to overwrite settings
  • all of this should work with subcommands too

The Features

  • argument types like string, bool, int, float, date, time, datetime, json
  • subcommands
  • autogenerated usage string
  • autogenerated help messages
  • automatically loads configuration files
  • automatically loads environmental variables
  • multiplattform (Windows, Linux, MacOsX, Unix)
  • set and get configurations autogenerated subcommands within the created program

The priorities of the settings:

  1. commandline arguments overwrite
  2. environmental variables that overwrite
  3. local settings in a subfolder of the working directory that overwrite
  4. user setting for the current user that overwrite
  5. global settings for the local machine that overwrite
  6. default values

Installation of the config program

Example

An easy example without subcommands:

package main

import (
	"fmt"
	"os"

	"gitlab.com/golang-utils/config/v2"
)

var (
	// creates a new config
	cfg = config.New(
		"hello", // program name
		0, 1, 2, // version (0.1.2)
		"hello is an easy example", // purpose of the program
		config.AsciiArt("hello"),   // optional ascii-art
	)

	// argName is an example of a string arg that is required
	argName = cfg.String("name", "please pass your name here", config.Required())

	// argAge is an example of an optional arg that is an int
	argAge = cfg.Int("age", "your age here")

	// argVegetarian is an example of a boolean arg with a default value and a shortflag
	argVegetarian = cfg.Bool("veggy", "are you a vegetarian", config.Default(false), config.Shortflag('v'))
)

func main() {

	// check the arguments
	err := cfg.Run()

	// the parameters were not correct
	if err != nil {

		// print the Usage information
		fmt.Println(cfg.Usage())

		// print the error
		fmt.Fprintf(os.Stderr, "ERROR: %v\n", err)

		// exit with correct error code
		os.Exit(1)
	}

	fmt.Printf("Hello, %s!\n", argName.Get())

	// check, if argAge was given
	if argAge.IsSet() {
		fmt.Printf("Your are %v years old.\n", argAge.Get())
	}

	if argVegetarian.Get() {
		fmt.Println("You are vegetarian.")
	}

	os.Exit(0)
}

If you would compile this program as "hello" and would run "hello help" in the commandline, you would get

    __           __ __
   / /_   ___   / // /____
  / __ \ / _ \ / // // __ \
 / / / //  __// // // /_/ /
/_/ /_/ \___//_//_/ \____/

hello v0.1.2
  hello is an easy example

usage:
  hello [command] OPTION...

options:
  --name=''                     please pass your name here

  [--age=<integer>]             your age here

  [-v, --veggy=false]           are you a vegetarian


commands:
  config                        show the configuration of hello

  version                       show the version of hello

  help                          show the help


for help about a specific command, run
  hello help <command>

Optional arguments are in [brackets].

running

hello --name=Marc --age=50

returns

Hello, Marc!
Your are 50 years old.

this line

hello config -o=name -v=Marc set

will set the option 'name' in the local configuration file to 'Marc' So that is the fallback for the next invocation.

hello help config

will show all informations about the configuration files and environmental variables

Example with subcommands

package main

import (
	"fmt"
	"os"

	"gitlab.com/golang-utils/config/v2"
)

var (
	// creates a new config
	cfg = config.New(
		"hello", // program name
		0, 1, 2, // version (0.1.2)
		"hello is a subcommand example", // purpose of the program
		config.AsciiArt("hello"),
	)

	// argName is a toplevel string arg that is required
	argName = cfg.String("name", "please pass your name here", config.Required())

	// argAge is a toplevel int, that we only want to use in the top level
	argAge = cfg.Int("age", "your age here", config.Required())

	// cmdGoodbye is an example of a (sub)command
	// we skip the 'age' argument from the toplevel, because we don't need it in the subcommand
	cmdGoodbye = cfg.Command("goodbye", "say farewell").Skip("age")

	// argGoodbyeLanguage is an argument that is just available for the (sub)command cmdGoodbye
	argGoodbyeLanguage = cmdGoodbye.String("language", "valid is 'es' for spanish and 'en' for english", config.Default("en"))
)

func main() {

	// check the arguments
	err := cfg.Run()

	// the parameters were not correct
	if err != nil {

		// print the Usage information
		fmt.Println(cfg.Usage())

		// print the error
		fmt.Fprintf(os.Stderr, "ERROR: %v\n", err)

		// exit with correct error code
		os.Exit(1)
	}

	switch cfg.ActiveCommand() {
	case cmdGoodbye:
		// argGoodbyeLanguage is just available for cmdGoodbye
		switch argGoodbyeLanguage.Get() {

		// note that argName from the toplevel is also available
		// argAge however is skipped. otherwise we would get an error message because of a missing argument
		case "es":
			fmt.Printf("Ciao, %s!\n", argName.Get())
		case "en":
			fmt.Printf("Goodbye, %s!\n", argName.Get())
		default:
			// print the error
			fmt.Fprintf(os.Stderr, "ERROR: unknown language: %s\n", argGoodbyeLanguage.Get())
		}
	default:
		fmt.Printf("Hello, %s, you are %v years old.\n", argName.Get(), argAge.Get())
	}

	os.Exit(0)
}

If you run

hello help

here, you get

    __           __ __
   / /_   ___   / // /____
  / __ \ / _ \ / // // __ \
 / / / //  __// // // /_/ /
/_/ /_/ \___//_//_/ \____/

hello v0.1.2
  hello is a subcommand example

usage:
  hello [command] OPTION...

options:
  --name=''                     please pass your name here

  --age=<integer>               your age here


commands:
  goodbye                       say farewell

  config                        show the configuration of hello

  version                       show the version of hello

  help                          show the help


for help about a specific command, run
  hello help <command>

and with

hello help goodbye
hello goodbye
  say farewell

usage:
  hello goodbye OPTION...

options:
  [--language='en']             valid is 'es' for spanish and 'en' for english

  --name=''                     please pass your name here

hello goodbye --name=Marc

gives you the expected

Goodbye, Marc!

also, see example-app

Documentation

see https://pkg.go.dev/gitlab.com/golang-utils/config/v2

Documentation

Overview

Package config provides a cross plattform library to merge configuration files, environmental variables and command line flags.

Index

Examples

Constants

View Source
const (
	DateFormat      = "2006-01-02"
	TimeFormat      = "15:04:05"
	DateTimeFormat  = "2006-01-02 15:04:05"
	DateTimeGeneral = "2006-01-02 15:04:05 -0700 MST"
)

Variables

View Source
var (
	ErrInvalidShortflag = errors.New("invalid shortflag")
	ErrSubCommand       = errors.New("sub command is not supported")
	ErrMissingHelp      = errors.New("missing help text")
)
View Source
var (
	//USER_DIR    string
	CONFIG_DIR  string
	GLOBAL_DIRS string // colon separated list to look for
	WORKING_DIR string
	CONFIG_EXT  = ".conf"
)
View Source
var VERSION = Version{Major: 2, Minor: 3, Patch: 8}

Functions

func Default

func Default(val interface{}) func(*Option)

func Required

func Required() func(*Option)

func RunScaffold added in v2.2.0

func RunScaffold(dir, prog string, test bool) (err error)

func Shortflag

func Shortflag(s rune) func(*Option)

func ValidateName added in v2.1.0

func ValidateName(name string) (err error)

rules for names:

must not start with numbers
may not have more than an underscore in a row
may not have more than a dash in a row
may not start or end with an underscore
may not start or end with a dash
may not have an underscore followed by a dash
may not have a dash followed by an underscore
other than that, just lowercase letters are allowed
we need at least two characters

func ValidateType

func ValidateType(option Option) error

ValidateType checks if the given type is valid. If it does, nil is returned, otherwise ErrInvalidType is returned

Types

type BoolGetter

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

func (*BoolGetter) Get

func (b *BoolGetter) Get() bool

func (*BoolGetter) IsSet

func (b *BoolGetter) IsSet() bool

type Config

type Config struct {
	// contains filtered or unexported fields
}
Example
app := New("testapp", 1, 2, 3, "help text")
verbose := app.Bool("verbose", "show verbose messages", Required())
// real application would use
// err := app.Run()
err := app.RunArgs("--verbose")
if err != nil {
	fmt.Printf("ERROR: %v", err)
}
fmt.Printf("verbose: %v", verbose.Get())
Output:

verbose: true

func New

func New(appname string, majorVersion, minorVersion, patchVersion uint16, helpIntro string, opts ...ConfigOption) (c *Config)

New creates a new *Config for the given appname and version numbers It panics, if the appname does not conform to the naming rules.

  • just lowercase letters are allowed
  • it must have at least two characters
  • it must not start with numbers
  • it must not start or end with an underscore or a dash
  • it must not have an underscore followed by an underscore or a dash
  • it must not have a dash followed by a dash or an underscore

func NewConfig

func NewConfig(app string, version Version, helpIntro string, mainConfig bool) (c *Config, err error)

func (*Config) ActiveCommand

func (c *Config) ActiveCommand() (s *Config)

CurrentSub returns the active command

func (*Config) Binary

func (c *Config) Binary() (path string, err error)

Binary returns the path to the binary of the app

func (*Config) Bool

func (c *Config) Bool(name, helpText string, opts ...func(*Option)) BoolGetter

shortcut for MustNewOption of type bool

func (*Config) CheckMissing

func (c *Config) CheckMissing() error

CheckMissing checks if mandatory values are missing inside the values map CheckMissing stops on the first error

func (*Config) Command

func (c *Config) Command(name string, helpIntro string) *Config

Command returns a *Config for a command and panics on errors

func (*Config) CommmandName

func (c *Config) CommmandName() string

func (*Config) Date

func (c *Config) Date(name, helpText string, opts ...func(*Option)) DateTimeGetter

func (*Config) DateTime

func (c *Config) DateTime(name, helpText string, opts ...func(*Option)) DateTimeGetter

shortcut for MustNewOption of type datetime

func (*Config) EachCommand

func (c *Config) EachCommand(fn func(name string, val *Config))

func (*Config) EachSpec

func (c *Config) EachSpec(fn func(name string, opt *Option))

func (*Config) EachValue

func (c *Config) EachValue(fn func(name string, val interface{}))

func (*Config) FirstGlobalsFile

func (c *Config) FirstGlobalsFile() string

GlobalFile returns the path for the global config file in the first global directory

func (*Config) Float

func (c *Config) Float(name, helpText string, opts ...func(*Option)) FloatGetter

shortcut for MustNewOption of type float64

func (Config) GetBool

func (c Config) GetBool(option string) bool

GetBool returns the value of the option as bool

func (*Config) GetCommandConfig

func (c *Config) GetCommandConfig(name string) (s *Config, err error)

func (Config) GetFloat

func (c Config) GetFloat(option string) float64

GetFloat returns the value of the option as float64

func (Config) GetInt

func (c Config) GetInt(option string) int

GetInt returns the value of the option as int

func (Config) GetJSON

func (c Config) GetJSON(option string, val interface{}) error

GetJSON unmarshals the value of the option to val.

func (Config) GetString

func (c Config) GetString(option string) string

GetString returns the value of the option as string

func (Config) GetTime

func (c Config) GetTime(option string) (t time.Time)

GetTime returns the value of the option as time

func (Config) GetValue

func (c Config) GetValue(option string) interface{}

GetValue returns the value of the option

func (*Config) Int

func (c *Config) Int(name, helpText string, opts ...func(*Option)) IntGetter

shortcut for MustNewOption of type int

func (*Config) IsOption

func (c *Config) IsOption(option string) bool

IsOption returns true, if the given option is allowed

func (Config) IsSet

func (c Config) IsSet(option string) bool

IsSet returns true, if the given option is set and false if not.

func (*Config) JSON

func (c *Config) JSON(name, helpText string, opts ...func(*Option)) JSONGetter

shortcut for MustNewOption of type json

func (*Config) LastBool

func (c *Config) LastBool(name, helpText string, opts ...func(*Option)) BoolGetter

LastBool receives the last argument as a boolean

func (*Config) LastDate

func (c *Config) LastDate(name, helpText string, opts ...func(*Option)) DateTimeGetter

LastDate receives the last argument as a date

func (*Config) LastDateTime

func (c *Config) LastDateTime(name, helpText string, opts ...func(*Option)) DateTimeGetter

LastDateTime receives the last argument as a datetime

func (*Config) LastFloat

func (c *Config) LastFloat(name, helpText string, opts ...func(*Option)) FloatGetter

LastFloat receives the last argument as a float32

func (*Config) LastInt

func (c *Config) LastInt(name, helpText string, opts ...func(*Option)) IntGetter

LastInt receives the last argument as an int

func (*Config) LastString

func (c *Config) LastString(name, helpText string, opts ...func(*Option)) StringGetter

LastString receives the last argument as a string

func (*Config) LastTime

func (c *Config) LastTime(name, helpText string, opts ...func(*Option)) DateTimeGetter

LastTime receives the last argument as a time

func (*Config) Load

func (c *Config) Load(withArgs bool) error

func (*Config) LoadDefaults

func (c *Config) LoadDefaults()

func (*Config) LoadFile

func (c *Config) LoadFile(path string) (err error, found bool)

LoadFile merges the config from the given file and returns any error happening during the merge If the file could not be opened (does not exist), no error is returned TODO maybe an error should be returned, if the file exists, but could not be opened because of missing access rights

func (*Config) LoadGlobals

func (c *Config) LoadGlobals() error

LoadGlobals loads the first config file for the app it could find inside the GLOBAL_DIRS and returns an error if the config could not be merged properly If no config file could be found, no error is returned.

func (*Config) LoadLocals

func (c *Config) LoadLocals() error

LoadLocals merges config inside a .config subdir in the local directory

func (*Config) LoadUser

func (c *Config) LoadUser() error

LoadUser loads the user specific config file

func (*Config) LocalFile

func (c *Config) LocalFile() string

LocalFile returns the local config file (inside the .config subdir of the current working dir)

func (*Config) Locations

func (c *Config) Locations(option string) []string

Location returns the locations where the option was set in the order of setting.

The locations are tracked differently: - defaults are tracked by their %v printed value - environment variables are tracked by their name - config files are tracked by their path - cli args are tracked by their name - settings via Set() are tracked by the given location or the caller if that is empty

func (*Config) MarshalJSON

func (c *Config) MarshalJSON() ([]byte, error)

MarshalJSON serializes the spec to JSON

func (*Config) Merge

func (c *Config) Merge(rd io.Reader, location string) error

func (*Config) MergeArgs

func (c *Config) MergeArgs() error

MergeArgs merges the os.Args into the config args like --a-key='a val' will correspond to the config value A_KEY=a val If the key is CONFIG_SPEC, MergeArgs will print the config spec as json and exit the program If any error happens the error will be printed to os.StdErr and the program exists will status code 1 exiting the program. also if --config_spec is set the spec is directly written to the StdOut and the program is exiting. If --help is set, the help message is printed with the the help messages for the config options. If --version is set, the version of the running app is returned

func (*Config) MergeEnv2 added in v2.1.0

func (c *Config) MergeEnv2() error

func (*Config) MustNewOption

func (c *Config) MustNewOption(name, type_, helpText string, opts []func(*Option)) *Option

panics for invalid values

func (*Config) NewOption

func (c *Config) NewOption(name, type_, helpText string, opts []func(*Option)) (*Option, error)

adds a new option

func (*Config) Relax

func (c *Config) Relax(option string) *Config

func (*Config) Reset

func (c *Config) Reset()

Reset cleans the values, the locations and any current subcommand

func (*Config) Run

func (c *Config) Run() error

Load loads the config values in the following order where each loader overwrittes corresponding config keys that have been defined

defaults
global config
user config
local config
env config
args config

in the args config any wrong syntax or values result in writing the error to StdErr and exiting the program. also if --config_spec is set the spec is directly written to the StdOut and the program is exiting. If --help is set, the help message is printed with the the help messages for the config options

func (*Config) RunArgs added in v2.1.0

func (c *Config) RunArgs(args ...string) error

RunArgs runs the config by just respecting the given args

func (*Config) RunArgsSilent added in v2.1.0

func (c *Config) RunArgsSilent(args ...string) error

RunArgsSilent runs the config by just respecting the given args and don't print anything for defaults

func (*Config) RunCat added in v2.1.5

func (cmdConfig *Config) RunCat(ty string) (outstr string, err error)

ty := optionCatType.Get()

func (*Config) RunGet added in v2.1.5

func (cmdConfig *Config) RunGet(key, cmd string) (out string, err error)

cmd := optionSetSubCmd.Get() key := optionGetKey.Get()

func (*Config) RunLocations added in v2.1.5

func (cmdConfig *Config) RunLocations() (locjson string, err error)

func (*Config) RunPath added in v2.1.5

func (cmdConfig *Config) RunPath(ty string) (outstr string, err error)

ty := optionPathType.Get()

func (*Config) RunRm added in v2.1.5

func (cmdConfig *Config) RunRm(ty string) error

ty := optionRmType.Get()

func (*Config) RunSet added in v2.1.5

func (cmdConfig *Config) RunSet(key, val string, ty string, cmd string) error

key := optionSetKey.Get() val := optionSetValue.Get() ty := optionSetPathType.Get() cmd := optionSetSubCmd.Get()

func (*Config) RunUnset added in v2.2.2

func (cmdConfig *Config) RunUnset(key, ty string, cmd string) error

key := optionSetKey.Get() ty := optionSetPathType.Get() cmd := optionSetSubCmd.Get()

func (*Config) SaveToGlobals

func (c *Config) SaveToGlobals() error

SaveToGlobals saves the given config values to a global config file don't save secrets inside the global config, since it is readable for everyone A new global config is written with 0644. The config is saved inside the first directory of GLOBAL_DIRS

func (*Config) SaveToLocal

func (c *Config) SaveToLocal() error

SaveToLocal saves all values to the local config file A new config is written with 0640, ro readable for user group and writeable for the user

func (*Config) SaveToUser

func (c *Config) SaveToUser() error

SaveToUser saves all values to the user config file creating missing directories A new config is written with 0640, ro readable for user group and writeable for the user

func (*Config) Set

func (c *Config) Set(option string, val string, location string) error

Set sets the option to the value. Location is a hint from where the option setting was triggered. If the location is empty, the caller file and line is tracked as location.

func (*Config) SetGlobalOptions

func (c *Config) SetGlobalOptions(options map[string]string) error

func (*Config) SetLocalOptions

func (c *Config) SetLocalOptions(options map[string]string) error

func (*Config) SetUserOptions

func (c *Config) SetUserOptions(options map[string]string) error

func (*Config) Skip

func (c *Config) Skip(option string) *Config

Skip skips the given option of the parent command and is chainable It panics, if the given option is not a parent option of if the current config is no subcommand

func (*Config) SkipAllBut

func (c *Config) SkipAllBut(except ...string) *Config

Skip skips all options of the parent command but the given

func (*Config) SpecTree

func (c *Config) SpecTree() map[string]*Option

func (*Config) String

func (c *Config) String(name, helpText string, opts ...func(*Option)) StringGetter

shortcut for MustNewOption of type string

func (*Config) Time

func (c *Config) Time(name, helpText string, opts ...func(*Option)) DateTimeGetter

func (*Config) UnmarshalJSON

func (c *Config) UnmarshalJSON(data []byte) error

UnmarshalJSON deserializes the spec from JSON

func (*Config) Usage

func (c *Config) Usage() string

func (*Config) UserFile

func (c *Config) UserFile() string

UserFile returns the user defined config file path

func (*Config) ValidateValues

func (c *Config) ValidateValues() error

ValidateValues validates only values that are set and not nil. It does not check for missing mandatory values (use CheckMissing for that) ValidateValues stops on the first error

func (*Config) WriteConfigFilex

func (c *Config) WriteConfigFilex(path string, perm os.FileMode) (err error)

WriteConfigFile writes the configuration values to the given file The file is overwritten/created on success and a backup of an existing file is written back if an error happens the given perm is only used to create new files.

type ConfigOption added in v2.2.2

type ConfigOption func(c *Config)

func AsciiArt added in v2.2.2

func AsciiArt(s string) ConfigOption

type DateTimeGetter

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

func (*DateTimeGetter) Get

func (b *DateTimeGetter) Get() time.Time

func (*DateTimeGetter) IsSet

func (b *DateTimeGetter) IsSet() bool

type EmptyValueError

type EmptyValueError string

func (EmptyValueError) Error

func (e EmptyValueError) Error() string

type ErrDoubleOption

type ErrDoubleOption string

func (ErrDoubleOption) Error

func (e ErrDoubleOption) Error() string

type ErrDoubleShortflag

type ErrDoubleShortflag string

func (ErrDoubleShortflag) Error

func (e ErrDoubleShortflag) Error() string

type ErrInvalidAppName

type ErrInvalidAppName string

func (ErrInvalidAppName) Error

func (e ErrInvalidAppName) Error() string

type ErrInvalidOptionName

type ErrInvalidOptionName string

func (ErrInvalidOptionName) Error

func (e ErrInvalidOptionName) Error() string

type FloatGetter

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

func (*FloatGetter) Get

func (b *FloatGetter) Get() float64

func (*FloatGetter) IsSet

func (b *FloatGetter) IsSet() bool

type IntGetter

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

func (*IntGetter) Get

func (b *IntGetter) Get() int

func (*IntGetter) IsSet

func (b *IntGetter) IsSet() bool

type InvalidConfig

type InvalidConfig struct {
	Version Version
	Err     error
}

func (InvalidConfig) Error

func (e InvalidConfig) Error() string

type InvalidConfigEnv

type InvalidConfigEnv struct {
	Version Version
	EnvKey  string
	Err     error
}

func (InvalidConfigEnv) Error

func (e InvalidConfigEnv) Error() string

type InvalidConfigFileError

type InvalidConfigFileError struct {
	ConfigFile string
	Version    Version
	Err        error
}

func (InvalidConfigFileError) Error

func (e InvalidConfigFileError) Error() string

type InvalidConfigFlag

type InvalidConfigFlag struct {
	Version Version
	Flag    string
	Err     error
}

func (InvalidConfigFlag) Error

func (e InvalidConfigFlag) Error() string

type InvalidDefault

type InvalidDefault struct {
	Option
}

func (InvalidDefault) Error

func (e InvalidDefault) Error() string

type InvalidNameError

type InvalidNameError string

func (InvalidNameError) Error

func (e InvalidNameError) Error() string

type InvalidTypeError

type InvalidTypeError struct {
	Option
}

func (InvalidTypeError) Error

func (e InvalidTypeError) Error() string

type InvalidValueError

type InvalidValueError struct {
	Option
	Value interface{}
}

func (InvalidValueError) Error

func (e InvalidValueError) Error() string

type InvalidVersionError

type InvalidVersionError string

func (InvalidVersionError) Error

func (e InvalidVersionError) Error() string

type JSONGetter

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

func (*JSONGetter) Get

func (b *JSONGetter) Get(val interface{}) error

func (*JSONGetter) IsSet

func (b *JSONGetter) IsSet() bool

type MissingOptionError

type MissingOptionError struct {
	Version Version
	Option
}

func (MissingOptionError) Error

func (e MissingOptionError) Error() string

type Option

type Option struct {
	// Name must consist of words that are joined by the underscore character _
	// Each word must consist of uppercase letters [A-Z] and may have numbers
	// A word must consist of two ascii characters or more.
	// A name must at least have one word
	// If the option is the flag-less last argument, Name is empty
	Name string `json:"name"`

	// Required indicates, if the Option is required
	Required bool `json:"required"`

	// Type must be one of "bool","int","float64","string","datetime","json"
	Type string `json:"type"`

	// The Help string is part of the documentation
	Help string `json:"help"`

	// The Default value for the Config. The value might be nil for optional Options.
	// Otherwise, it must have the same type as the Type property indicates
	Default interface{} `json:"default,omitempty"`

	// A Shortflag for the Option. Shortflags may only be used for commandline flags
	// They must be a single lowercase ascii character
	Shortflag string `json:"shortflag,omitempty"`

	// LastArgName is only set if the Option is the flag-less last argument (then Name is empty)
	LastArgName string `json:"lastargname,omitempty"`
}

func (Option) Validate

func (c Option) Validate() error

Validate checks if the Option is valid. If it does, nil is returned, otherwise the error is returned

func (Option) ValidateDefault

func (c Option) ValidateDefault() error

ValidateDefault checks if the default value is valid. If it does, nil is returned, otherwise ErrInvalidDefault is returned or a json unmarshalling error if the type is json

func (Option) ValidateValue

func (c Option) ValidateValue(val interface{}) error

ValidateValue checks if the given value is valid. If it does, nil is returned, otherwise ErrInvalidValue is returned or a json unmarshalling error if the type is json

type StringGetter

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

func (*StringGetter) Get

func (b *StringGetter) Get() string

func (*StringGetter) IsSet

func (b *StringGetter) IsSet() bool

type UnknownOptionError

type UnknownOptionError struct {
	Version Version
	Option  string
}

func (UnknownOptionError) Error

func (e UnknownOptionError) Error() string

type Version

type Version = version.Version

type Versions

type Versions = version.Versions

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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