Documentation
¶
Overview ¶
Package sflag is an simple cli flag parse tool
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ArgsParser ¶
type ArgsParser struct {
// BoolOpts bool option names. list all bool value options.
// eg. "--debug -h" -> []string{"debug", "h"}
BoolOpts []string
// ArrayOpts array option names. list all array value options.
// eg. "--name tom --name john" should add []string{"name"}
ArrayOpts []string
// contains filtered or unexported fields
}
ArgsParser definition. a simple command line args parser
func ParseArgs ¶
func ParseArgs(args []string, boolOpts []string, arrayOpts []string) *ArgsParser
ParseArgs parse os.Args to options.
func (*ArgsParser) OptsString ¶
func (p *ArgsParser) OptsString() string
OptsString convert all options to string
func (*ArgsParser) Parse ¶
func (p *ArgsParser) Parse(args []string)
Parse args list to options
Supports options format:
-e // bool, short option -e <value> // short option -e=<value> -aux // multi short bool options --bool-opt // bool, lang option --long-opt <value> // lang option --long-opt=<value>
type Arguments ¶
type Arguments struct {
// contains filtered or unexported fields
}
Arguments definition
type Option ¶
type Option struct {
Name string
Short string
// Type value type. allow: int, string, bool, ints, strings, bools, custom
Type string
// Value of the option. allow: bool, string, slice(ints, strings)
Value interface{}
// refer flag.Value interface
Setter func(string) error
Required bool
DefValue interface{}
// Description
Description string
}
Option is config info for a option Usage:
cmd.AddOpt(Option{
Name: "name"
Short: "n"
DType: "string"
})
cmd.Flags.String()
type Options ¶
type Options struct {
// contains filtered or unexported fields
}
Options the values for parsed arguments and options
type ValueGetter ¶
type ValueGetter struct {
// value store parsed argument data. (type: string, []string)
Value interface{}
// is array
IsArray bool
}
ValueGetter struct
func (*ValueGetter) Array ¶
func (v *ValueGetter) Array() (ss []string)
Array alias of the Strings()
func (*ValueGetter) String ¶
func (v *ValueGetter) String(defVal ...string) string
String argument value to string
func (*ValueGetter) Strings ¶
func (v *ValueGetter) Strings() (ss []string)
Strings value to string slice, if argument isArray = true.
Click to show internal directories.
Click to hide internal directories.