pflagutil

package
v0.0.0-...-d280c18 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2023 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package pflagutil contains helper types and functions for the spf13/pflag and spf13/cobra packages regarding flags.

Index

Constants

This section is empty.

Variables

View Source
var TimeDefaultLayout = "Jan 02 15:04"

TimeDefaultLayout is the layout used when showing a Time flag value in the program's helper text.

Functions

func TimeRangeCompletion

func TimeRangeCompletion(*cobra.Command, []string, string) ([]string, cobra.ShellCompDirective)

TimeRangeCompletion is a completion function for the TimeRange flag type, and is meant to be registered into a Cobra command object.

Types

type Time

type Time struct {
	Now bool
	// contains filtered or unexported fields
}

Time is a pflag.Value-compatible type for allowing datetimes to be used in flags. The fuzzytime package is used to parse the user-provided flag string value.

func (*Time) Set

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

Set attempts to parse the string as a time.Time and updates its internal state on success, or returns a parsing error if it fails.

func (*Time) Source

func (t *Time) Source() string

Source returns the source string that was used to create this time.

func (*Time) String

func (t *Time) String() string

String returns a formatted string of the underlying time. If the Now field has been set, the string literal "now" is returned instead.

func (*Time) Time

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

Time returns the time.Time value. If the Now field is set, time.Now() is returned instead.

func (*Time) TimePtr

func (t *Time) TimePtr(base time.Time) *time.Time

TimePtr returns the time.Time value, or nil if the object is nil. If the Now field is set, time.Now() is returned instead.

func (*Time) Type

func (t *Time) Type() string

Type returns "time", the flag type name to be used in helper text.

type TimeRange

type TimeRange timeutil.TimeSpanShorthand

TimeRange is a pflag.Value-compatible type for allowing time span shorthand enumeration to be used in flags.

func NewTimeRangePtr

func NewTimeRangePtr(shorthand timeutil.TimeSpanShorthand) *TimeRange

NewTimeRangePtr returns a pointer to a new TimeRange instance.

func (*TimeRange) Set

func (r *TimeRange) Set(s string) error

Set attempts to parse the string as a timeutil.TimeSpanShorthand and updates its internal state on success, or returns a parsing error if it fails.

func (*TimeRange) String

func (r *TimeRange) String() string

String returns the string representation of the time range.

func (*TimeRange) TimeSpanShorthand

func (r *TimeRange) TimeSpanShorthand() timeutil.TimeSpanShorthand

TimeSpanShorthand returns the underlying timeutil value.

func (*TimeRange) Type

func (r *TimeRange) Type() string

Type returns "range", the flag type name to be used in helper text.

Jump to

Keyboard shortcuts

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