flag

package
v1.5.220 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool(name string, value bool, usage string) *bool

Bool creates a bool in our FlagSet.

func Cheating

func Cheating() (bool, string)

Cheating returns if any cheats are enabled, and what they are.

func Duration

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

Duration creates a Duration in our FlagSet.

func Float64

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

Float64 creates a float64 in our FlagSet.

func Get

func Get[T any](name string) T

Get loads a flag by name.

func Int

func Int(name string, value int, usage string) *int

Int creates an int in our FlagSet.

func Parse

func Parse(getSystemDefaults func() (*Config, error))

Parse parses the command-line flags, then loads the config object using the provided function. Should be called initially, before loading config.

func ResetFlagToDefault added in v1.2.399

func ResetFlagToDefault(name string) error

ResetFlagToDefault returns a given flag to its default value.

func ResetToDefaults

func ResetToDefaults()

ResetToDefaults returns all flags to their default value.

func Set

func Set(name string, value interface{}) error

Set overrides a flag value. May be used by the menu.

func String

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

String creates a string in our FlagSet.

func StringMap

func StringMap[T any](name string, value map[string]T, usage string) *map[string]T

StringMap is a custom flag type to contain maps from string to T.

func SystemDefault added in v1.0.59

func SystemDefault[T any](m map[string]T) T

SystemDefault performs a GOOS/GOARCH dependent value lookup to be used in flag defaults. Map keys shall be */*, GOOS/*, */GOARCH or GOOS/GOARCH.

func Text added in v1.2.399

func Text[T any, PT interface {
	encoding.TextMarshaler
	encoding.TextUnmarshaler
	*T
}](name string, value T, usage string) PT

Text creates a flag based on a variable that fulfills TextMarshaler and TextUnmarshaler.

Types

type Config

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

Config is a JSON serializable type containing the flags.

func Marshal

func Marshal() *Config

Marshal returns a config object for the currently set flags (both those from the config and command line). We only write non-default flag values.

func NoConfig

func NoConfig() (*Config, error)

NoConfig can be passed to Parse if the binary wants to do no config file processing.

func (*Config) MarshalJSON

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

MarshalJSON returns the JSON representation of the config.

func (*Config) UnmarshalJSON

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

UnmarshalJSON loads the config from a JSON object string.

Jump to

Keyboard shortcuts

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