argparser

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2021 License: MIT Imports: 7 Imported by: 0

README

Arg Parser

Documentation

Index

Constants

View Source
const (
	NoneTypeStr   = "None"
	BoolTypeStr   = "bool"
	StringTypeStr = "string"
	UInt8TypeStr  = "uint8"
	UInt16TypeStr = "uint16"
	UInt32TypeStr = "uint32"
	UInt64TypeStr = "uint64"
	Int8TypeStr   = "int8"
	Int16TypeStr  = "int16"
	Int32TypeStr  = "int32"
	Int64TypeStr  = "int64"
)
View Source
const (
	TrueHlc  = "true"
	YesHlc   = "yes"
	OnHlc    = "on"
	FalseHlc = "false"
	NoHlc    = "no"
	OffHlc   = "off"
)

common and global hlcs.

Variables

This section is empty.

Functions

func ToBoolType

func ToBoolType(value string) (v, isBool bool)

Types

type EventArgs

type EventArgs struct {
	// contains filtered or unexported fields
}

func ParseArg

func ParseArg(text string) (e *EventArgs, err error)

ParseArg will parse the whole text into an EventArg and will return it.

func (*EventArgs) GetAsBool

func (e *EventArgs) GetAsBool(name ...string) bool

GetAsString will give you the boolean value of the flag with the specified name. if there is no flag with this name, or there is an error on our path, it will return you false.

func (*EventArgs) GetAsInteger

func (e *EventArgs) GetAsInteger(name ...string) (vI int64, ok bool)

GetAsString will give you the integer value of the flag with the specified name. if there is no flag with this name, or there is an error on our path, it will return you zero and false.

func (*EventArgs) GetAsString

func (e *EventArgs) GetAsString(name ...string) string

GetAsString will give you the string value of the flag with the specified name. if there is no flag with this name, or there is an error on our path, it will return you an empty string.

func (*EventArgs) GetAsStringOrRaw

func (e *EventArgs) GetAsStringOrRaw(name ...string) string

GetAsStringOrRaw will give you the string value of the flag with the specified name. if there is no flag with this name, or there is an error on our path, it will return you the raw data in the EventArgs struct.

func (*EventArgs) GetAsStringT

func (e *EventArgs) GetAsStringT(name ...string) string

GetAsStringT's functionality is exactly like GetAsString, but it will also trim the spaces, so you can use a pure string. please consider that using this method is somehow dangerous and the usage is for places like toLang in wotoTranslation package.

func (*EventArgs) GetAsStringTOrRaw

func (e *EventArgs) GetAsStringTOrRaw(name ...string) string

GetAsStringTOrRaw's functionality is exactly like GetAsString, but it will also trim the spaces, so you can use a pure string. please consider that using this method is somehow dangerous and the usage is for places like toLang in wotoTranslation package. if the value is empty, it will return the raw data.

func (*EventArgs) GetCommand

func (e *EventArgs) GetCommand() string

---------------------------------------------------------

func (*EventArgs) GetFlag

func (e *EventArgs) GetFlag(names ...string) *Flag

func (*EventArgs) GetFlags

func (e *EventArgs) GetFlags() []Flag

func (*EventArgs) GetIndexFlag

func (e *EventArgs) GetIndexFlag(index int) *Flag

func (*EventArgs) GetLength

func (e *EventArgs) GetLength() int

func (*EventArgs) HasFlag

func (e *EventArgs) HasFlag(names ...string) bool

HasFlag will check if this EventArgs has at least one the provided flags or not. please notice that if you want to check if it has ALL of the flags, use `HasFlags` method.

func (*EventArgs) HasFlags

func (e *EventArgs) HasFlags(names ...string) bool

HasFlag will check if this EventArgs has ALL of the provided flags or not. please notice that if you want to check if it has at least one of the flags, use `HasFlag` method.

func (*EventArgs) IsEmpty

func (e *EventArgs) IsEmpty() bool

func (*EventArgs) IsEmptyOrRaw

func (e *EventArgs) IsEmptyOrRaw() bool

type Flag

type Flag struct {
	// contains filtered or unexported fields
}

Flag is the options passed along with the commands by users. they should send them with prefex "--", but we will remove them in the argparser.

func (*Flag) GetAsBool

func (f *Flag) GetAsBool() bool

func (*Flag) GetAsInteger

func (f *Flag) GetAsInteger() (vI int64, ok bool)

GetAsInteger will give the value of this flag as an int64 value. please notice that if it fails to convert the value to int64, it will return you zero and the second return value will be false.

func (*Flag) GetAsString

func (f *Flag) GetAsString() string

GetAsString will give you the value as an string. for example if value is `true` (with flag type of `bool`), then the string will be "true". or if it's 10(an integer), it will give you: "10".

func (*Flag) GetIndex

func (f *Flag) GetIndex() int

GetIndex will return the index of this flag.

func (*Flag) GetName

func (f *Flag) GetName() string

GetName will give you the name of this flag.

func (*Flag) GetType

func (f *Flag) GetType() FlagType

GetType will return the type of the value of this flag. please notice that if you don't enter any value for this flag, it will be considered as `true` (which is type bool).

func (*Flag) GetValue

func (f *Flag) GetValue() interface{}

GetValue will return you the value of this flag. remember that value can be

func (*Flag) GetValueAndType

func (f *Flag) GetValueAndType() (interface{}, FlagType)

type FlagType

type FlagType uint8
const (
	NoneFlagType   FlagType = iota
	BoolFlagType   FlagType = iota + 1
	StringFlagType FlagType = iota + 2
	UInt8FlagType  FlagType = iota + 3
	UInt16FlagType FlagType = iota + 4
	UInt32FlagType FlagType = iota + 5
	UInt64FlagType FlagType = iota + 6
	Int8FlagType   FlagType = iota + 7
	Int16FlagType  FlagType = iota + 8
	Int32FlagType  FlagType = iota + 9
	Int64FlagType  FlagType = iota + 10
)

func (*FlagType) Compare

func (t *FlagType) Compare(value *FlagType) bool

func (*FlagType) IsInteger

func (t *FlagType) IsInteger() bool

func (*FlagType) ToString

func (t *FlagType) ToString() string

type Hlc

type Hlc struct {
	Name  string
	Value interface{}
	Type  FlagType
}

High-level constant.

type HlcCollection

type HlcCollection []Hlc

func GetHlcCollection

func GetHlcCollection(h ...Hlc) HlcCollection

func (*HlcCollection) Contains

func (c *HlcCollection) Contains(name string) bool

func (*HlcCollection) GetValue

func (c *HlcCollection) GetValue(name string) (interface{}, FlagType)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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