go_flags

package module
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2025 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidValue = "invalid value %q, allowed values are: %s"
)

Functions

func SetFlag added in v0.3.0

func SetFlag(value flag.Value, name string, usage string)

SetFlag registers the custom flag with the standard flag package.

Parameters:

value - the flag.Value to register.
name - the flag name.
usage - the usage description for the flag.

Types

type Flag

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

Flag is a custom flag type that restricts its value to a predefined set of allowed strings.

func NewFlag

func NewFlag(
	defaultValue string,
	value *string,
	allowed []string,
	name string,
	usage string,
) *Flag

NewFlag creates a new Flag with a default value and a list of allowed values.

Parameters:

defaultValue - the default value for the flag.
value - the default value for the flag.
allowed - slice of allowed string values.
name - the name of the flag.
usage - the usage description for the flag.

Returns:

A pointer to the created Flag.

func (*Flag) Allowed

func (f *Flag) Allowed() []string

Allowed returns the list of allowed values for the flag.

Returns:

The allowed values.

func (*Flag) Default added in v0.3.4

func (f *Flag) Default() string

Default returns the default value of the flag.

Returns:

The default value of the flag as a string.

func (*Flag) Set

func (f *Flag) Set(value string) error

Set validates and sets the flag's value.

Parameters:

value - the value to set.

Returns:

An error if the value is not allowed, otherwise nil.

func (*Flag) SetFlag added in v0.3.4

func (f *Flag) SetFlag()

SetFlag registers the custom flag with the standard flag package.

func (*Flag) String

func (f *Flag) String() string

String returns the string representation of the flag's current value.

Returns:

The current value of the flag as a string.

func (*Flag) Value

func (f *Flag) Value() string

Value returns the current value of the flag.

Returns:

The current value of the flag as a string.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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