1
0
forked from x/icebergs
This commit is contained in:
shy 2023-08-13 22:13:54 +08:00
parent 1f0f42db7d
commit 4e8b1cf68d
3 changed files with 17 additions and 4 deletions

View File

@ -288,6 +288,15 @@ func init() {
})
}
func HostPort(m *ice.Message, host, port string, arg ...string) string {
if port == "443" {
return kit.Format("https://%s", host)
} else if port == "80" {
return kit.Format("http://%s", host)
} else {
return kit.Format("http://%s:%s", host, port)
}
}
func SpideGet(m *ice.Message, arg ...ice.Any) ice.Any {
return kit.UnMarshal(m.Cmdx(http.MethodGet, arg))
}

View File

@ -33,7 +33,8 @@ func init() {
}
}},
TEMPLATE: {Hand: func(m *ice.Message, arg ...string) {
m.Echo(nfs.Template(m, "demo.shy"), path.Base(path.Dir(path.Join(arg[2], arg[1]))))
m.Option(mdb.NAME, path.Base(path.Dir(path.Join(arg[2], arg[1]))))
m.Echo(nfs.Template(m, "demo.shy"))
}},
COMPLETE: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy("web.wiki.word", COMPLETE, arg) }},
}, PlugAction()), Hand: func(m *ice.Message, arg ...string) {

View File

@ -283,8 +283,8 @@ func (m *Message) Start(key string, arg ...string) *Message {
})
}
func (m *Message) Travel(cb Any) *Message {
target := m.target
defer func() { m.target = target }()
target, cmd, key := m.target, m._cmd, m._key
defer func() { m.target, m._cmd, m._key = target, cmd, key }()
list := []*Context{m.root.target}
for i := 0; i < len(list); i++ {
switch cb := cb.(type) {
@ -292,7 +292,10 @@ func (m *Message) Travel(cb Any) *Message {
cb(list[i].context, list[i])
case func(*Context, *Context, string, *Command):
m.target = list[i]
kit.For(kit.SortedKey(list[i].Commands), func(k string) { cb(list[i].context, list[i], k, list[i].Commands[k]) })
kit.For(kit.SortedKey(list[i].Commands), func(k string) {
m._cmd, m._key = list[i].Commands[k], k
cb(list[i].context, list[i], k, list[i].Commands[k])
})
case func(*Context, *Context, string, *Config):
m.target = list[i]
kit.For(kit.SortedKey(list[i].Configs), func(k string) { cb(list[i].context, list[i], k, list[i].Configs[k]) })