gf: github.com/gogf/gf/os/gcmd Index | Files

package gcmd

import "github.com/gogf/gf/os/gcmd"

Package gcmd provides console operations, like options/arguments reading and command running.

Index

Package Files

gcmd.go gcmd_handler.go gcmd_parser.go gcmd_parser_handler.go gcmd_scan.go

func AutoRun Uses

func AutoRun() error

AutoRun automatically recognizes and executes the callback function by value of index 0 (the first console parameter).

func BindHandle Uses

func BindHandle(cmd string, f func()) error

BindHandle registers callback function <f> with <cmd>.

func BindHandleMap Uses

func BindHandleMap(m map[string]func()) error

BindHandle registers callback function with map <m>.

func BuildOptions Uses

func BuildOptions(m map[string]string, prefix ...string) string

BuildOptions builds the options as string.

func ContainsOpt Uses

func ContainsOpt(name string, def ...string) bool

ContainsOpt checks whether option named <name> exist in the arguments.

func GetArg Uses

func GetArg(index int, def ...string) string

GetArg returns the argument at <index>.

func GetArgAll Uses

func GetArgAll() []string

GetArgAll returns all parsed arguments.

func GetArgVar Uses

func GetArgVar(index int, def ...string) *gvar.Var

GetArgVar returns the argument at <index> as gvar.Var.

func GetOpt Uses

func GetOpt(name string, def ...string) string

GetOpt returns the option value named <name>.

func GetOptAll Uses

func GetOptAll() map[string]string

GetOptAll returns all parsed options.

func GetOptVar Uses

func GetOptVar(name string, def ...string) *gvar.Var

GetOptVar returns the option value named <name> as gvar.Var.

func RunHandle Uses

func RunHandle(cmd string) error

RunHandle executes the callback function registered by <cmd>.

func Scan Uses

func Scan(info ...interface{}) string

Scan prints <info> to stdout, reads and returns user input, which stops by '\n'.

func Scanf Uses

func Scanf(format string, info ...interface{}) string

Scanf prints <info> to stdout with <format>, reads and returns user input, which stops by '\n'.

type Parser Uses

type Parser struct {
    // contains filtered or unexported fields
}

Parser for arguments.

func Parse Uses

func Parse(supportedOptions map[string]bool, strict ...bool) (*Parser, error)

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 Uses

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 Uses

func (p *Parser) AutoRun() error

AutoRun automatically recognizes and executes the callback function by value of index 0 (the first console parameter).

func (*Parser) BindHandle Uses

func (p *Parser) BindHandle(cmd string, f func()) error

BindHandle registers callback function <f> with <cmd>.

func (*Parser) BindHandleMap Uses

func (p *Parser) BindHandleMap(m map[string]func()) error

BindHandle registers callback function with map <m>.

func (*Parser) ContainsOpt Uses

func (p *Parser) ContainsOpt(name string) bool

ContainsOpt checks whether option named <name> exist in the arguments.

func (*Parser) GetArg Uses

func (p *Parser) GetArg(index int, def ...string) string

GetArg returns the argument at <index>.

func (*Parser) GetArgAll Uses

func (p *Parser) GetArgAll() []string

GetArgAll returns all parsed arguments.

func (*Parser) GetArgVar Uses

func (p *Parser) GetArgVar(index int, def ...string) *gvar.Var

GetArgVar returns the argument at <index> as gvar.Var.

func (*Parser) GetOpt Uses

func (p *Parser) GetOpt(name string, def ...string) string

GetOpt returns the option value named <name>.

func (*Parser) GetOptAll Uses

func (p *Parser) GetOptAll() map[string]string

GetOptAll returns all parsed options.

func (*Parser) GetOptVar Uses

func (p *Parser) GetOptVar(name string, def ...interface{}) *gvar.Var

GetOptVar returns the option value named <name> as gvar.Var.

func (*Parser) MarshalJSON Uses

func (p *Parser) MarshalJSON() ([]byte, error)

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*Parser) RunHandle Uses

func (p *Parser) RunHandle(cmd string) error

RunHandle executes the callback function registered by <cmd>.

Package gcmd imports 9 packages (graph). Updated 2020-08-09. Refresh now. Tools for package owners.