boa

package module
v0.0.0-...-cbea2ab Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2022 License: MIT Imports: 13 Imported by: 5

README

boa

Documentation

Index

Constants

View Source
const (
	Usagepat          = `^[Uu]{1}sage: `
	CommandSectionPat = `^Commands[\t ]*:`
	FlagSectionPat    = `^Flags[\t ]*:`
	MoreSectionPat    = `^More[\t ]*:`
	LongSectionPat    = `^Long Description[\t ]*:`
)

Variables

This section is empty.

Functions

func AppDataName

func AppDataName() string

func CollectItems

func CollectItems(helpstring string) (map[string]CmdLineItem, string, string)

func CollectItemsFromJSON

func CollectItemsFromJSON(jsonStr string) (map[string]CmdLineItem, error)

func PrintCli

func PrintCli(cli *CLI)

func PrintItem

func PrintItem(it CmdLineItem)

func PrintMap

func PrintMap(items map[string]CmdLineItem)

func StringFromCode

func StringFromCode(code ParseErrCode) string

func TypeToString

func TypeToString(p ParameterType) string

Types

type CLI

type CLI struct {
	Application string
	Items       map[string]CmdLineItem
	AllHelp     map[string]string
	Errs        []error
}

func FromHelp

func FromHelp(helpstring string, args []string) *CLI

func FromJSON

func FromJSON(jsonStr string, args []string) *CLI

func ParseCommandLineArgs

func ParseCommandLineArgs(cmds map[string]CmdLineItem, args []string) *CLI

func (*CLI) Bool

func (C *CLI) Bool(item string) (bool, bool)

func (*CLI) Date

func (C *CLI) Date(item string) (time.Time, bool)

func (*CLI) DateSlice

func (C *CLI) DateSlice(item string) ([]time.Time, bool)

func (*CLI) Email

func (C *CLI) Email(item string) (mail.Address, bool)

func (*CLI) EmailSlice

func (C *CLI) EmailSlice(item string) ([]mail.Address, bool)

func (*CLI) Errors

func (C *CLI) Errors() string

func (*CLI) Float

func (C *CLI) Float(item string) (float64, bool)

func (*CLI) FloatSlice

func (C *CLI) FloatSlice(item string) ([]float64, bool)

func (*CLI) HasErrors

func (C *CLI) HasErrors() bool

func (*CLI) Help

func (C *CLI) Help(topic string, ty ...HelpType) string

func (*CLI) IPv4

func (C *CLI) IPv4(item string) (net.IP, bool)

func (*CLI) IPv4Slice

func (C *CLI) IPv4Slice(item string) ([]net.IP, bool)

func (*CLI) Int

func (C *CLI) Int(item string) (int, bool)

func (*CLI) IntSlice

func (C *CLI) IntSlice(item string) ([]int, bool)

func (*CLI) LastError

func (C *CLI) LastError() error

func (*CLI) Path

func (C *CLI) Path(item string) (string, bool)

func (*CLI) PathSlice

func (C *CLI) PathSlice(item string) ([]string, bool)

func (*CLI) SetError

func (C *CLI) SetError(err error)

func (*CLI) String

func (C *CLI) String(item string) (string, bool)

func (*CLI) StringSlice

func (C *CLI) StringSlice(item string) ([]string, bool)

func (*CLI) Time

func (C *CLI) Time(item string) (time.Time, bool)

func (*CLI) TimeDuration

func (C *CLI) TimeDuration(item string) (time.Duration, bool)

func (*CLI) TimeDurationSlice

func (C *CLI) TimeDurationSlice(item string) ([]time.Duration, bool)

func (*CLI) TimeSSlice

func (C *CLI) TimeSSlice(item string) ([]time.Time, bool)

func (*CLI) URL

func (C *CLI) URL(item string) (url.URL, bool)

func (*CLI) URLSlice

func (C *CLI) URLSlice(item string) ([]url.URL, bool)

type CmdLineItem

type CmdLineItem struct {
	ParamType   ParameterType
	Value       any
	Name        string
	Alias       string
	ShortHelp   string
	LongHelp    string
	IsDefault   bool
	IsFlag      bool
	Exclusive   bool
	Required    bool
	RequiredOr  []string
	RequiredAnd []string
	ParamOpt    bool
	ParamCount  int
	Extra       string // the boa-gui tool uses this field for code generation
	Disabled    bool   // the boa-gui tool uses this field for script editing
	Id          int    // use as index to sort the items in as read order
}

type HelpType

type HelpType int
const (
	ShortStr HelpType = iota
	LongStr
	CombinedStr
)

type ParameterType

type ParameterType int
const (
	TypeBool ParameterType = iota
	TypeString
	TypeStringSlice
	TypeInt
	TypeIntSlice
	TypeFloat
	TypeFloatSlice
	TypeTime
	TypeTimeSlice
	TypeTimeDuration
	TypeTimeDurationSlice
	TypeDate
	TypeDateSlice
	TypePath
	TypePathSlice
	TypeURL
	TypeURLSlice
	TypeIPv4
	TypeIPv4Slice
	TypeEmail
	TypeEmailSlice
	TypePhone
	TypePhoneSlice
)

type ParseErrCode

type ParseErrCode int
const (
	//errors from reading input script
	BeExternalError ParseErrCode = iota
	//"expecting a file path for input script"
	BeNoFileGiven
	//"input script is not formatted as a Boa input script"
	BeWrongFileFormat
	//"cannot read input script %s"
	BeFileReadError
	//"section %s has no content at line %d"
	BeNoSectionText
	// "unsupported argument type at line %d"
	BeUnsupportedType
	//"reached end of input script"
	BeEofError
	//"line only contains meta characters"
	BeBadMetaLine
	//"meta character string is not at beginning of line"
	BeMetaNotStart
	//"command or flag in input script cannot be  parsed"
	BeNoCommandName

	//"item %s is exclusive but was found with %s"
	BeNoExclusiveItem
	//"item %s is required but was not found"
	BeNoRequiredItem
	//"command or flag passed on command line is not recognized"
	BeInvalidCommand
	//"argument for %s not found"
	BeNoRequiredString
	//"integer argument for %s not found"
	BeNoRequiredInt
	//"real number argument for %s not found"
	BeNoRequiredFloat
	//"date argument for %s not found"
	BeNoRequiredDate
	// "time argument for %s not found"
	BeNoRequiredTime
	//"time duration argument for %s not found"
	BeNoRequiredDuration
	//"file path argument for %s not found"
	BeNoRequiredPath
	//"URL argument for %s not found"
	BeNoRequiredURL
	//"Email address argument for %s npt found"
	BeNoRequiredEmail
	//"Phone number argument for %s not found"
	BeNoRequiredPhone
	//"IP address argument for %s not found"
	BeNoRequiredIPv4
	//"%s, argument for %s, cannot be interpreted as a boolean"
	BeNotABool
	//"%s, argument for %s, cannot be interpreted as an integer"
	BeNotAnInt
	// "%s, argument for %s, cannot be interpreted as a real number"
	BeNotAFloat
	// "argument to %s, %s is not a valid date value such as '01-01-2022'"
	BeNotADate
	//"argument to %s, %s is not a valid time value such as '3:45PM'"
	BeNotATime
	//"argument to %s, %s is not a valid duration value such as '1h10m20s'"
	BeNotADuration
	//"%s, argument for %s, cannot be interpreted as an email address"
	BeNotAnEmail
	//"%s, argument for %s, cannot be interpreted as a phone number"
	BeNotAPhone
	//"%s, argument for %s, cannot be interpreted as a file path"
	BeNotAPath
	//"%s, argument for %s, cannot be interpreted as a URL"
	BeNotAURL
	//"%s, argument for %s, cannot be interpreted as an IP address of IPv4 format"
	BeNotAnIPv4
)

func (ParseErrCode) String

func (e ParseErrCode) String() string

type ParseError

type ParseError struct {
	Code ParseErrCode
	Err  error
}

func ErrorFromCode

func ErrorFromCode(code ParseErrCode, args ...any) ParseError

func NewParseError

func NewParseError(code ParseErrCode, fmtstr string, args ...any) ParseError

func (ParseError) Error

func (e ParseError) Error() string

Jump to

Keyboard shortcuts

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