chad

package
v0.0.0-...-a013e18 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Arg

type Arg struct {
	Name, Help   string
	DefaultValue interface{}
	Required     bool
}

A datastructure representing a defined argument. Used in the validation step.

func NewArg

func NewArg(name, help string, defaultValue interface{}, required bool) *Arg

type Chad

type Chad struct {
	DefinedFlags            map[string]Arg
	Result                  *parse.ParseResult
	ExpectedPositionalCount int
	PositionalNames         []string
	// contains filtered or unexported fields
}

A datastructure representing a true Chad. The Chad holds all important data for validation and parsed results after validation.

func NewChad

func NewChad() *Chad

Usage:

chad := chad.NewChad()
chad.RegisterArgs(
	[]chad.Arg{ // These are our arguments.
		*chad.NewArg("file", "The file to be read", "default_filename", true),
	},
	0, // The number of positional arguments we expect.
)
chad.Parse() // or any other parse<...> function.

Before parsing anything, you have to register the arguments for the validation process to be able to execute.

func (*Chad) BoolFlag

func (slf *Chad) BoolFlag(key string) bool

Check if a flag is supplied, synonymous to Chad.IsFlagPresent(key)

func (*Chad) FloatFlag

func (slf *Chad) FloatFlag(key string) float64

Get a flag's value by its name in form of a float64

func (*Chad) FloatIndex

func (slf *Chad) FloatIndex(idx int) float64

Get a positional value my its index in form of a float64

func (*Chad) FloatPosName

func (slf *Chad) FloatPosName(name string) float64

Get a positional value my its name in form of a float64

func (*Chad) IntFlag

func (slf *Chad) IntFlag(key string) int

Get a flag's value by its name in form of an int

func (*Chad) IntIndex

func (slf *Chad) IntIndex(idx int) int

Get a positional value my its index in form of an int

func (*Chad) IntPosName

func (slf *Chad) IntPosName(name string) int

Get a positional value my its name in form of an int

func (*Chad) IsFlagDefault

func (slf *Chad) IsFlagDefault(key string) bool

Check if a flag retained its default value.

func (*Chad) IsFlagPresent

func (slf *Chad) IsFlagPresent(key string) bool

Check if a flag is present in the parsed arguments.

func (*Chad) Parse

func (slf *Chad) Parse()

Parse from os.Args

func (*Chad) ParseFromSlice

func (slf *Chad) ParseFromSlice(input []string)

Parse from an input string slice

func (*Chad) ParseFromString

func (slf *Chad) ParseFromString(input string)

Parse from an input string

func (*Chad) RegisterArgs

func (slf *Chad) RegisterArgs(args []Arg, positionalNames []string)

Register the arguments to be parsed. This allows for the validation of the arguments.

func (*Chad) StringFlag

func (slf *Chad) StringFlag(key string) string

Get a flag's value by its name in form of a string

func (*Chad) StringIndex

func (slf *Chad) StringIndex(idx int) string

Get a positional value my its index in form of a string

func (*Chad) StringPosName

func (slf *Chad) StringPosName(name string) string

Get a positional value my its name in form of a string

Jump to

Keyboard shortcuts

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