boa

package module
v0.0.0-...-5e39605 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2024 License: MIT Imports: 10 Imported by: 9

Documentation

Index

Constants

View Source
const (
	ZeroOrMore = -99  // variable number of args but all are optional
	OneOrMore  = -100 // variable number of args but at least one is required
	OneOrNone  = -1   // fixed number of params but none are required
)

Optional parameters are designated via negative numbers. A command with 2 parameters will use a ParamCount of 2 if required or -2 if optional. Optional parameters are used if a default parameter is defined or if an empty string is acceptable Passing 0 parameters when 1 or more are required results in an error Using the list-end sentinel value of '--' is necessary unless the cmd is at the last one. |== lets boa know the expected param is missing Example: app --test -- more=more another // requires a param but has a default

Variables

This section is empty.

Functions

func AppDataName

func AppDataName() string

func CollectItemsFromJSON

func CollectItemsFromJSON(jsonBytes []byte) (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 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 FromJSON

func FromJSON(json []byte, 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 {
	Id           int // use as index to sort the items in as read order
	Name         string
	Alias        string
	ParamType    ParameterType
	ParamCount   int // -100 means 1 or more are required, -99 is 0 or more
	ShortHelp    string
	LongHelp     string
	Errors       []error
	Value        interface{} // string values taken from command line may be converted to any type
	DefaultValue string      // string because all values are taken off the command line as strings

	IsDefault   bool
	IsFlag      bool
	IsExclusive bool
	IsParamOpt  bool
	IsRequired  bool
	IsDeleted   bool

	RunCode string // the boa-gui tool uses this field for code generation
	ParName string
	ChNames []string
}

func NewCmdLineItem

func NewCmdLineItem() *CmdLineItem

func (CmdLineItem) Error

func (c CmdLineItem) Error() string

func (*CmdLineItem) SetError

func (c *CmdLineItem) SetError(err error)

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 valid Boa json input"
	BeWrongFileFormat
	//"cannot read input script %s"
	BeFileReadError
	// "unsupported argument type"
	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 not 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 (c ParseErrCode) String() string

type ParseError

type ParseError struct {
	Code ParseErrCode
	Err  error
}

func Errorf

func Errorf(code ParseErrCode, 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