Documentation ¶
Overview ¶
Package gcmd provides console operations, like options/arguments reading and command running.
Index ¶
- func AutoRun() error
- func BindHandle(cmd string, f func()) error
- func BindHandleMap(m map[string]func()) error
- func BuildOptions(m map[string]string, prefix ...string) string
- func ContainsOpt(name string, def ...string) bool
- func GetArg(index int, def ...string) string
- func GetArgAll() []string
- func GetArgVar(index int, def ...string) *gvar.Var
- func GetOpt(name string, def ...string) string
- func GetOptAll() map[string]string
- func GetOptVar(name string, def ...string) *gvar.Var
- func RunHandle(cmd string) error
- func Scan(info ...interface{}) string
- func Scanf(format string, info ...interface{}) string
- type Parser
- func (p *Parser) AutoRun() error
- func (p *Parser) BindHandle(cmd string, f func()) error
- func (p *Parser) BindHandleMap(m map[string]func()) error
- func (p *Parser) ContainsOpt(name string) bool
- func (p *Parser) GetArg(index int, def ...string) string
- func (p *Parser) GetArgAll() []string
- func (p *Parser) GetArgVar(index int, def ...string) *gvar.Var
- func (p *Parser) GetOpt(name string, def ...string) string
- func (p *Parser) GetOptAll() map[string]string
- func (p *Parser) GetOptVar(name string, def ...interface{}) *gvar.Var
- func (p *Parser) MarshalJSON() ([]byte, error)
- func (p *Parser) RunHandle(cmd string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AutoRun ¶ added in v1.9.1
func AutoRun() error
AutoRun automatically recognizes and executes the callback function by value of index 0 (the first console parameter).
func BindHandle ¶ added in v1.9.1
BindHandle registers callback function <f> with <cmd>.
func BindHandleMap ¶ added in v1.9.1
BindHandle registers callback function with map <m>.
func BuildOptions ¶
BuildOptions builds the options as string.
func ContainsOpt ¶
ContainsOpt checks whether option named <name> exist in the arguments.
Types ¶
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser for arguments.
func Parse ¶
Parse creates and returns a new Parser with os.Args and supported options.
Note that the parameter <supportedOptions> is as [option name: need argument], which means the value item of <supportedOptions> indicates whether corresponding option name needs argument or not.
The optional parameter <strict> specifies whether stops parsing and returns error if invalid option passed.
func ParseWithArgs ¶
func ParseWithArgs(args []string, supportedOptions map[string]bool, strict ...bool) (*Parser, error)
ParseWithArgs creates and returns a new Parser with given arguments and supported options.
Note that the parameter <supportedOptions> is as [option name: need argument], which means the value item of <supportedOptions> indicates whether corresponding option name needs argument or not.
The optional parameter <strict> specifies whether stops parsing and returns error if invalid option passed.
func (*Parser) AutoRun ¶
AutoRun automatically recognizes and executes the callback function by value of index 0 (the first console parameter).
func (*Parser) BindHandle ¶
BindHandle registers callback function <f> with <cmd>.
func (*Parser) BindHandleMap ¶ added in v1.9.1
BindHandle registers callback function with map <m>.
func (*Parser) ContainsOpt ¶
ContainsOpt checks whether option named <name> exist in the arguments.
func (*Parser) MarshalJSON ¶
MarshalJSON implements the interface MarshalJSON for json.Marshal.