fflag

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

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

Go to latest
Published: Jan 13, 2024 License: MIT Imports: 13 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(flag Flag)

func AutoEnv

func AutoEnv(fn func(long string) (env string))

func Bool

func Bool(short string, long string, value bool, usage string) *bool

func BoolVar

func BoolVar(ptr *bool, short string, long string, value bool, usage string)

func Bytes

func Bytes(short string, long string, value []byte, usage string) *[]byte

func BytesVar

func BytesVar(ptr *[]byte, short string, long string, value []byte, usage string)

func Config

func Config(fn func(*os.File) error)

func Duration

func Duration(short string, long string, value time.Duration, usage string) *time.Duration

func DurationVar

func DurationVar(ptr *time.Duration, short string, long string, value time.Duration, usage string)

func Float

func Float(short string, long string, value float64, usage string) *float64

func FloatSlice

func FloatSlice(short string, long string, value []float64, usage string) *[]float64

func FloatSliceVar

func FloatSliceVar(ptr *[]float64, short string, long string, value []float64, usage string)

func FloatVar

func FloatVar(ptr *float64, short string, long string, value float64, usage string)

func Func

func Func(short string, long string, usage string, fn func())

func Help

func Help()

func Int

func Int(short string, long string, value int, usage string) *int

func Int64

func Int64(short string, long string, value int64, usage string) *int64

func Int64Slice

func Int64Slice(short string, long string, value []int64, usage string) *[]int64

func Int64SliceVar

func Int64SliceVar(ptr *[]int64, short string, long string, value []int64, usage string)

func Int64Var

func Int64Var(ptr *int64, short string, long string, value int64, usage string)

func IntSlice

func IntSlice(short string, long string, value []int, usage string) *[]int

func IntSliceVar

func IntSliceVar(ptr *[]int, short string, long string, value []int, usage string)

func IntVar

func IntVar(ptr *int, short string, long string, value int, usage string)

func MustParse

func MustParse() (unused []string)

func Parse

func Parse() (unused []string, err error)

func ParseArgs

func ParseArgs() (unused []string, err error)

func ParseEnv

func ParseEnv() (err error)

func Reset

func Reset()

func Size

func Size(short string, long string, value bytesize.Size, usage string) *bytesize.Size

func SizeVar

func SizeVar(ptr *bytesize.Size, short string, long string, value bytesize.Size, usage string)

func String

func String(short string, long string, value string, usage string) *string

func StringSlice

func StringSlice(short string, long string, value []string, usage string) *[]string

func StringSliceVar

func StringSliceVar(ptr *[]string, short string, long string, value []string, usage string)

func StringVar

func StringVar(ptr *string, short string, long string, value string, usage string)

func StructFields

func StructFields(dst interface{})

func Uint

func Uint(short string, long string, value uint, usage string) *uint

func Uint64

func Uint64(short string, long string, value uint64, usage string) *uint64

func Uint64Slice

func Uint64Slice(short string, long string, value []uint64, usage string) *[]uint64

func Uint64SliceVar

func Uint64SliceVar(ptr *[]uint64, short string, long string, value []uint64, usage string)

func Uint64Var

func Uint64Var(ptr *uint64, short string, long string, value uint64, usage string)

func UintSlice

func UintSlice(short string, long string, value []uint, usage string) *[]uint

func UintSliceVar

func UintSliceVar(ptr *[]uint, short string, long string, value []uint, usage string)

func UintVar

func UintVar(ptr *uint, short string, long string, value uint, usage string)

func Usage

func Usage() string

func Var

func Var(ptr Value, short string, long string, value string, usage string)

func Version

func Version(version string)

Types

type Flag

type Flag struct {
	// Short is the short-form flag name, parsed from CLI flags prefixed by '-'.
	Short string

	// Long is the long-form flag name, parsed from CLI flags prefixed by '--'.
	Long string

	// Env ...
	Env string

	// Usage is the description for this CLI flag, used when generating usage string.
	Usage string

	// Required specifies whether this flag is required, if so returning error.
	Required bool

	// Default is the default value for this CLI flag, used when no value provided.
	Default string

	// RawValues contains raw value strings populated during parse stage.
	RawValues []string

	// Value stores the actual value pointer that is set upon argument parsing.
	Value Value
}

func GetEnv

func GetEnv(name string) *Flag

func GetLong

func GetLong(name string) *Flag

func GetShort

func GetShort(name string) *Flag

func (Flag) AppendUsage

func (f Flag) AppendUsage(b []byte) []byte

AppendUsage will append (new-line terminated) usage information for flag to b.

func (*Flag) Letter

func (f *Flag) Letter() rune

Letter returns the first letter associated with this flag, preferring short over long.

func (Flag) Name

func (f Flag) Name() string

Name returns a CLI readable name for this flag, preferring long. e.g. "--long".

type FlagSet

type FlagSet struct {
	// contains filtered or unexported fields
}
var Global FlagSet

Global provides access to a global FlagSet instance accessible via global FlagSet functions below.

func (*FlagSet) Add

func (set *FlagSet) Add(flag Flag)

Add will check the validity of, and add given flag to this FlagSet.

func (*FlagSet) AutoEnv

func (set *FlagSet) AutoEnv(fn func(long string) (env string))

AutoEnv will automatically assign environment keys to flags with a long-name provided, if nil will use a default function.

func (*FlagSet) Bool

func (set *FlagSet) Bool(short string, long string, value bool, usage string) *bool

func (*FlagSet) BoolSlice

func (set *FlagSet) BoolSlice(short string, long string, value []bool, usage string) *[]bool

func (*FlagSet) BoolSliceVar

func (set *FlagSet) BoolSliceVar(ptr *[]bool, short string, long string, value []bool, usage string)

func (*FlagSet) BoolVar

func (set *FlagSet) BoolVar(ptr *bool, short string, long string, value bool, usage string)

func (*FlagSet) Bytes

func (set *FlagSet) Bytes(short string, long string, value []byte, usage string) *[]byte

func (*FlagSet) BytesVar

func (set *FlagSet) BytesVar(ptr *[]byte, short string, long string, value []byte, usage string)

func (*FlagSet) Config

func (set *FlagSet) Config(fn func(*os.File) error)

Config registers a function hook to open path and pass to given 'fn' on supplied '-c' or '--config' value.

func (*FlagSet) Duration

func (set *FlagSet) Duration(short string, long string, value time.Duration, usage string) *time.Duration

func (*FlagSet) DurationSlice

func (set *FlagSet) DurationSlice(short string, long string, value []time.Duration, usage string) *[]time.Duration

func (*FlagSet) DurationSliceVar

func (set *FlagSet) DurationSliceVar(ptr *[]time.Duration, short string, long string, value []time.Duration, usage string)

func (*FlagSet) DurationVar

func (set *FlagSet) DurationVar(ptr *time.Duration, short string, long string, value time.Duration, usage string)

func (*FlagSet) Float

func (set *FlagSet) Float(short string, long string, value float64, usage string) *float64

func (*FlagSet) FloatSlice

func (set *FlagSet) FloatSlice(short string, long string, value []float64, usage string) *[]float64

func (*FlagSet) FloatSliceVar

func (set *FlagSet) FloatSliceVar(ptr *[]float64, short string, long string, value []float64, usage string)

func (*FlagSet) FloatVar

func (set *FlagSet) FloatVar(ptr *float64, short string, long string, value float64, usage string)

func (*FlagSet) Func

func (set *FlagSet) Func(short string, long string, usage string, fn func())

Func registers a function hook to be called on boolean result = true of given short,long,env Flag.

func (*FlagSet) GetEnv

func (set *FlagSet) GetEnv(name string) *Flag

GetEnv will fetch the flag with matching env name.

func (*FlagSet) GetLong

func (set *FlagSet) GetLong(name string) *Flag

GetLong will fetch the flag with matching long name.

func (*FlagSet) GetShort

func (set *FlagSet) GetShort(name string) *Flag

GetShort will fetch the flag with matching short name.

func (*FlagSet) Help

func (set *FlagSet) Help()

Help registers a function hook to print usage string and exit with code = 0 on '-h' or '--help'.

func (*FlagSet) Hook

func (set *FlagSet) Hook(fn func())

Hook allows registering a function hook to be called directly after parse.

func (*FlagSet) Int

func (set *FlagSet) Int(short string, long string, value int, usage string) *int

func (*FlagSet) Int64

func (set *FlagSet) Int64(short string, long string, value int64, usage string) *int64

func (*FlagSet) Int64Slice

func (set *FlagSet) Int64Slice(short string, long string, value []int64, usage string) *[]int64

func (*FlagSet) Int64SliceVar

func (set *FlagSet) Int64SliceVar(ptr *[]int64, short string, long string, value []int64, usage string)

func (*FlagSet) Int64Var

func (set *FlagSet) Int64Var(ptr *int64, short string, long string, value int64, usage string)

func (*FlagSet) IntSlice

func (set *FlagSet) IntSlice(short string, long string, value []int, usage string) *[]int

func (*FlagSet) IntSliceVar

func (set *FlagSet) IntSliceVar(ptr *[]int, short string, long string, value []int, usage string)

func (*FlagSet) IntVar

func (set *FlagSet) IntVar(ptr *int, short string, long string, value int, usage string)

func (*FlagSet) MustParse

func (set *FlagSet) MustParse(args, env []string) (unused []string)

MustParse calls FlagSet.Parse(...), panicking on error.

func (*FlagSet) Parse

func (set *FlagSet) Parse(args, env []string) (unused []string, err error)

Parse parses environment variables, followed by CLI arguments, into FlagSet, returning unused arguments.

func (*FlagSet) ParseArgs

func (set *FlagSet) ParseArgs(args []string) (unused []string, err error)

ParseArgs parses CLI arguments from slices into FlagSet, returning unused arguments.

func (*FlagSet) ParseEnv

func (set *FlagSet) ParseEnv(env []string) (err error)

ParseEnv parses environment variables from slice into FlagSet.

func (*FlagSet) Reset

func (set *FlagSet) Reset()

Reset will reset all Flags in FlagSet.

func (*FlagSet) Size

func (set *FlagSet) Size(short string, long string, value bytesize.Size, usage string) *bytesize.Size

func (*FlagSet) SizeSlice

func (set *FlagSet) SizeSlice(short string, long string, value []bytesize.Size, usage string) *[]bytesize.Size

func (*FlagSet) SizeSliceVar

func (set *FlagSet) SizeSliceVar(ptr *[]bytesize.Size, short string, long string, value []bytesize.Size, usage string)

func (*FlagSet) SizeVar

func (set *FlagSet) SizeVar(ptr *bytesize.Size, short string, long string, value bytesize.Size, usage string)

func (*FlagSet) Sort

func (set *FlagSet) Sort()

Sort will sort the internal slice of flags, first by short name, then long name.

func (*FlagSet) String

func (set *FlagSet) String(short string, long string, value string, usage string) *string

func (*FlagSet) StringSlice

func (set *FlagSet) StringSlice(short string, long string, value []string, usage string) *[]string

func (*FlagSet) StringSliceVar

func (set *FlagSet) StringSliceVar(ptr *[]string, short string, long string, value []string, usage string)

func (*FlagSet) StringVar

func (set *FlagSet) StringVar(ptr *string, short string, long string, value string, usage string)

func (*FlagSet) StructFields

func (set *FlagSet) StructFields(dst any)

StructFields registers appropriately tagged struct fields as flags.

Tags: "short" - the flag short name "long" - the flag long name "env" - flag env key name "usage" - the flag usage information "default" - the default flag value (in string form) "required" - whether flag MUST be provided

func (*FlagSet) Uint

func (set *FlagSet) Uint(short string, long string, value uint, usage string) *uint

func (*FlagSet) Uint64

func (set *FlagSet) Uint64(short string, long string, value uint64, usage string) *uint64

func (*FlagSet) Uint64Slice

func (set *FlagSet) Uint64Slice(short string, long string, value []uint64, usage string) *[]uint64

func (*FlagSet) Uint64SliceVar

func (set *FlagSet) Uint64SliceVar(ptr *[]uint64, short string, long string, value []uint64, usage string)

func (*FlagSet) Uint64Var

func (set *FlagSet) Uint64Var(ptr *uint64, short string, long string, value uint64, usage string)

func (*FlagSet) UintSlice

func (set *FlagSet) UintSlice(short string, long string, value []uint, usage string) *[]uint

func (*FlagSet) UintSliceVar

func (set *FlagSet) UintSliceVar(ptr *[]uint, short string, long string, value []uint, usage string)

func (*FlagSet) UintVar

func (set *FlagSet) UintVar(ptr *uint, short string, long string, value uint, usage string)

func (*FlagSet) Usage

func (set *FlagSet) Usage() string

Usage returns a string showing typical terminal-formatted usage information for all of the registered flags.

func (*FlagSet) Var

func (set *FlagSet) Var(ptr Value, short string, long string, value string, usage string)

Var will add given Value implementation to the Flagset, with given short / long / env names and usage, and encoded default 'value' string.

func (*FlagSet) Version

func (set *FlagSet) Version(version string)

Version registers a function hook to print given version string and exit with code = 0 on '-v' or '--version'.

type Value

type Value interface {
	Set(string) error
	Kind() string
	String() string
}

Value defines a pointer to usable flag value type.

Jump to

Keyboard shortcuts

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