flags

package
v3.3.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package flag provides extended support for flag parsing. It uses the standard flag package underneath but adds automatic flag registration from structures, more types of flags, and some support funcitons for adding more flag types.

Index

Constants

View Source
const (
	// FullHelpFlag is the name of the flag used to show the full help.
	FullHelpFlag = "fullhelp"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Choice

type Choice interface {
	String() string
}

Choice is the interface to something that represents a value for an enumerated type.

type Choices

type Choices []Choice

Choices is a slice of Enum values for a given type.

func (Choices) Len

func (c Choices) Len() int

Len returns the number of choices available.

func (Choices) Less

func (c Choices) Less(i, j int) bool

Less can be used to form a total ordering of the choices by their name.

func (Choices) String

func (c Choices) String() string

String returns the full set of options as a comma delimited string.

func (Choices) Swap

func (c Choices) Swap(i, j int)

Swap does an in place swap of two items on the page.

type Choosable

type Choosable interface {
	// Chooser returns a Chooser object that can be used to select values for the implementing type.
	Chooser() Chooser
}

Choosable is the interface to type that can return a chooser for itself. Anything that implements Choosable is direclty usesable as a flag value.

type Chooser

type Chooser struct {
	// Value is the value we are choosing for.
	Value Enum
	// Choices is the full set of choices available.
	Choices Choices
}

Chooser is is used to select from amongst a set of choices. It conforms to the flag.Value interface.

func ForEnum

func ForEnum(v Enum) Chooser

ForEnum automatically builds a Chooser for a 0 based sequential enumerated integer type up to 1000. It expects that the values will all have names from the first to the last, starting at 0, and that after the end of the valid range the string method for the type will either return the empty string or strconv.Itoa of the base value.

func (Chooser) Set

func (c Chooser) Set(value string) error

Set chooses the choice that matches the string.

func (Chooser) String

func (c Chooser) String() string

String returns the string form of the current value.

type Enum

type Enum interface {
	// String represents the current value in a string form, used for choice matching.
	String() string
	// Choose is handed a value to set from the Choices list for the enum.
	Choose(interface{})
}

Enum is the interface to a enumerated value. Anything that implements Enum is direclty usesable as a flag value.

type Set

type Set struct {
	// Raw is the underlying flag set
	// TODO: hide this once we stop things relying on it
	Raw flag.FlagSet
}

func (*Set) Args

func (s *Set) Args() []string

Args returns the unprocessed part of the command line passed to Parse.

func (*Set) Bind

func (s *Set) Bind(name string, value interface{}, help string)

Bind uses reflection to bind flag values to the verb. It will recurse into nested structures adding all leaf fields.

func (*Set) ForceCommandLine

func (s *Set) ForceCommandLine()

ForceCommandLine is an ugly hack for things that try to directly use the flag package TODO: remove this

func (*Set) HasVisibleFlags

func (s *Set) HasVisibleFlags(verbose bool) bool

HasVisibleFlags returns true if the set has bound flags for the specified verbosity.

func (*Set) Parse

func (s *Set) Parse(fullHelp *bool, args ...string)

Parse processes the args to fill in the flags. see flag.Parse for more details.

func (*Set) Usage

func (s *Set) Usage(verbose bool) string

Usage returns the usage string for the flags.

type StringSlice

type StringSlice []string

func (*StringSlice) Set

func (i *StringSlice) Set(v string) error

func (*StringSlice) String

func (i *StringSlice) String() string

type U64Slice

type U64Slice []uint64

func (*U64Slice) Set

func (i *U64Slice) Set(v string) error

func (*U64Slice) String

func (i *U64Slice) String() string

type URL

type URL struct {
	url.URL
}

URL implements flag.Value for a url.URL flag.

func (*URL) Set

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

Jump to

Keyboard shortcuts

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