cli

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Short flag name struct tag.
	ShortNameTag = "short"

	// Long flag name struct tag.
	LongNameTag = "long"

	// Usage flag struct tag.
	UsageTag = "usage"

	// Required flag struct tag.
	RequiredTag = "required"

	// Default value struct tag.
	DefaultTag = "default"
)

Variables

This section is empty.

Functions

func Unmarshaler

func Unmarshaler(dec *strdecode.Decoder) func(dst reflect.Value, typ reflect.Type, src []string) error

Unmarshaler returns a default Decoder unmarshaling func implementation based on given strdecode.Decoder instance.

Types

type Flag

type Flag struct {
	// Short is the short-form flag name, parsed from CLI flags prefixed by '-'.
	Short string

	// Long is the long-form flag name, parsed from CLI flags prefixed by '--'.
	Long string

	// Usage is the description for this CLI flag, used when generating usage string.
	Usage string

	// Required specifies whether this flag is required, if so returning error.
	Required bool

	// Default is the default value for this CLI flag, used when no value provided.
	Default string

	// Values contains raw value strings populated during parse stage.
	Values []string
	// contains filtered or unexported fields
}

func NewFlag

func NewFlag(dst interface{}, short, long string, value string, usage string) Flag

NewFlag ...

func (Flag) AppendUsage

func (f Flag) AppendUsage(b []byte) []byte

AppendUsage will append (new-line terminated) usage information for flag to b.

func (Flag) Name

func (f Flag) Name() string

Name ...

type FlagSet

type FlagSet struct {
	// Flags should contain possible flags to be searched for when parsing CLI args.
	Flags Flags

	// Unmarshal should unmarshal possible CLI argument value slice into 'dst'. Note
	// that for singular values len = 1, if flag was provided with no value len = 0.
	Unmarshal func(dst reflect.Value, typ reflect.Type, src []string) error
}

func (*FlagSet) Bool

func (set *FlagSet) Bool(short, long string, value bool, usage string, required bool) *bool

func (*FlagSet) BoolVar

func (set *FlagSet) BoolVar(ptr *bool, short, long string, value bool, usage string, required bool)

func (*FlagSet) Bytes

func (set *FlagSet) Bytes(short, long string, value []byte, usage string, required bool) *[]byte

func (*FlagSet) BytesVar

func (set *FlagSet) BytesVar(ptr *[]byte, short, long string, value []byte, usage string, required bool)

func (*FlagSet) Float

func (set *FlagSet) Float(short, long string, value float64, usage string, required bool) *float64

func (*FlagSet) FloatVar

func (set *FlagSet) FloatVar(ptr *float64, short, long string, value float64, usage string, required bool)

func (*FlagSet) Int

func (set *FlagSet) Int(short, long string, value int, usage string, required bool) *int

func (*FlagSet) Int64

func (set *FlagSet) Int64(short, long string, value int64, usage string, required bool) *int64

func (*FlagSet) Int64Var

func (set *FlagSet) Int64Var(ptr *int64, short, long string, value int64, usage string, required bool)

func (*FlagSet) IntVar

func (set *FlagSet) IntVar(ptr *int, short, long string, value int, usage string, required bool)

func (*FlagSet) Parse

func (set *FlagSet) Parse(args []string) (unknown []string, err error)

Parse ... will parse value strings from CLI arguments slice, storing in the Decoder before call to Decode(). Returns unrecognized arguments.

func (*FlagSet) ParseStrict

func (set *FlagSet) ParseStrict(args []string) error

ParseStrict will perform .Parse() but return error in the case that unknown arguments are returned.

func (*FlagSet) String

func (set *FlagSet) String(short, long string, value string, usage string, required bool) *string

func (*FlagSet) StringVar

func (set *FlagSet) StringVar(ptr *string, short, long string, value string, usage string, required bool)

func (*FlagSet) StructFields

func (set *FlagSet) StructFields(dst interface{})

func (*FlagSet) Uint

func (set *FlagSet) Uint(short, long string, value uint, usage string, required bool) *uint

func (*FlagSet) Uint64

func (set *FlagSet) Uint64(short, long string, value uint64, usage string, required bool) *uint64

func (*FlagSet) Uint64Var

func (set *FlagSet) Uint64Var(ptr *uint64, short, long string, value uint64, usage string, required bool)

func (*FlagSet) UintVar

func (set *FlagSet) UintVar(ptr *uint, short, long string, value uint, usage string, required bool)

func (*FlagSet) Validate

func (set *FlagSet) Validate() error

Validate will check over receiving set Flags for valid flag short/long names and conflicts.

func (*FlagSet) Var

func (set *FlagSet) Var(dst interface{}, short, long, value, usage string, required bool)

type Flags

type Flags []Flag

Flags provides helpful methods for a slice of flags.

func (Flags) AppendUsage

func (f Flags) AppendUsage(b []byte) []byte

AppendUsage will call .AppendUsage() for each contained Flag and return accumulated bytes.

func (Flags) GetLong

func (f Flags) GetLong(name string) int

GetLong will fetch the flag index with matching long name, or -1.

func (Flags) GetShort

func (f Flags) GetShort(name string) int

GetShort will fetch the flag index with matching short name, or -1.

func (Flags) Sort

func (f Flags) Sort()

Sort will alphabetically sort receiving Flags.

func (Flags) Usage

func (f Flags) Usage() string

Usage will generate an accumulated usage string for all of the contained Flags.

type InvalidFlagError

type InvalidFlagError struct {
	Name string
	Type string
	Msg  string
}

InvalidFlagError encapsulates error information regarding an invalid flag when calling cli.Flags{}.Validate().

func (*InvalidFlagError) Error

func (err *InvalidFlagError) Error() string

Jump to

Keyboard shortcuts

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