Documentation ¶
Overview ¶
Package tag reflect struct tag for bin
Index ¶
Examples ¶
Constants ¶
View Source
const ( CmdType uint8 = iota CmdApp CmdCommand CmdOption )
View Source
const ( TyAppName = "app" TyCommandName = "command" TyOptionName = "option" )
View Source
const ( CmdTypeKey = "CTY" // CmdCommandField the command sets of field CmdCommandField = "Commands" // CmdExecFn let command to be runnable CmdExecFn = "Exec" CmdTagName = "cmd" CmdFieldArg = "Arg" )
View Source
const ( OptRequire = "require" OptShort = "short" OptAlias = "alias" OptHelp = "help" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Parser ¶
type Parser struct { Tags []Tag // contains filtered or unexported fields }
func (*Parser) CommandTag ¶
CommandTag get tag sub command
func (*Parser) Run ¶
func (c *Parser) Run()
Example ¶
type test struct { Name string `cmd:"option:name require help:输入姓名"` Test string `cmd:"option:test help:输入test 表达式"` } // the app main struct type app struct { CTY Name `cmd:"app:yang"` Test *test `cmd:"command:test alias:tst,t help:测试命令工具 valuable"` } //func main(){ myapp := &app{ Test: &test{}, } parser := NewParser(myapp) parser.Run() //}
Output: 欢饮使用命令行程序,命令格式如下: $ yang [command] [option] 命令列表: test 测试命令工具,别名 tst,t
type RunnableCommand ¶
RunnableCommand runnable comand struct template
func (*RunnableCommand) Exec ¶
func (c *RunnableCommand) Exec(arg *bin.Arg)
type Tag ¶
type Tag struct { // the name is field of struct Name string Type uint8 Raw string Values map[string][]string // contains filtered or unexported fields }
func (*Tag) CheckOption ¶
CheckOption check if option exist
func (*Tag) IsRequired ¶
func (*Tag) ValueString ¶
ValueString get string app
Click to show internal directories.
Click to hide internal directories.