Help us shape the future of Go! Take the 2026 Go Developer Survey

flagconfig

package module
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2013 License: Apache-2.0 Imports: 9 Imported by: 5

README

flagconfig

A very simple library for specifying parameters and their default values and having them be read in from either the command-line or a configuration file. Also does auto-generation of configuration files with default values set.

Installation

.go.yaml:

    - loc: https://github.com/mediocregopher/flagconfig.git
      type: git
      ref: v0.4.2
      path: github.com/mediocregopher/flagconfig

Standard

go get github.com/mediocregopher/flagconfig

Usage

Godocs can be found here

See the example for basic usage.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FlagConfig

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

func New

func New(projname string) *FlagConfig

New returns a FlagConfig struct. Usage of this struct is: * Tell it what params to look for with StrParam, IntParam, etc... * Call Parse() * Get found parameters using GetStr, GetInt, etc...

func (*FlagConfig) DisallowConfig

func (f *FlagConfig) DisallowConfig()

If called then flagconfig won't have the ability to read in a configuration file. The --config and --example options won't be present in the --help menu.

func (*FlagConfig) FlagParam

func (f *FlagConfig) FlagParam(name, descr string, def bool)

FlagParam tells flagconfig to look for a param called name on the command line or in the config file. Passing the flag on the command-line indicates a value of whatever the opposite of the default is (so if the default is false, passing it on the command-line would mean true). In the configuration file the value can be either "true" or "false".

func (*FlagConfig) GetFlag

func (f *FlagConfig) GetFlag(name string) bool

GetFlag looks for a configuration parameter of the given name and returns its value (assuming the parameter is a flag).

func (*FlagConfig) GetInt

func (f *FlagConfig) GetInt(name string) int

GetInt looks for a configuration parameter of the given name and returns its value (assuming the parameter is an integer)

func (*FlagConfig) GetInts

func (f *FlagConfig) GetInts(name string) []int

GetInts looks for a configuration parameter of the given name and returns its value (assuming the parameter is a list of strings)

func (*FlagConfig) GetPositionals

func (f *FlagConfig) GetPositionals() []string

GetPositionals returns all positional arguments found after Parse'ing. Will return empty slice if none were found, and nil if Parse hasn't been called yet

func (*FlagConfig) GetStr

func (f *FlagConfig) GetStr(name string) string

GetStr looks for a configuration parameter of the given name and returns its value (assuming the parameter is a string)

func (*FlagConfig) GetStrs

func (f *FlagConfig) GetStrs(name string) []string

GetStrs looks for a configuration parameter of the given name and returns its value (assuming the parameter is a list of strings)

func (*FlagConfig) Help

func (f *FlagConfig) Help() string

Returns a formatted help string for the parameters that have been given so far

func (*FlagConfig) IntParam

func (f *FlagConfig) IntParam(name, descr string, def int)

IntParam tells flagconfig to look for a param called name of type int in either the config file or on the command line, or use the given default instead

func (*FlagConfig) IntParams

func (f *FlagConfig) IntParams(name, descr string, defaults ...int)

IntParams tells flagconfig to look for zero or more parameters of type int in either the config file or on the command line, or use the given default instead. If any are defined in one location they overwrite all from the other. For example, if there are three defined in the config file and one defined on the command-line, that one will be the only one in the returned value.

func (*FlagConfig) Parse

func (f *FlagConfig) Parse() error

Parse loads flagconfig's runtime configuration, using both command-line arguments and a possible configuration file

func (*FlagConfig) RequiredIntParam

func (f *FlagConfig) RequiredIntParam(name, descr string)

RequiredIntParam tells flagconfig to look for a param called name of type int in either the config file or on the command line, or return an error from Parse if it's not specified anywhere

func (*FlagConfig) RequiredStrParam

func (f *FlagConfig) RequiredStrParam(name, descr string)

RequiredStrParam tells flagconfig to look for a param called name of type string in either the config file or on the command line, or return an error from Parse if it's not specified anywhere

func (*FlagConfig) SetDescription

func (f *FlagConfig) SetDescription(descr string)

SetDescription sets the description which will be shown above the flag usage when --help is called on the command-line. This is optional.

func (*FlagConfig) SetExtraHelp

func (f *FlagConfig) SetExtraHelp(help string)

SetExtraHelp sets a string which will show up at the tail end of the --help message, after all flags are defined. This is optional.

func (*FlagConfig) StrParam

func (f *FlagConfig) StrParam(name, descr, def string)

StrParam tells flagconfig to look for a param called name of type string in either the config file or on the command line, or use the given default instead

func (*FlagConfig) StrParams

func (f *FlagConfig) StrParams(name, descr string, defaults ...string)

StrParams tells flagconfig to look for zero or more parameters of type string in either the config file or on the command line, or use the given default instead. If any are defined in one location they overwrite all from the other. For example, if there are three defined in the config file and one defined on the command-line, that one will be the only one in the returned value.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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