value

package
v0.21.1 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: BSD-3-Clause Imports: 15 Imported by: 2

Documentation

Overview

Package value provides support for some additional flag value types.

Index

Constants

This section is empty.

Variables

View Source
var DefaultTimeLayouts = []string{
	time.DateOnly,
	time.RFC3339,
	"2006-01-02T15:04:05",
	"2006-01-02 15:04:05",
	"2006-01-02T15:04",
	"2006-01-02 15:04",
}

DefaultTimeLayouts specifies the layouts that are allowed when parsing Time. The default specifies RFC3339, which is what the built-in parser would use, plus bare dates (YYYY-MM-dd) and their time of day using the 24-hour clock and optionally with seconds resolution.

Functions

func JSON

func JSON(v any) flag.Getter

JSON wraps a pointer to a value which will be marshalled from files as JSON. The value can't be used directly from the command line unless it also implements Value.Set or ValueReader.SetData, which the value must define. Using JSON from the command line would be cumbersome.

func ParseByteLength

func ParseByteLength(s string) (int, error)

ParseByteLength from a string

Types

type ByteLength

type ByteLength int

ByteLength represents number of bytes

func (*ByteLength) UnmarshalText

func (b *ByteLength) UnmarshalText(data []byte) error

type Hex

type Hex int

Hex represents an integer that parses from the hex syntax

func (Hex) String

func (h Hex) String() string

func (*Hex) UnmarshalText

func (h *Hex) UnmarshalText(d []byte) error

type Octal

type Octal int

Octal represents an integer that parses from the octal syntax

func (Octal) String

func (h Octal) String() string

func (*Octal) UnmarshalText

func (h *Octal) UnmarshalText(d []byte) error

type Time added in v0.21.1

type Time struct {

	// AllowedLayouts specifies the layouts that are allowed when parsing
	// the timestamps. By default, DefaultTimeLayouts is used when this
	// is unspecified.
	AllowedLayouts []string
	// contains filtered or unexported fields
}

Time provides a value whose parsing can be configured, which increases the ergonomics of dates and times in flags and args.

func (Time) DateOnly added in v0.21.1

func (t Time) DateOnly() bool

DateOnly indicates whether the timestamp was parsed only from a date, which means that the time of day that was intended by the user could be ambiguous.

func (*Time) Range added in v0.21.1

func (t *Time) Range() (start, end time.Time)

Range interprets the timestamp as a range of time. If an exact timestamp was specified or if any component of the time of day was specified, both return values will correspond to the value that was parsed. If only a date was specified the range will correspond to the start and end of day.

func (*Time) Reset added in v0.21.1

func (t *Time) Reset()

Reset will reset the timestamp. The configuration attribute, AllowedLayout is not modified by this method

func (*Time) Set added in v0.21.1

func (t *Time) Set(arg string) error

func (*Time) String added in v0.21.1

func (t *Time) String() string

func (*Time) Value added in v0.21.1

func (t *Time) Value() time.Time

Value obtains the timestamp as time.Time.

Jump to

Keyboard shortcuts

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