option

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package option provides flag.Value implementation for basic types.

Option syntax

Integer options accept 1234, 0664, 0x1234 and may be negative. Boolean options may be:

1, 0, t, f, T, F, true, false, TRUE, FALSE, True, False

Duration options accept any input valid for time.ParseDuration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bool

type Bool bool

func NewBool

func NewBool(val bool, p *bool) *Bool

NewBool creates a new boolean value.

func (*Bool) Get

func (b *Bool) Get() any

Get implements Getter.

func (*Bool) IsBoolFlag

func (b *Bool) IsBoolFlag() bool

IsBoolFlag always return true.

func (*Bool) Set

func (b *Bool) Set(s string) error

Set implements Value.

func (*Bool) String

func (b *Bool) String() string

String implements Value.

type Duration

type Duration time.Duration

func NewDuration

func NewDuration(val time.Duration, p *time.Duration) *Duration

NewDuration creates a new boolean value.

func (*Duration) Get

func (d *Duration) Get() any

Get implements Getter.

func (*Duration) Set

func (d *Duration) Set(s string) error

func (*Duration) String

func (d *Duration) String() string

String implements Value.

type Float64

type Float64 float64

func NewFloat64

func NewFloat64(val float64, p *float64) *Float64

NewFloat64 creates a new float64 value.

func (*Float64) Get

func (f *Float64) Get() any

Get implements Getter.

func (*Float64) Set

func (f *Float64) Set(s string) error

Set implements Value.

func (*Float64) String

func (f *Float64) String() string

String implements Value.

type Func added in v0.5.0

type Func func(string) error

Func implements Value.

func (Func) Set added in v0.5.0

func (f Func) Set(s string) error

func (Func) String added in v0.5.0

func (f Func) String() string

type Getter

type Getter = flag.Getter

Getter is an interface that allows the contents of a Value to be retrieved. It wraps the Value interface, rather than being part of it, because it appeared after Go 1 and its compatibility rules. All Value types provided by this package satisfy the Getter interface, except the type used by Func.

type Int

type Int int

func NewInt

func NewInt(val int, p *int) *Int

NewInt creates a new int value.

func (*Int) Get

func (i *Int) Get() any

Get implements Getter.

func (*Int) Set

func (i *Int) Set(s string) error

Set implements Value.

func (*Int) String

func (i *Int) String() string

String implements Value.

type Int64

type Int64 int64

func NewInt64

func NewInt64(val int64, p *int64) *Int64

NewInt64 creates a new int64 value.

func (*Int64) Get

func (i *Int64) Get() any

Get implements Getter.

func (*Int64) Set

func (i *Int64) Set(s string) error

Set implements Value.

func (*Int64) String

func (i *Int64) String() string

String implements Value.

type Option added in v0.5.0

type Option struct {
	Name     string
	Usage    string
	Value    Value
	DefValue string
}

Option define a configuration option.

type Slice added in v0.5.0

type Slice[T any] struct {
	// contains filtered or unexported fields
}

Slice is a wrapper around []T that implements Value. *T MUST implement Value otherwise Slice.Set / Slice.String will panic at runtime.

func NewSlice added in v0.5.0

func NewSlice[T any](val []T, p *[]T) *Slice[T]

NewSlice creates a new slice value.

func (*Slice[T]) Set added in v0.5.0

func (s *Slice[T]) Set(str string) error

Set implements Value.

func (*Slice[T]) String added in v0.5.0

func (s *Slice[T]) String() string

String implements Value.

type String

type String string

func NewString

func NewString(val string, p *string) *String

NewString creates a new string value.

func (*String) Get

func (s *String) Get() any

Get implements Getter.

func (*String) Set

func (s *String) Set(val string) error

Set implements Value.

func (*String) String

func (s *String) String() string

String implements Value.

type Text

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

func NewText

NewText creates a new encoding.TextMarshaler/encoding.TextUnmarshaler value.

func (Text) Get

func (v Text) Get() any

Get implements Getter.

func (Text) Set

func (v Text) Set(s string) error

Set implements Value.

func (Text) String

func (v Text) String() string

String implements Value.

type Uint

type Uint uint

func NewUint

func NewUint(val uint, p *uint) *Uint

NewUint creates a new uint value.

func (*Uint) Get

func (u *Uint) Get() any

Get implements Getter.

func (*Uint) Set

func (u *Uint) Set(s string) error

Set implements Value.

func (*Uint) String

func (u *Uint) String() string

String implements Value.

type Uint64

type Uint64 uint64

func NewUint64

func NewUint64(val uint64, p *uint64) *Uint64

NewUint64 creates a new uint64 value.

func (*Uint64) Get

func (i *Uint64) Get() any

Get implements Getter.

func (*Uint64) Set

func (i *Uint64) Set(s string) error

Set implements Value.

func (*Uint64) String

func (i *Uint64) String() string

String implements Value.

type Value

type Value = flag.Value

Value is the interface to the dynamic value stored in an option. (The default value is represented as a string.)

Jump to

Keyboard shortcuts

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