resolver

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 4, 2020 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const CommandEnHelper = `` /* 264-byte string literal not displayed */
View Source
const CommandZhHelper = `` /* 273-byte string literal not displayed */
View Source
const DefStrFlagDiv = `:`
View Source
const DefStrFlagLineDiv = `\n`
View Source
const DefStrFlagLineRune rune = '\n'
View Source
const ROOT = "global"
View Source
const StrFlagHidden rune = '#'
View Source
const StrFlagRequired rune = '@'
View Source
const TypeRegexpPattern = `^\[([a-z]+)\]`

Variables

View Source
var SimpleCommandLine = &SimpleCommanderApp{}

Functions

func Args

func Args() (args []*flag.Flag)

func BindBootHandler

func BindBootHandler(handler func(app *SimpleCommanderApp))

func BuildFlagByArgInfoStrArr

func BuildFlagByArgInfoStrArr(info []string) cli.Flag

func DeleteByIndex

func DeleteByIndex(arr []string, index int) []string

func FilterArrString

func FilterArrString(arr []string) []string

func FlagAppend

func FlagAppend(typeName string, name string, usage string, defs ...interface{}) (string, interface{})

func Get

func Get(key string) string

func GetArgN

func GetArgN(i int) string

func GetBigInt

func GetBigInt(key string) int64

func GetBool

func GetBool(key string) bool

func GetFlagNames

func GetFlagNames(names string) (map[string]interface{}, bool)

func GetFlagType

func GetFlagType(ty string) (map[string]string, bool)

func GetFloat

func GetFloat(key string) float64

func GetInt

func GetInt(key string) int

func GetName

func GetName() string

func GetNum

func GetNum(key string) int

func GetOsArgN

func GetOsArgN(i int) string

func GetOsArgs

func GetOsArgs() []string

func GetValue

func GetValue(key string) interface{}

func ReleaseStdout

func ReleaseStdout(stdout *os.File, tmp *os.File)

func Run

func Run()

func SliceFlags

func SliceFlags(row string, slice string) (arr []string)

func Str2Bool

func Str2Bool(str string) bool

func Str2Float64

func Str2Float64(str string) float64

func Str2Int

func Str2Int(str string) int

func Str2IntArray

func Str2IntArray(nums string) []int

func Str2IntSlice

func Str2IntSlice(str string) (arr *cli.IntSlice)

func TemplateParse

func TemplateParse(tplName string, tplContent string, v interface{}, funcMaps ...template.FuncMap) string

Types

type CommanderAppDto

type CommanderAppDto struct {
	Arguments []*CommanderFlagDto
	Usage     string
	Name      string
	Desc      string
	Version   string
	File      string
}

命令行应用 体 数据结构

func NewCommanderAppDto

func NewCommanderAppDto() *CommanderAppDto

func (*CommanderAppDto) InitDto

func (appDto *CommanderAppDto) InitDto(app *SimpleCommanderApp) *CommanderAppDto

type CommanderFlagDto

type CommanderFlagDto struct {
	Name         string
	Usage        string
	DefaultValue interface{}
	Value        interface{}
	RowType      string
}

命令参数 数据结构

func BuildFlagDtoByArgInfoStrArr

func BuildFlagDtoByArgInfoStrArr(info []string) *CommanderFlagDto

func NewCommanderFlagDto

func NewCommanderFlagDto() *CommanderFlagDto

func ParseFlagsExpress

func ParseFlagsExpress(express string) []*CommanderFlagDto

func (*CommanderFlagDto) InitFlagDto

func (flagDto *CommanderFlagDto) InitFlagDto(name, rowType, usage string, value interface{}, defValue interface{}) *CommanderFlagDto

初始化

type FlagResolver

type FlagResolver interface {
	fmt.Stringer
	Row() interface{}
	Args() []cli.Flag
	SetSlice(string) FlagResolver
	GetSlice() string
}

func NewFlagsStrWrapper

func NewFlagsStrWrapper(str ...interface{}) FlagResolver

func StrTemplateResolver

func StrTemplateResolver(template string, slice ...string) FlagResolver

type FlagsStrWrapper

type FlagsStrWrapper struct {
	RowStr StringFlags
	Slice  string
	ArgArr []cli.Flag
}

func StrFlagsWrapper

func StrFlagsWrapper(flags StringFlags, slice ...string) *FlagsStrWrapper

func (*FlagsStrWrapper) Args

func (wrapper *FlagsStrWrapper) Args() (flags []cli.Flag)

func (*FlagsStrWrapper) GetSlice

func (wrapper *FlagsStrWrapper) GetSlice() string

func (*FlagsStrWrapper) Parse

func (wrapper *FlagsStrWrapper) Parse()

func (*FlagsStrWrapper) Row

func (wrapper *FlagsStrWrapper) Row() interface{}

func (*FlagsStrWrapper) SetSlice

func (wrapper *FlagsStrWrapper) SetSlice(slice string) FlagResolver

func (*FlagsStrWrapper) String

func (wrapper *FlagsStrWrapper) String() string

type IniParser

type IniParser struct {
	FileName string
	IM       map[string]map[string]string
}

func NewIniParser

func NewIniParser() *IniParser

func (*IniParser) GetName

func (iniP *IniParser) GetName(pName string, vName string) string

func (*IniParser) ParserIniFile

func (iniP *IniParser) ParserIniFile(fileName string) error

type Local

type Local string
const (
	ZhLocal Local = "zh"
	EnLocal Local = "en"
)

type SimpleCommanderApp

type SimpleCommanderApp struct {
	Usage       interface{}                  // 用户帮助说明
	AutoParse   bool                         // 是否初始时自动解析
	Parsed      bool                         // 是否已经解析
	Name        string                       // 命令应用名
	Desc        string                       // 命令应用描述
	Lang        Local                        // 语言
	ArgumentMap map[string]*CommanderFlagDto // 参数存储容器
	BootHandler func(app *SimpleCommanderApp)
}

func NewSimpleCommanderAppByMap

func NewSimpleCommanderAppByMap(data map[string]interface{}) *SimpleCommanderApp

func (*SimpleCommanderApp) AddFlag

func (app *SimpleCommanderApp) AddFlag(ty string, name string, usage string, defs ...interface{})

func (*SimpleCommanderApp) AddFlagsByStrExpress

func (app *SimpleCommanderApp) AddFlagsByStrExpress(tpl string)

func (*SimpleCommanderApp) Args

func (app *SimpleCommanderApp) Args() (args []*flag.Flag)

func (*SimpleCommanderApp) Boot

func (app *SimpleCommanderApp) Boot()

func (*SimpleCommanderApp) Get

func (app *SimpleCommanderApp) Get(key string) string

func (*SimpleCommanderApp) GetArgN

func (app *SimpleCommanderApp) GetArgN(i int) string

func (*SimpleCommanderApp) GetBigInt

func (app *SimpleCommanderApp) GetBigInt(key string) int64

func (*SimpleCommanderApp) GetBool

func (app *SimpleCommanderApp) GetBool(key string) bool

func (*SimpleCommanderApp) GetFloat

func (app *SimpleCommanderApp) GetFloat(key string) float64

func (*SimpleCommanderApp) GetInt

func (app *SimpleCommanderApp) GetInt(key string) int

func (*SimpleCommanderApp) GetName

func (app *SimpleCommanderApp) GetName() string

func (*SimpleCommanderApp) GetNum

func (app *SimpleCommanderApp) GetNum(key string) int

func (*SimpleCommanderApp) GetOsArgN

func (app *SimpleCommanderApp) GetOsArgN(i int) string

func (*SimpleCommanderApp) GetOsArgs

func (app *SimpleCommanderApp) GetOsArgs() []string

func (*SimpleCommanderApp) GetUsage

func (app *SimpleCommanderApp) GetUsage() func()

func (*SimpleCommanderApp) GetValue

func (app *SimpleCommanderApp) GetValue(key string) interface{}

func (*SimpleCommanderApp) HasArg

func (app *SimpleCommanderApp) HasArg(key string) bool

func (*SimpleCommanderApp) HelpBoot

func (app *SimpleCommanderApp) HelpBoot()

func (*SimpleCommanderApp) HelpWrapper

func (app *SimpleCommanderApp) HelpWrapper(usage string) func()

func (*SimpleCommanderApp) Init

func (app *SimpleCommanderApp) Init()

func (*SimpleCommanderApp) Parse

func (app *SimpleCommanderApp) Parse() bool

func (*SimpleCommanderApp) PrintUsage

func (app *SimpleCommanderApp) PrintUsage()

func (*SimpleCommanderApp) Run

func (app *SimpleCommanderApp) Run()

func (*SimpleCommanderApp) Usage2Str

func (app *SimpleCommanderApp) Usage2Str() string

type SimpleCommanderAppApi

type SimpleCommanderAppApi interface {
	Get(string) string
	GetInt(string) int
	GetNum(string) int
	GetBool(string) bool
	GetBigInt(string) int64
	GetFloat(string) float64
	GetArgN(int) string
	GetOsArgs() []string
	GetOsArgN(int) string
	Run()
}

type SimpleResolver

type SimpleResolver interface {
	Args() []*flag.Flag
	core.AutoInit
	core.BootAble
	GetUsage() func()
	GetName() string
	HelpBoot()
	Parse() bool
}

func NewSimpleCommanderApp

func NewSimpleCommanderApp() SimpleResolver
Example
SimpleCommandLine.BootHandler = func(app *SimpleCommanderApp) {
	app.AddFlagsByStrExpress(FlagsExpress)
}
// SimpleCommandLine.Usage2Str()
//SimpleCommandLine.PrintUsage()
SimpleCommandLine.Parse()
SimpleCommandLine.Get("name")
Output:

type StringFlags

type StringFlags string

func Str2FlagTemplate

func Str2FlagTemplate(str string) StringFlags

func (StringFlags) Resolver

func (s StringFlags) Resolver() FlagResolver

func (StringFlags) String

func (s StringFlags) String() string

Jump to

Keyboard shortcuts

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