dcmd

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AutoRun

func AutoRun() error

AutoRun 根据命令行传入自动执行绑定的方法

func BindHandle

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

BindHandle 为命令绑定执行方法

func BindHandleMap

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

BindHandleMap 通过map传入批量绑定方法

func BuildOptions

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

BuildOptions 通过map构造出options

func ContainsOpt

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

ContainsOpt 判断指定name的option是否存在

func GetArg

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

GetArg 获取参数

func GetArgAll

func GetArgAll() []string

GetArgAll 获取全部参数

func GetArgVar

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

GetArgVar 获取var类型的参数

func GetOpt

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

GetOpt 获取option中的值

func GetOptAll

func GetOptAll() map[string]string

GetOptAll 获取全部options

func GetOptVar

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

GetOptVar 获取var类型的options

func GetOptWithEnv

func GetOptWithEnv(key string, def ...interface{}) *dvar.Var

GetOptWithEnv returns the command line argument of the specified <key>. If the argument does not exist, then it returns the environment variable with specified <key>. It returns the default value <def> if none of them exists.

Fetching Rules: 1. Command line arguments are in lowercase format, eg: gf.<package name>.<variable name>; 2. Environment arguments are in uppercase format, eg: GF_<package name>_<variable name>;

func GetWithEnv

func GetWithEnv(key string, def ...interface{}) *dvar.Var

GetWithEnv 获取参数,如果命令行不存在则从环境变量中获取

func Init

func Init(args ...string)

Init 初始化参数

func RunHandle

func RunHandle(cmd string) error

RunHandle 运行某个方法

func Scan

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

Scan 交互操作

func Scanf

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

Scanf 支持格式化参数的交互操作

Types

type Parser

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

func Parse

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

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

func (that *Parser) AutoRun() error

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

func (*Parser) BindHandle

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

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

func (*Parser) BindHandleMap

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

BindHandleMap registers callback function with map <m>.

func (*Parser) ContainsOpt

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

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

func (*Parser) GetArg

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

GetArg returns the argument at <index>.

func (*Parser) GetArgAll

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

GetArgAll returns all parsed arguments.

func (*Parser) GetArgVar

func (that *Parser) GetArgVar(index int, def ...string) *dvar.Var

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

func (*Parser) GetOpt

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

GetOpt returns the option value named <name>.

func (*Parser) GetOptAll

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

GetOptAll returns all parsed options.

func (*Parser) GetOptVar

func (that *Parser) GetOptVar(name string, def ...interface{}) *dvar.Var

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

func (*Parser) MarshalJSON

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

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*Parser) RunHandle

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

RunHandle executes the callback function registered by <cmd>.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL