tag

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

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 Name

type Name struct {
	Name, Alias, Help string
}

type Parser

type Parser struct {
	Tags []Tag
	// contains filtered or unexported fields
}

func NewParser

func NewParser(value any) *Parser

NewParser app should be struct app or prt

func (*Parser) CommandTag

func (c *Parser) CommandTag(name string) (tag *Tag, option []Tag)

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 Runnable

type Runnable interface {
	Exec(arg *bin.Arg)
}

type RunnableCommand

type RunnableCommand struct {
	Arg *bin.Arg
}

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 ParseTag

func ParseTag(vTag string) *Tag

func (*Tag) CheckOption

func (c *Tag) CheckOption(args ...string) bool

CheckOption check if option exist

func (*Tag) IsRequired

func (c *Tag) IsRequired() bool

func (*Tag) Names

func (c *Tag) Names() []string

func (*Tag) Own

func (c *Tag) Own(name string) bool

Own check name its own be tag by name or alias

func (*Tag) Short

func (c *Tag) Short() []string

func (*Tag) Value

func (c *Tag) Value(args ...string) []string

func (*Tag) ValueString

func (c *Tag) ValueString(args ...string) string

ValueString get string app

Jump to

Keyboard shortcuts

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