mirror of
https://shylinux.com/x/icebergs
synced 2025-04-30 18:59:22 +08:00
opt some
This commit is contained in:
parent
f98cf8c113
commit
7c0892cba7
2
exec.go
2
exec.go
@ -52,7 +52,7 @@ func (m *Message) Assert(expr interface{}) bool {
|
||||
panic(expr)
|
||||
}
|
||||
func (m *Message) Sleep(d string, arg ...interface{}) *Message {
|
||||
m.Debug("sleep %s %s", d, kit.FileLine(2, 3))
|
||||
// m.Debug("sleep %s %s", d, kit.FileLine(2, 3))
|
||||
if time.Sleep(kit.Duration(d)); len(arg) > 0 {
|
||||
m.Cmdy(arg...)
|
||||
}
|
||||
|
25
misc.go
25
misc.go
@ -280,7 +280,7 @@ func (c *Context) _cmd(m *Message, cmd *Command, key string, sub string, h *Acti
|
||||
h.Hand(m, arg...)
|
||||
return m
|
||||
}
|
||||
func (c *Context) split(name string) (list []interface{}) {
|
||||
func SplitCmd(name string) (list []interface{}) {
|
||||
const (
|
||||
TEXT = "text"
|
||||
ARGS = "args"
|
||||
@ -343,6 +343,29 @@ func (c *Context) split(name string) (list []interface{}) {
|
||||
}
|
||||
return list
|
||||
}
|
||||
func (m *Message) Design(action interface{}, help string, input ...interface{}) {
|
||||
list := kit.List()
|
||||
for _, input := range input {
|
||||
switch input := input.(type) {
|
||||
case string:
|
||||
list = append(list, SplitCmd("action "+input)...)
|
||||
case map[string]interface{}:
|
||||
if kit.Format(input[TYPE]) != "" && kit.Format(input[NAME]) != "" {
|
||||
list = append(list, input)
|
||||
continue
|
||||
}
|
||||
kit.Fetch(kit.KeyValue(nil, "", input), func(k string, v interface{}) {
|
||||
list = append(list, kit.Dict(NAME, k, TYPE, "text", VALUE, v))
|
||||
})
|
||||
}
|
||||
}
|
||||
k := kit.Format(action)
|
||||
if a, ok := m._cmd.Action[k]; ok {
|
||||
a.List = list
|
||||
m._cmd.Meta[k] = list
|
||||
kit.Value(m._cmd.Meta, kit.Keys("_trans", k), help)
|
||||
}
|
||||
}
|
||||
|
||||
func MergeAction(list ...interface{}) map[string]*Action {
|
||||
if len(list) == 0 {
|
||||
|
4
type.go
4
type.go
@ -145,7 +145,7 @@ func (c *Context) Merge(s *Context) *Context {
|
||||
}
|
||||
|
||||
if c.Commands[key] = cmd; cmd.List == nil {
|
||||
cmd.List = c.split(cmd.Name)
|
||||
cmd.List = SplitCmd(cmd.Name)
|
||||
}
|
||||
if cmd.Meta == nil {
|
||||
cmd.Meta = kit.Dict()
|
||||
@ -183,7 +183,7 @@ func (c *Context) Merge(s *Context) *Context {
|
||||
continue // alias cmd
|
||||
}
|
||||
if a.List == nil {
|
||||
a.List = c.split(a.Name)
|
||||
a.List = SplitCmd(a.Name)
|
||||
}
|
||||
if len(a.List) > 0 {
|
||||
cmd.Meta[k] = a.List
|
||||
|
Loading…
x
Reference in New Issue
Block a user