Anter

package module
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2025 License: MIT Imports: 6 Imported by: 0

README

Anter

Go argument parser

Documentation

Index

Constants

View Source
const (
	FTYPE_UNKNOWN = iota /* It is used to indicate an error */
	FTYPE_BOOL           /* It means that the flag didn't expect any value */
	FTYPE_VALUE          /* It specifies that the flag expect a value */
)

LFlag.tp

View Source
const (
	F_SINGLE_DASHED = 1 << iota //TODO: Add support for shorthand flags
	F_DOUBLE_DASHED
	F_CONCAT

	F_DEFAULT_FLAG = 3
)

LFlag.flag

View Source
const (
	ARGTP_EOA = iota
	ARGTP_COMMAND
	ARGTP_FLAG
	ARGTP_VALUE
	ARGTP_BINPATH

	ARGTP_UNKNOWN = -1
	ARGF_NONE     = -1
)

Arg type: "--flag" -> flag "new" -> Command "--flag=value" | "--flag value" -> value

View Source
const (
	NO_COLOR_ASCII_CODE = "\033[0m"
	BLACK_ASCCI_CODE    = "\033[0;30m"
	RED_ASCII_CODE      = "\033[0;31m"
	GREEN_ASCII_CODE    = "\033[0;32m"
	YELLOW_ASCII_CODE   = "\033[0;33m"
	BLUE_ASCII_CODE     = "\033[0;34m"
	MAGENTA_ASCII_CODE  = "\033[0;35m"
	CYAN_ASCCI_CODE     = "\033[0;36m"
	WHITE_ASCCI_CODE    = "\033[0;37m"
)

Variables

This section is empty.

Functions

func ArgtpToString

func ArgtpToString(tp int) string

TODO: This function should be a part of the Arg structure

func BlackTxt

func BlackTxt(txt string) string

func BlueTxt

func BlueTxt(txt string) string

func CyanTxt

func CyanTxt(txt string) string

func Err

func Err(msg string) error

func ErrF

func ErrF(format string, n ...any) error

func GreenTxt

func GreenTxt(txt string) string

func InitLib

func InitLib(com []string, fls []LFlag) error

** Mandatory ** This is the first function to be called to

Init the library

func MagentaTxt

func MagentaTxt(txt string) string

func RedTxt

func RedTxt(txt string) string

func SErrF

func SErrF(format string, n ...any) string

func Unimpl

func Unimpl(msg string)

func UnimplFunc

func UnimplFunc(f string)

func UnwrapStrFlag

func UnwrapStrFlag(flag string) string

TODO: add support for single dashed flag:

"-h"	->	"h" | "help"

This function remove the flag header ("--" | "-") from the provided string and returns the result

func WhiteTxt

func WhiteTxt(txt string) string

func YellowTxt

func YellowTxt(txt string) string

Types

type Anter

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

func AnalArg

func AnalArg() (Anter, error)

This function analise the argv from os.Argv and stores the info in the Anter structure

func (*Anter) GetCom added in v0.8.0

func (an *Anter) GetCom() Arg

It return the first command that occured An EOA Arg is return if it wasn't present

func (*Anter) GetFlagBool

func (an *Anter) GetFlagBool(flag string) (bool, error)

The 'flag' can be passed like "--flag" | "flag" Return true if the flag was provided false if it wasn't provided or due to an error

func (*Anter) GetFlagFloat

func (an *Anter) GetFlagFloat(flag string, base int) (float64, error)

The flag can be provided like "--flag" | "flag"

func (*Anter) GetFlagFloat32

func (an *Anter) GetFlagFloat32(flag string) (float32, error)

The flag can be provided like "--flag" | "flag"

func (*Anter) GetFlagFloat64

func (an *Anter) GetFlagFloat64(flag string) (float64, error)

The flag can be provided like "--flag" | "flag"

func (*Anter) GetFlagInt

func (an *Anter) GetFlagInt(flag string, bitSize int) (int64, error)

The flag can be provided like "--flag" | "flag"

func (*Anter) GetFlagInt16

func (an *Anter) GetFlagInt16(flag string) (int16, error)

The flag can be provided like "--flag" | "flag"

func (*Anter) GetFlagInt32

func (an *Anter) GetFlagInt32(flag string) (int32, error)

The flag can be provided like "--flag" | "flag"

func (*Anter) GetFlagInt64

func (an *Anter) GetFlagInt64(flag string) (int64, error)

The flag can be provided like "--flag" | "flag"

func (*Anter) GetFlagInt8

func (an *Anter) GetFlagInt8(flag string) (int8, error)

The flag can be provided like "--flag" | "flag"

func (*Anter) GetFlagString

func (an *Anter) GetFlagString(flag string) (string, error)

This function gets the flag value if it was a valuable flag and returns it The flag can be provided like "--flag" | "flag"

func (*Anter) GetFlagUInt

func (an *Anter) GetFlagUInt(flag string, base int) (uint64, error)

The flag can be provided like "--flag" | "flag"

func (*Anter) GetFlagUInt16

func (an *Anter) GetFlagUInt16(flag string) (uint16, error)

The flag can be provided like "--flag" | "flag"

func (*Anter) GetFlagUInt32

func (an *Anter) GetFlagUInt32(flag string) (uint32, error)

The flag can be provided like "--flag" | "flag"

func (*Anter) GetFlagUInt64

func (an *Anter) GetFlagUInt64(flag string) (uint64, error)

The flag can be provided like "--flag" | "flag"

func (*Anter) GetFlagUInt8

func (an *Anter) GetFlagUInt8(flag string) (uint8, error)

The flag can be provided like "--flag" | "flag"

func (*Anter) GetFlagValue

func (an *Anter) GetFlagValue(SFlag string) (string, error)

For boolean flag it return TRUE | FALSE based on

if the flag was provied or not

For valuable flag it returns the value if

given or an error

If the flag was not provided during initialization it return an error If the flag was not given by the user it returns an error

func (*Anter) IsComPresent_Str added in v0.8.0

func (an *Anter) IsComPresent_Str(com string) bool

TODO? shall we call this function without the _Str suffix? It checks if the provided command (as a string) was given by the user

type AnterIter added in v0.9.0

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

func NewIter added in v0.9.0

func NewIter(an *Anter) AnterIter

Creates a new simple Argument Iterator

func (*AnterIter) Get added in v0.9.0

func (ai *AnterIter) Get() Arg

It gets the current argument If there are no more arguments it returns an EOA Arg

func (*AnterIter) GetNext added in v0.10.0

func (ai *AnterIter) GetNext() Arg

If exist return the next arg otherwise it returns an EOA arg. Use Arg.IsEOA() to see if so

func (*AnterIter) Next added in v0.9.0

func (ai *AnterIter) Next() bool

Goes to the next argument if exist Returns false if there is no other

type Arg

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

func (*Arg) AIdx added in v0.8.0

func (arg *Arg) AIdx() int

Warning the returned idx doesn't always mean that the specified argument is in os.Arg[a_indx]

func (*Arg) IsBinPath added in v0.8.0

func (arg *Arg) IsBinPath() bool

func (*Arg) IsCom added in v0.8.0

func (arg *Arg) IsCom() bool

func (*Arg) IsEOA added in v0.8.0

func (arg *Arg) IsEOA() bool

func (*Arg) IsFlag added in v0.8.0

func (arg *Arg) IsFlag() bool

func (*Arg) IsValidType added in v0.8.0

func (arg *Arg) IsValidType() bool

An invalid type is any argument that has his type == ARGTP_UNKNOWN

func (*Arg) IsValue added in v0.8.0

func (arg *Arg) IsValue() bool

func (*Arg) RIdx added in v0.8.0

func (arg *Arg) RIdx() int

If the arg is a flag or a command this return the index of the flag | command in the array that was provided with the function 'InitLib'

func (*Arg) Str added in v0.8.0

func (arg *Arg) Str() string

func (*Arg) Type added in v0.8.0

func (arg *Arg) Type() int

type LFlag

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

func NewDefFlag added in v0.10.0

func NewDefFlag(name string, tp int) LFlag

like NewFlag but flag = F_DEFAULT_FLAG

func NewFlag added in v0.10.0

func NewFlag(name string, tp, flag int) LFlag

-name whould be provided without any dashes -tp indicates the flag type:

[-] FTYPE_VALUE	-> Expects a value after the flag
[-] FTYPE_BOOL		-> It is used to activate a flag

- flag indicates some other flag for the flag [You can use the F_DEFAULT_FLAG to activate default flags]

Jump to

Keyboard shortcuts

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