Documentation ¶
Index ¶
- Variables
- func ArgGetInDef(a Arg, mode HelpMode) string
- func ArgGetOutDef(a Arg) string
- func AsEvalError(err error) *starlark.EvalError
- func CallStack(err error) starlark.CallStack
- func CheckArgsContain(kwargs []starlark.Tuple, key ...string) booldeprecated
- func Equal(one, another starlark.Value) bool
- func EqualInt(one starlark.Value, another int64) bool
- func GetExamplesDoc(examples []Example, mode HelpMode) string
- func GetFromArgs(kwargs []starlark.Tuple, key string) starlark.Valuedeprecated
- func GetFromArgsBool(kwargs []starlark.Tuple, key string, defaultValue bool) (bool, error)deprecated
- func GetFromArgsInt64(kwargs []starlark.Tuple, key string, defaultValue int64) (int64, error)deprecated
- func GetHelpFor(v starlark.Value, mode HelpMode) string
- func GetHelperHelpFor(v CanHelp, mode HelpMode) string
- func Hash(v string, fact uint32) uint32
- func IsArgExist(err error) bool
- func IsArgNotExist(err error) bool
- func IsArgTypeMismatch(err error) bool
- func NewListFromStrings(elems []string) *starlark.List
- func String(any fmt.Stringer) starlark.String
- func ToStringDict(globalMiddleware Middleware, elements ...map[string]interface{}) starlark.StringDict
- func ToStringList(value starlark.Value) ([]string, error)
- func TraverseList(value starlark.Value, f func(starlark.Value) error) error
- func TraverseLists(values []starlark.Value, f func(starlark.Value) error) error
- type Arg
- func AnyArg(name string) Arg
- func BoolArg(name string) Arg
- func BytesArg(name string) Arg
- func DictArg(name string, keyType, valueType Arg) Arg
- func FloatArg(name string) Arg
- func FuncArg(name string, in Args, out Arg) Arg
- func IntArg(name string) Arg
- func ListArg(name string, innerType Arg) Arg
- func NoneArg(name string) Arg
- func StringArg(name string) Arg
- func StructArg(name string, desc *StructDescription) Arg
- func TupleArg(name string, a ...Arg) Arg
- func UnionArg(name string, a ...Arg) Arg
- type Args
- type Assertable
- type AssertableBool
- type BasicType
- type BuiltinFunc
- type CanHelp
- type CustomTypeArg
- func (c CustomTypeArg) Default(value interface{}) Arg
- func (c CustomTypeArg) DocLong() string
- func (c CustomTypeArg) DocShort() string
- func (c CustomTypeArg) InDefaultValue() string
- func (c CustomTypeArg) InName() string
- func (c CustomTypeArg) InType() string
- func (c CustomTypeArg) Long(s string) Arg
- func (c CustomTypeArg) Optional() Arg
- func (c CustomTypeArg) OutType() string
- func (c CustomTypeArg) Short(s string) Arg
- type DataTypeMember
- type DocObject
- type DocProvider
- type ErrArgExist
- type ErrArgNotExist
- type ErrArgTypeMismatch
- type Example
- type Function
- func (f *Function) ArgsInSplit() []Arg
- func (f *Function) CallInternal(thread *starlark.Thread, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)
- func (f Function) Copy() *Function
- func (f *Function) Freeze()
- func (f *Function) GetArgOutDef() string
- func (f *Function) GetArgsInDef() string
- func (f *Function) GetDefDoc(mode HelpMode) string
- func (f *Function) GetFullDesc(mode HelpMode) string
- func (f *Function) GetSimpleDesc(mode HelpMode) string
- func (f *Function) Hash() (uint32, error)
- func (f *Function) Name() string
- func (f *Function) Receiver() starlark.Value
- func (f *Function) String() string
- func (f *Function) Truth() starlark.Bool
- func (f *Function) Type() string
- type HelpMode
- type Helper
- func (h *Helper) ArgsCount() int
- func (h *Helper) CheckContainKeywordArg(keys ...string) error
- func (h *Helper) CheckExactArgs(count int) error
- func (h *Helper) CheckMinArgs(count int) error
- func (h *Helper) CheckOnlyContainKeywordArg(keys ...string) error
- func (h *Helper) ContainKeywordArg(key string) bool
- func (h *Helper) GetAllPositionalArgs() []starlark.Value
- func (h *Helper) GetFirstArg() (starlark.Value, error)
- func (h *Helper) GetKeywordArgs(key string) starlark.Value
- func (h *Helper) GetKeywordArgsBool(key string) (bool, error)
- func (h *Helper) GetKeywordArgsBoolWithDefault(key string, defaultValue bool) (bool, error)
- func (h *Helper) GetKeywordArgsInt64(key string) (int64, error)
- func (h *Helper) GetKeywordArgsInt64WithDefault(key string, defaultValue int64) (int64, error)
- func (h *Helper) GetKeywordArgsString(key string) (string, error)
- func (h *Helper) GetKeywordArgsStringList(key string) ([]string, error)
- func (h *Helper) GetKeywordArgsStringListWithDefault(key string, defaultValue []string) ([]string, error)
- func (h *Helper) GetKeywordArgsStringWithDefault(key string, defaultValue string) (string, error)
- func (h *Helper) GetKeywordArgsUint64(key string) (uint64, error)
- func (h *Helper) GetKeywordArgsUint64WithDefault(key string, defaultValue uint64) (uint64, error)
- func (h *Helper) Print(msg string)
- func (h *Helper) UnpackArgs(pairs ...interface{}) *Helper
- func (h *Helper) UnpackArgsIgnoreKeyword(pairs ...interface{}) *Helper
- func (h *Helper) UnpackBasicArgs(pairs ...interface{}) *Helperdeprecated
- func (h *Helper) UnpackPositionalArgs(min int, vars ...interface{}) *Helper
- type Middleware
- type Module
- type PreDeclaredValue
- type RawDefaultString
- type StandardFunc
- type StarlarkModule
- type Struct
- func (s *Struct) Assert() (bool, string)
- func (s *Struct) Attr(name string) (starlark.Value, error)
- func (s *Struct) AttrNames() []string
- func (s *Struct) Description() string
- func (s *Struct) FieldEqual(name string, value starlark.Value) bool
- func (s *Struct) Freeze()
- func (s *Struct) Get(key starlark.Value) (v starlark.Value, found bool, err error)
- func (s *Struct) GetDefDoc(mode HelpMode) string
- func (s *Struct) GetFullDesc(mode HelpMode) string
- func (s *Struct) GetSimpleDesc(mode HelpMode) string
- func (s *Struct) Hash() (uint32, error)
- func (s *Struct) Items() []starlark.Tuple
- func (s *Struct) Iterate() starlark.Iterator
- func (s *Struct) String() string
- func (s *Struct) ToDict() *starlark.Dict
- func (s *Struct) Truth() starlark.Bool
- func (s *Struct) Type() string
- type StructDescription
- func (d *StructDescription) ConstructAll(dict starlark.StringDict) (*Struct, error)
- func (d *StructDescription) GetDefDoc(mode HelpMode) string
- func (d *StructDescription) GetFullDesc(mode HelpMode) string
- func (d *StructDescription) GetSimpleDesc(mode HelpMode) string
- func (d *StructDescription) MustConstructAll(dict starlark.StringDict) *Struct
- func (d *StructDescription) ProvideDoc() DocProvider
- func (d *StructDescription) UnsafeConstruct(dict starlark.StringDict) *Struct
- func (d *StructDescription) WithAssertProvider(f func(s *Struct) (pass bool, failReason string)) *StructDescription
- type UnpackArgsFunc
Constants ¶
This section is empty.
Variables ¶
var ELLIPSIS = symbolArg("...")
var SLASH = symbolArg("/")
var STAR = symbolArg("*")
Functions ¶
func ArgGetInDef ¶
func ArgGetOutDef ¶
func AsEvalError ¶ added in v0.1.1
func CheckArgsContain
deprecated
func GetExamplesDoc ¶
func GetHelperHelpFor ¶
func IsArgExist ¶ added in v0.1.5
func IsArgNotExist ¶ added in v0.1.4
func IsArgTypeMismatch ¶ added in v0.1.4
func NewListFromStrings ¶ added in v0.2.6
func ToStringDict ¶ added in v0.2.0
func ToStringDict(globalMiddleware Middleware, elements ...map[string]interface{}) starlark.StringDict
ToStringDict convert elements to StringDict any element must be one of - *StarlarkModule - *Module - starlark.Value Panic: any other values will result in panic
func TraverseList ¶ added in v0.2.5
Types ¶
type Arg ¶
type Arg interface { Optional() Arg // 将 arg 标记为 optional Default(value interface{}) Arg Short(s string) Arg Long(s string) Arg InName() string // 传入时的参数名 InType() string // 传入时展示的参数名 InDefaultValue() string // 传入时的默认值(空代表无默认值) OutType() string // 返回时展示的参数名(空代表无返回值) DocShort() string DocLong() string // contains filtered or unexported methods }
func StructArg ¶ added in v0.1.9
func StructArg(name string, desc *StructDescription) Arg
type Assertable ¶
Assertable 为数据提供 assert 的能力
type AssertableBool ¶ added in v0.2.2
func NewFalseWithReason ¶ added in v0.2.2
func NewFalseWithReason(reason string) AssertableBool
func (AssertableBool) Assert ¶ added in v0.2.2
func (a AssertableBool) Assert() (pass bool, failReason string)
type BuiltinFunc ¶
func UnHelp ¶
func UnHelp(f StandardFunc) BuiltinFunc
UnHelp 将 BuiltinFunc 重新映射为标准 StandardFunc,用于兼容第三方库使用 需要注意的是,兼容方式要求将原 *starlark.Builtin 类型的 fn 改用 *Function 类型
type CanHelp ¶
type CanHelp interface { GetDefDoc(mode HelpMode) string // 获取声明信息,应当包括名称、类型,不应包括任何用法解释 GetSimpleDesc(mode HelpMode) string // 获取简单说明信息,应当在一行内完成,不应过长 GetFullDesc(mode HelpMode) string // 获取详细说明信息,不应重复包括 GetSimpleDesc 中的内容,用于说明具体的使用方式,换行应使用 LF }
CanHelp 接口为自定义类型提供了输出帮助信息的能力 内部的 Function Struct Module 已经实现了 CanHelp
type CustomTypeArg ¶
func (CustomTypeArg) Default ¶
func (c CustomTypeArg) Default(value interface{}) Arg
func (CustomTypeArg) DocLong ¶
func (c CustomTypeArg) DocLong() string
func (CustomTypeArg) DocShort ¶
func (c CustomTypeArg) DocShort() string
func (CustomTypeArg) InDefaultValue ¶
func (c CustomTypeArg) InDefaultValue() string
func (CustomTypeArg) InName ¶
func (c CustomTypeArg) InName() string
func (CustomTypeArg) InType ¶
func (c CustomTypeArg) InType() string
func (CustomTypeArg) Long ¶
func (c CustomTypeArg) Long(s string) Arg
func (CustomTypeArg) Optional ¶
func (c CustomTypeArg) Optional() Arg
func (CustomTypeArg) OutType ¶
func (c CustomTypeArg) OutType() string
func (CustomTypeArg) Short ¶
func (c CustomTypeArg) Short(s string) Arg
type DataTypeMember ¶
type DocProvider ¶
DocProvider 标志着一个 starlark 数据类型可以进行 help 执行
type ErrArgExist ¶ added in v0.1.5
type ErrArgExist struct{ ArgName string }
func (ErrArgExist) Error ¶ added in v0.1.5
func (e ErrArgExist) Error() string
type ErrArgNotExist ¶ added in v0.1.4
type ErrArgNotExist struct{ ArgName string }
func (ErrArgNotExist) Error ¶ added in v0.1.4
func (e ErrArgNotExist) Error() string
type ErrArgTypeMismatch ¶ added in v0.1.4
func (ErrArgTypeMismatch) Error ¶ added in v0.1.4
func (e ErrArgTypeMismatch) Error() string
type Function ¶
type Function struct { Ctx context.Context FuncName string // 函数名称 Short string // 简介 Long string // 详细帮助信息 Examples []Example // 示例 Middleware Middleware Fn BuiltinFunc ArgsIn Args ArgOut Arg // contains filtered or unexported fields }
Function 函数类型
func NewBuiltinFunction ¶
func NewBuiltinFunction(name string, f BuiltinFunc) *Function
NewBuiltinFunction 快速创建一个无文档的 Function 示例
func (*Function) ArgsInSplit ¶
func (*Function) CallInternal ¶
func (*Function) GetArgOutDef ¶
GetArgOutDef 获取函数出参文档 返回空或 ` -> TYPE`
func (*Function) GetFullDesc ¶
func (*Function) GetSimpleDesc ¶
type Helper ¶
type Helper struct { Name string Thread *starlark.Thread Fn *Function PositionalArgs []starlark.Value Kwargs []starlark.Tuple // original Kwargs KeywordArgs starlark.StringDict Err error Args starlark.Tuple // Deprecated: please use PositionalArgs }
func (*Helper) CheckContainKeywordArg ¶ added in v0.1.5
CheckContainKeywordArg will return error if there is any keyword arguments passed in not exist. If there are other keyword arguments, won't error. If you want to check that, maybe you want to use CheckOnlyContainKeywordArg.
func (*Helper) CheckExactArgs ¶
CheckExactArgs 检查是否传递了指定数量的参数,如果否则返回 error
func (*Helper) CheckMinArgs ¶
CheckMinArgs 检查是否传递了至少指定数量的参数,如果否则返回 error
func (*Helper) CheckOnlyContainKeywordArg ¶ added in v0.1.5
CheckOnlyContainKeywordArg will return error if there is any keyword arguments except for passed in keys. If any of keys not exist, won't error. If you want to check that, maybe you want to use CheckContainKeywordArg
func (*Helper) ContainKeywordArg ¶ added in v0.1.4
func (*Helper) GetAllPositionalArgs ¶ added in v0.1.4
func (*Helper) GetFirstArg ¶
GetFirstArg 获得第一个参数
func (*Helper) GetKeywordArgs ¶
GetKeywordArgs 从 keyword args 中提取出指定 key 对应的值,如果值不存在返回 nil
func (*Helper) GetKeywordArgsBool ¶
GetKeywordArgsBool 从 keyword args 中提取出指定 key 对应的值并转换为 int64 类型
func (*Helper) GetKeywordArgsBoolWithDefault ¶ added in v0.1.4
GetKeywordArgsBoolWithDefault like GetKeywordArgsBool but accept a defaultValue arg
func (*Helper) GetKeywordArgsInt64 ¶ added in v0.1.4
GetKeywordArgsInt64 从 keyword args 中提取出指定 key 对应的值并转换为 int64 类型
func (*Helper) GetKeywordArgsInt64WithDefault ¶ added in v0.1.4
GetKeywordArgsInt64WithDefault like GetKeywordArgsInt64 but accept a defaultValue arg
func (*Helper) GetKeywordArgsString ¶ added in v0.1.4
GetKeywordArgsString 从 keyword args 中提取出指定 key 对应的值并转换为 string 类型
func (*Helper) GetKeywordArgsStringList ¶ added in v0.1.6
GetKeywordArgsStringList 从 keyword args 中提取出指定 key 对应的值并转换为 []string 类型 If type of key is a single string, it's also valid and will return a single element string slice
func (*Helper) GetKeywordArgsStringListWithDefault ¶ added in v0.1.6
func (h *Helper) GetKeywordArgsStringListWithDefault(key string, defaultValue []string) ([]string, error)
GetKeywordArgsStringListWithDefault like GetKeywordArgsStringList but accept a defaultValue arg
func (*Helper) GetKeywordArgsStringWithDefault ¶ added in v0.1.4
GetKeywordArgsStringWithDefault like GetKeywordArgsString but accept a defaultValue arg
func (*Helper) GetKeywordArgsUint64 ¶ added in v0.1.4
GetKeywordArgsUint64 从 keyword args 中提取出指定 key 对应的值并转换为 uint64 类型
func (*Helper) GetKeywordArgsUint64WithDefault ¶ added in v0.1.4
GetKeywordArgsUint64WithDefault like GetKeywordArgsUint64 but accept a defaultValue arg
func (*Helper) UnpackArgs ¶
func (*Helper) UnpackArgsIgnoreKeyword ¶
UnpackArgsIgnoreKeyword 类似于 UnpackArgs,但是忽略命名参数
func (*Helper) UnpackBasicArgs
deprecated
func (*Helper) UnpackPositionalArgs ¶
type Middleware ¶ added in v0.2.0
func ChainMiddleware ¶ added in v0.2.0
func ChainMiddleware(middlewares ...Middleware) Middleware
type Module ¶
type Module struct { Name string Short string // module 功能简介 SubModules []*Module PreDeclares []*PreDeclaredValue Functions []*Function Structs []*StructDescription FuncMiddleware Middleware }
type PreDeclaredValue ¶
type PreDeclaredValue struct { Name string Short string // 简介 Long string // 详细帮助信息 Examples []Example // 示例 Value starlark.Value }
PreDeclaredValue 为预声明的变量/常量值
func (*PreDeclaredValue) GetDefDoc ¶
func (m *PreDeclaredValue) GetDefDoc(mode HelpMode) string
func (*PreDeclaredValue) GetFullDesc ¶
func (m *PreDeclaredValue) GetFullDesc(mode HelpMode) string
func (*PreDeclaredValue) GetSimpleDesc ¶
func (m *PreDeclaredValue) GetSimpleDesc(mode HelpMode) string
type RawDefaultString ¶
type RawDefaultString string
type StandardFunc ¶
type StarlarkModule ¶
type StarlarkModule struct { starlarkstruct.Module // contains filtered or unexported fields }
func (*StarlarkModule) GetDefDoc ¶
func (m *StarlarkModule) GetDefDoc(mode HelpMode) string
func (*StarlarkModule) GetFullDesc ¶
func (m *StarlarkModule) GetFullDesc(mode HelpMode) string
func (*StarlarkModule) GetSimpleDesc ¶
func (m *StarlarkModule) GetSimpleDesc(mode HelpMode) string
type Struct ¶
type Struct struct { Descriptor *StructDescription Values starlark.StringDict }
func (*Struct) Description ¶
func (*Struct) GetFullDesc ¶
func (*Struct) GetSimpleDesc ¶
type StructDescription ¶
type StructDescription struct { Name string // struct 名称 Short string Long string AssertNote string Examples []Example Fields map[string]Arg Editable bool // TODO 是否允许 field 被修改,需要注意的是如果允许那么需要特别处理 assert ReturnNoneForUnExistField bool // 对于不存在的 field 返回 None 而不是错误 StringProvider func(s *Struct) string TruthProvider func(s *Struct) starlark.Bool HashProvider func(s *Struct) (uint32, error) AssertProvider func(s *Struct) (pass bool, failReason string) GetProvider func(s *Struct, key starlark.Value) (v starlark.Value, found bool, err error) // contains filtered or unexported fields }
StructDescription 为一个 struct 的描述信息
func NewStruct ¶
func NewStruct(name string, args ...Arg) *StructDescription
func (*StructDescription) ConstructAll ¶
func (d *StructDescription) ConstructAll(dict starlark.StringDict) (*Struct, error)
ConstructAll 传递的 dict 必须与期望的 Fields 相对应 TODO: 类型检测尚未实现
func (*StructDescription) GetDefDoc ¶
func (d *StructDescription) GetDefDoc(mode HelpMode) string
func (*StructDescription) GetFullDesc ¶
func (d *StructDescription) GetFullDesc(mode HelpMode) string
func (*StructDescription) GetSimpleDesc ¶
func (d *StructDescription) GetSimpleDesc(mode HelpMode) string
func (*StructDescription) MustConstructAll ¶
func (d *StructDescription) MustConstructAll(dict starlark.StringDict) *Struct
MustConstructAll ConstructAll but will panic if error
func (*StructDescription) ProvideDoc ¶
func (d *StructDescription) ProvideDoc() DocProvider
func (*StructDescription) UnsafeConstruct ¶
func (d *StructDescription) UnsafeConstruct(dict starlark.StringDict) *Struct
UnsafeConstruct 不做任何检查,创建相应的 struct
func (*StructDescription) WithAssertProvider ¶
func (d *StructDescription) WithAssertProvider(f func(s *Struct) (pass bool, failReason string)) *StructDescription
type UnpackArgsFunc ¶
type UnpackArgsFunc func(pairs ...interface{}) error
Source Files ¶
- arg.go
- arg_basic.go
- arg_custom.go
- arg_default.go
- arg_dict.go
- arg_func.go
- arg_list.go
- arg_message.go
- arg_none.go
- arg_optional.go
- arg_split.go
- arg_struct.go
- arg_tuple.go
- arg_union.go
- args.go
- assert.go
- doc.go
- doc_provider.go
- enum.go
- equal.go
- error.go
- example.go
- flag.go
- function.go
- function_doc.go
- function_helper.go
- function_middleware.go
- global.go
- hash.go
- legacy_args.go
- legacy_wrapper.go
- list.go
- map.go
- member_datatype.go
- module.go
- module_doc.go
- predeclared.go
- predeclared_doc.go
- string.go
- struct.go
- struct_doc.go
- struct_helper.go
- struct_option.go
- terminal.go