args

package
v0.0.2-alpha Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2021 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFlagSyntax  = fmt.Errorf("invalid flag format. E.g. --name:s, --name:i:f")
	ErrAllowFormat = fmt.Errorf("only i, f, s, b, a format is allowed")
	ErrVarSyntax   = fmt.Errorf("variable flag must start with --")
)

Functions

This section is empty.

Types

type Builder

type Builder interface {
	io.Reader
	Name(n, shortDesc string, aliases ...string)
	Usage(s string)
	Description(s string)
	Flag(flag []*Flag, t reflect.Type)
	FlagVisitor(fn func(fw FlagWriter))
	Example(s, topAnchor string)
	String() string
}

func NewConsoleBuilder

func NewConsoleBuilder() Builder

func NewMarkdownBuilder

func NewMarkdownBuilder() Builder

type Flag

type Flag struct {
	Short       string // single character, e.g. -e, -e
	Long        string // more 2 character, e.g. --name or -name
	Description string
}

func (*Flag) Set

func (flag *Flag) Set(fname string, field reflect.Value, val string, nextArg interface{}, nextArgKind reflect.Kind) (advance bool, err error)

type FlagWriter

type FlagWriter func(maxFlagSize int, short, long, defaultVal, description string)

type Flags

type Flags struct {
	FuncName    string
	Aliases     []string
	Flags       []*Flag
	Result      reflect.Type
	Example     string
	Usage       string
	ShortDesc   string
	Description string
}

func (*Flags) Help

func (flags *Flags) Help(md bool, topAnchor string) string

func (*Flags) HelpAsReader

func (flags *Flags) HelpAsReader(md bool, topAnchor string) io.Reader

func (*Flags) HelpFlagVisitor

func (Flags *Flags) HelpFlagVisitor(md bool, topAnchor string, fn func(fw FlagWriter)) io.Reader

func (*Flags) Parse

func (flags *Flags) Parse(args []string) (interface{}, error)

func (*Flags) ParseFunctionArgs

func (flags *Flags) ParseFunctionArgs(args []*FunctionArg) (interface{}, error)

ParseFlagFunction return a pointer to a struct result if no error occurred. Unlike Parse which accept slice of string, `ParseFlagFunction` accept a slice of interface value (any value), in order to avoid parsing back and forth between string and numeric value. When args values is all strings then `ParseFlagFunction` is behave exactly as `Parse` method

func (*Flags) Validate

func (flags *Flags) Validate() error

type FunctionArg

type FunctionArg struct {
	Val  interface{}
	Kind reflect.Kind
}

type FunctionMeta

type FunctionMeta struct {
	Name     string
	Redirect string
	Files    []string
	Args     []*FunctionArg
}

type MainOptions

type MainOptions struct {
	Cookfile string
	Targets  []string
	Args     map[string]interface{}
	FuncMeta *FunctionMeta
	IsHelp   bool
}

func ParseMainArgument

func ParseMainArgument(args []string) (*MainOptions, error)

type Redirect

type Redirect uint8

Jump to

Keyboard shortcuts

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