argparser

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2024 License: MIT Imports: 4 Imported by: 1

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

View Source
var (
	DefaultPrefixes = []rune{
		'/',
		'!',
	}
)

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, prefixes []rune) (e *EventArgs, err error)

func ParseArgDefault

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

func ParseArgWithOptions added in v1.0.6

func ParseArgWithOptions(text string, options *ParseOptions) (e *EventArgs, err error)

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

func (*EventArgs) CheckCommand

func (e *EventArgs) CheckCommand(cmd string) bool

CheckCommand will compare the command of this event arg with the given command. This function is case insensitive, if you want to compare it case sensitive, then use CompareCommand method.

func (*EventArgs) CompareCommand

func (e *EventArgs) CompareCommand(cmd string) bool

CompareCommand will compare the command of this event arg with the given command. This function is case sensitive, if you want to compare it case insensitive, then use CheckCommand method.

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) GetAsIntegerOrRaw

func (e *EventArgs) GetAsIntegerOrRaw(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) GetCommand

func (e *EventArgs) GetCommand() string

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

func (*EventArgs) GetFirstNoneEmptyValue

func (e *EventArgs) GetFirstNoneEmptyValue() 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

func (*EventArgs) HasFlags

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

func (*EventArgs) HasRawData

func (e *EventArgs) HasRawData() bool

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 prefix "--", but we will remove them in the pTools.

func (*Flag) GetAsBool

func (f *Flag) GetAsBool() bool

func (*Flag) GetAsInteger

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

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 you the index of this flag. index of a flag is a unique int. even if the name of two flags are the same, their index will not be the same.

func (*Flag) GetName

func (f *Flag) GetName() string

GetName will give you the name of this flag. it's not unique actually. for example:

`/command --test "hello" --test = "HI!"

func (*Flag) GetType

func (f *Flag) GetType() FlagType

GetType will return you the type of the value this flag. it's an enum.

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)

GetValueAndType returns both value and type of this flag. originally it has internal usage, but maybe you want to use it in your own package, so I made it public!

type FlagType

type FlagType uint8
const (
	NoneFlagType FlagType = iota
	BoolFlagType
	StringFlagType
	UInt8FlagType
	UInt16FlagType
	UInt32FlagType
	UInt64FlagType
	Int8FlagType
	Int16FlagType
	Int32FlagType
	Int64FlagType
)

func (*FlagType) Compare

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

func (*FlagType) IsInteger

func (t *FlagType) IsInteger() bool

func (*FlagType) IsString

func (t *FlagType) IsString() bool

func (*FlagType) ToString

func (t *FlagType) ToString() string

type ParseOptions added in v1.0.6

type ParseOptions struct {
	Prefixes []rune
}

func GetDefaultParseOptions added in v1.0.6

func GetDefaultParseOptions() *ParseOptions

Jump to

Keyboard shortcuts

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