Documentation ¶
Index ¶
- Constants
- func AppDataName() string
- func CollectItemsFromJSON(jsonBytes []byte) (map[string]CmdLineItem, error)
- func PrintCli(cli *CLI)
- func PrintItem(it CmdLineItem)
- func PrintMap(items map[string]CmdLineItem)
- func TypeToString(p ParameterType) string
- type CLI
- func (C *CLI) Bool(item string) (bool, bool)
- func (C *CLI) Date(item string) (time.Time, bool)
- func (C *CLI) DateSlice(item string) ([]time.Time, bool)
- func (C *CLI) Email(item string) (mail.Address, bool)
- func (C *CLI) EmailSlice(item string) ([]mail.Address, bool)
- func (C *CLI) Errors() string
- func (C *CLI) Float(item string) (float64, bool)
- func (C *CLI) FloatSlice(item string) ([]float64, bool)
- func (C *CLI) HasErrors() bool
- func (C *CLI) Help(topic string, ty ...HelpType) string
- func (C *CLI) IPv4(item string) (net.IP, bool)
- func (C *CLI) IPv4Slice(item string) ([]net.IP, bool)
- func (C *CLI) Int(item string) (int, bool)
- func (C *CLI) IntSlice(item string) ([]int, bool)
- func (C *CLI) LastError() error
- func (C *CLI) Path(item string) (string, bool)
- func (C *CLI) PathSlice(item string) ([]string, bool)
- func (C *CLI) SetError(err error)
- func (C *CLI) String(item string) (string, bool)
- func (C *CLI) StringSlice(item string) ([]string, bool)
- func (C *CLI) Time(item string) (time.Time, bool)
- func (C *CLI) TimeDuration(item string) (time.Duration, bool)
- func (C *CLI) TimeDurationSlice(item string) ([]time.Duration, bool)
- func (C *CLI) TimeSSlice(item string) ([]time.Time, bool)
- func (C *CLI) URL(item string) (url.URL, bool)
- func (C *CLI) URLSlice(item string) ([]url.URL, bool)
- type CmdLineItem
- type HelpType
- type ParameterType
- type ParseErrCode
- type ParseError
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 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 ParseCommandLineArgs ¶
func ParseCommandLineArgs(cmds map[string]CmdLineItem, args []string) *CLI
func (*CLI) TimeDurationSlice ¶
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 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
Click to show internal directories.
Click to hide internal directories.