flag

package module
v0.0.0-...-d395fe0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2017 License: MIT Imports: 11 Imported by: 0

README

Build Status

Usage

import "github.com/applee/flag"

var (
    config string
    age int
)

flag.StringVar(&config, flag.DefaultConfigFlagName, "", "path to config toml file")
flag.IntVar(&age, "age", 24, "help message for age")

log.Fatal(flag.Parse())

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfigFlagName = "config"

Functions

func Bool

func Bool(name string, value bool) *bool

Bool defines a bool flag with specified name, default value, and usage string. The return value is the address of a bool variable that stores the value of the flag.

func BoolVar

func BoolVar(p *bool, name string, value bool, usage string)

BoolVar defines a bool flag with specified name, default value, and usage string. The argument p points to a bool variable in which to store the value of the flag.

func Duration

func Duration(name string, value time.Duration, usage string) *time.Duration

Duration defines a time.Duration config variable with a given name and default value.

func DurationVar

func DurationVar(p *time.Duration, name string, value time.Duration, usage string)

DurationVar defines a time.Duration flag with specified name, default value, and usage string.

func Float64

func Float64(name string, value float64, usage string) *float64

Float64 defines a float64 config variable with a given name and default value.

func Float64Var

func Float64Var(p *float64, name string, value float64, usage string)

Float64Var defines a float64 flag with specified name, default value, and usage string.

func Init

func Init(name string, errorHandling flag.ErrorHandling)

func Int

func Int(name string, value int) *int

Int defines an int flag with specified name, default value, and usage string. The return value is the address of an int variable that stores the value of the flag.

func Int64

func Int64(name string, value int64) *int64

Int64 defines an int64 flag with specified name, default value, and usage string. The return value is the address of an int64 variable that stores the value of the flag.

func Int64Var

func Int64Var(p *int64, name string, value int64, usage string)

Int64Var defines an int64 flag with specified name, default value, and usage string. The argument p points to an int64 variable in which to store the value of the flag.

func IntVar

func IntVar(p *int, name string, value int, usage string)

IntVar defines an int flag with specified name, default value, and usage string. The argument p points to an int variable in which to store the value of the flag.

func Parse

func Parse() error

Parse parses the command-line, environment variables and config file flags into the global ConfigSet. This must be called after all config flags have been defined but before the flags are accessed by the program.

func Set

func Set(name, value string) error

func SetOutput

func SetOutput(output io.Writer)

func String

func String(name string, value string, usage string) *string

String defines a string flag with specified name, default value, and usage string. The return value is the address of a string variable that stores the value of the flag.

func StringVar

func StringVar(p *string, name string, value string, usage string)

StringVar defines a string flag with specified name, default value, and usage string. The argument p points to a string variable in which to store the value of the flag.

func Uint

func Uint(name string, value uint) *uint

Uint defines a uint flag with specified name, default value, and usage string. The return value is the address of a uint variable that stores the value of the flag.

func Uint64

func Uint64(name string, value uint64, usage string) *uint64

Uint64 defines a uint64 flag with specified name, default value, and usage string. The return value is the address of a uint64 variable that stores the value of the flag.

func Uint64Var

func Uint64Var(p *uint64, name string, value uint64, usage string)

Uint64Var defines a uint64 flag with specified name, default value, and usage string. The argument p points to a uint64 variable in which to store the value of the flag.

func UintVar

func UintVar(p *uint, name string, value uint, usage string)

UintVar defines a uint flag with specified name, default value, and usage string. The argument p points to a uint variable in which to store the value of the flag.

func Var

func Var(p flag.Value, name string, usage string)

Var defines a flag with the specified name and usage string. The type and value of the flag are represented by the first argument, of type Value, which typically holds a user-defined implementation of Value. For instance, the caller could create a flag that turns a comma-separated string into a slice of strings by giving the slice the methods of Value; in particular, Set would decompose the comma-separated string into the slice.

Types

type FlagSetEx

type FlagSetEx struct {
	*flag.FlagSet
	// contains filtered or unexported fields
}

func (*FlagSetEx) ParseEnv

func (f *FlagSetEx) ParseEnv(environ []string) error

ParseEnv parses flags from environment variables. Flags already set will be ignored.

func (*FlagSetEx) ParseTOML

func (f *FlagSetEx) ParseTOML(path string) error

type MultiError

type MultiError []error

MultiError is returned by batch operations when there are errors with particular elements. Errors will be in a one-to-one correspondence with the input elements; successful elements will have a nil entry.

func (MultiError) Error

func (m MultiError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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