flagutil

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBool

func GetBool(fs *flag.FlagSet, name string, defaultValue bool) bool

GetBool returns flag value as bool or defaultValue when not set/invalid.

func GetBoolPflag added in v1.4.0

func GetBoolPflag(fs *pflag.FlagSet, name string, defaultValue bool) bool

GetBoolPflag returns flag value as bool or defaultValue when not set/invalid.

func GetDuration

func GetDuration(fs *flag.FlagSet, name string, defaultValue time.Duration) time.Duration

GetDuration returns flag value as time.Duration or defaultValue when not set/invalid.

func GetDurationPflag added in v1.4.0

func GetDurationPflag(fs *pflag.FlagSet, name string, defaultValue time.Duration) time.Duration

GetDurationPflag returns flag value as time.Duration or defaultValue when not set/invalid.

func GetFlagValue

func GetFlagValue(fs *flag.FlagSet, name string) (string, bool)

GetFlagValue returns the string value for a flag if it was set.

func GetFlagValuePflag added in v1.4.0

func GetFlagValuePflag(fs *pflag.FlagSet, name string) (string, bool)

GetFlagValuePflag returns the string value for a flag if it was set.

func GetFloat64

func GetFloat64(fs *flag.FlagSet, name string, defaultValue float64) float64

GetFloat64 returns flag value as float64 or defaultValue when not set/invalid.

func GetInt

func GetInt(fs *flag.FlagSet, name string, defaultValue int) int

GetInt returns flag value as int or defaultValue when not set/invalid.

func GetInt64

func GetInt64(fs *flag.FlagSet, name string, defaultValue int64) int64

GetInt64 returns flag value as int64 or defaultValue when not set/invalid.

func GetInt64Pflag added in v1.4.0

func GetInt64Pflag(fs *pflag.FlagSet, name string, defaultValue int64) int64

GetInt64Pflag returns flag value as int64 or defaultValue when not set/invalid.

func GetIntPflag added in v1.4.0

func GetIntPflag(fs *pflag.FlagSet, name string, defaultValue int) int

GetIntPflag returns flag value as int or defaultValue when not set/invalid.

func GetString

func GetString(fs *flag.FlagSet, name, defaultValue string) string

GetString returns flag value or defaultValue when not set.

func GetStringPflag added in v1.4.0

func GetStringPflag(fs *pflag.FlagSet, name, defaultValue string) string

GetStringPflag returns flag value or defaultValue when not set.

func GetUint

func GetUint(fs *flag.FlagSet, name string, defaultValue uint) uint

GetUint returns flag value as uint or defaultValue when not set/invalid.

func GetUint64

func GetUint64(fs *flag.FlagSet, name string, defaultValue uint64) uint64

GetUint64 returns flag value as uint64 or defaultValue when not set/invalid.

func HasFlag

func HasFlag(fs *flag.FlagSet, name string) bool

HasFlag checks if a command-line flag is set in the given FlagSet

func HasFlagInArgs

func HasFlagInArgs(args []string, name string) bool

HasFlagInArgs checks if a flag is present in args (supports -name, --name, -name=value, --name=value)

func HasFlagInOSArgs

func HasFlagInOSArgs(name string) bool

HasFlagInOSArgs checks if a flag is present in os.Args

func HasFlagPflag added in v1.4.0

func HasFlagPflag(fs *pflag.FlagSet, name string) bool

HasFlagPflag checks if a command-line flag is set in the given pflag.FlagSet. It returns true if the flag was explicitly set (e.g. --port 8080 or -p 8080).

func ReadPasswordFromFile

func ReadPasswordFromFile(filePath string) (string, error)

ReadPasswordFromFile reads password from file (security improvement). Path is validated with path traversal check; relative paths are resolved to absolute. File content is trimmed of leading and trailing whitespace.

Types

This section is empty.

Jump to

Keyboard shortcuts

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