1
0
forked from x/icebergs

opt search

This commit is contained in:
harveyshao 2022-04-08 12:29:16 +08:00
parent 855aaac279
commit 20ebcc4754
12 changed files with 65 additions and 33 deletions

View File

@ -119,7 +119,6 @@ func init() {
}, Commands: map[string]*ice.Command{
USER: {Name: "user username auto create", Help: "用户", Action: ice.MergeAction(map[string]*ice.Action{
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
m.Cmd(mdb.SEARCH, mdb.CREATE, m.CommandKey(), m.PrefixKey())
UserRoot(ice.Pulse)
}},
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {

View File

@ -80,9 +80,6 @@ const COMMAND = "command"
func init() {
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
COMMAND: {Name: "command key auto", Help: "命令", Action: map[string]*ice.Action{
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
m.Cmd(mdb.SEARCH, mdb.CREATE, m.CommandKey(), m.PrefixKey())
}},
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
if arg[0] == m.CommandKey() || len(arg) > 1 && arg[1] != "" {
_command_search(m, arg[0], kit.Select("", arg, 1), kit.Select("", arg, 2))

View File

@ -235,7 +235,6 @@ func init() {
}, Commands: map[string]*ice.Command{
DIR: {Name: "dir path field... auto upload", Help: "目录", Action: map[string]*ice.Action{
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
m.Cmd(mdb.SEARCH, mdb.CREATE, m.CommandKey(), m.PrefixKey())
m.Cmd(mdb.RENDER, mdb.CREATE, m.CommandKey(), m.PrefixKey())
}},
mdb.SEARCH: {Name: "search type name", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {

View File

@ -56,6 +56,12 @@ func _serve_udp(m *ice.Message, host, port string) {
}
}
}
func _broad_search(m *ice.Message, kind, name, text string, arg ...string) {
m.Richs(BROAD, nil, mdb.FOREACH, func(key string, value map[string]interface{}) {
value = kit.GetMeta(value)
m.PushSearch(mdb.TYPE, "friend", mdb.TEXT, kit.Format("http://%s:%s", value[tcp.HOST], value[tcp.PORT]), value)
})
}
const BROAD = "broad"
@ -70,7 +76,6 @@ func init() {
kit.Format("http://%s:%s", m.Option(tcp.HOST), m.Option(tcp.PORT)))
m.Cmd(SPACE, tcp.DIAL, m.OptionSimple(ice.DEV))
}},
ice.CTX_EXIT: {Hand: func(m *ice.Message, arg ...string) { m.Conf(BROAD, "", "") }},
}, mdb.HashAction(
mdb.SHORT, "host,port", mdb.FIELD, "time,hash,host,port",
)), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {

View File

@ -258,6 +258,7 @@ func _space_fork(m *ice.Message) {
const (
CHROME = "chrome"
FRIEND = "friend"
MASTER = "master"
MYSELF = "myself"
SERVER = "server"
@ -284,11 +285,11 @@ func init() {
}, Commands: map[string]*ice.Command{
SPACE: {Name: "space name cmd auto invite", Help: "空间站", Action: ice.MergeAction(map[string]*ice.Action{
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
m.Cmd(mdb.SEARCH, mdb.CREATE, m.CommandKey(), m.PrefixKey())
m.Conf(SPACE, mdb.HASH, "")
}},
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
_space_search(m, arg[0], arg[1], kit.Select("", arg, 2))
_broad_search(m, arg[0], arg[1], kit.Select("", arg, 2))
}},
aaa.INVITE: {Name: "invite", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
for _, k := range []string{ice.MISC, ice.CORE, ice.BASE} {

View File

@ -334,18 +334,15 @@ const SPIDE = "spide"
func init() {
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
SPIDE: {Name: SPIDE, Help: "蜘蛛侠", Value: kit.Data(
mdb.SHORT, CLIENT_NAME, mdb.FIELD, "time,client.name,client.url",
LOGHEADERS, ice.FALSE,
)},
SPIDE: {Name: SPIDE, Help: "蜘蛛侠", Value: kit.Data(mdb.SHORT, CLIENT_NAME, mdb.FIELD, "time,client.name,client.url", LOGHEADERS, ice.FALSE)},
}, Commands: map[string]*ice.Command{
SPIDE: {Name: "spide client.name action=raw,msg,save,cache method=GET,PUT,POST,DELETE url format=form,part,json,data,file arg run create", Help: "蜘蛛侠", Action: ice.MergeAction(map[string]*ice.Action{
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
conf := m.Confm(cli.RUNTIME, "conf")
m.Cmd(SPIDE, mdb.CREATE, ice.OPS, kit.Select("http://:9020", conf["ctx_ops"]))
m.Cmd(SPIDE, mdb.CREATE, ice.OPS, kit.Select("http://127.0.0.1:9020", conf["ctx_ops"]))
m.Cmd(SPIDE, mdb.CREATE, ice.DEV, kit.Select("http://contexts.woa.com:80", conf["ctx_dev"]))
// m.Cmd(SPIDE, mdb.CREATE, ice.SHY, kit.Select("https://contexts.com.cn:443", conf["ctx_shy"]))
m.Cmd(SPIDE, mdb.CREATE, ice.SHY, kit.Select("https://shylinux.com:443", conf["ctx_shy"]))
// m.Cmd(SPIDE, mdb.CREATE, ice.SHY, kit.Select("https://contexts.com.cn:443", conf["ctx_shy"]))
}},
mdb.CREATE: {Name: "create name address", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
_spide_create(m, m.Option(mdb.NAME), m.Option(ADDRESS))

View File

@ -178,6 +178,11 @@ func _website_render(m *ice.Message, w http.ResponseWriter, r *http.Request, kin
web.Render(msg, msg.Option(ice.MSG_OUTPUT), msg.Optionv(ice.MSG_ARGS).([]interface{})...)
return true
}
func _website_search(m *ice.Message, kind, name, text string, arg ...string) {
m.Cmd(m.PrefixKey()).Table(func(index int, value map[string]string, head []string) {
m.PushSearch(value, mdb.TEXT, m.MergeURL2(path.Join("/chat/website", value[nfs.PATH])))
})
}
const WEBSITE = "website"
@ -216,6 +221,9 @@ func init() {
}
}},
"inner": {Hand: func(m *ice.Message, arg ...string) {}},
mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) {
_website_search(m, arg[0], arg[1], kit.Select("", arg, 2))
}},
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) {
m.EchoIFrame(_website_url(m, strings.TrimPrefix(path.Join(arg[2], arg[1]), SRC_WEBSITE)))
}},

View File

@ -178,7 +178,6 @@ func init() {
Index.Register(&ice.Context{Name: GO, Help: "后端", Commands: map[string]*ice.Command{
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Cmd(mdb.SEARCH, mdb.CREATE, GODOC, m.Prefix(GO))
m.Cmd(mdb.SEARCH, mdb.CREATE, GO, m.Prefix(GO))
m.Cmd(mdb.ENGINE, mdb.CREATE, GO, m.Prefix(GO))
LoadPlug(m, GO, MOD, SUM)

View File

@ -111,6 +111,7 @@ func init() {
_inner_exec(m, arg[0], arg[1], arg[2])
}},
mdb.SEARCH: {Name: "search", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
return
m.Option(nfs.DIR_ROOT, arg[2])
m.Option(cli.CMD_DIR, kit.Path(arg[2]))
m.Cmdy(mdb.SEARCH, arg[0], arg[1], arg[2])

View File

@ -36,6 +36,9 @@ func init() {
m.Option(mdb.TEXT, strings.TrimSpace(m.Option(mdb.TEXT)))
m.Cmdy(TEMPLATE, nfs.DEFS)
}},
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
m.PushSearch(mdb.TYPE, "go", mdb.NAME, "src/main.go", mdb.TEXT, m.MergeURL2("/chat/cmd/web.code.vimer"))
}},
mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
switch m.Option(ctx.ACTION) {
case web.DREAM:

View File

@ -38,10 +38,8 @@ func init() {
)},
}, Commands: map[string]*ice.Command{
WORD: {Name: "word path=src/main.shy@key auto play", Help: "语言文字", Meta: kit.Dict(ice.DisplayLocal("")), Action: ice.MergeAction(map[string]*ice.Action{
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
m.Cmd(mdb.SEARCH, mdb.CREATE, m.CommandKey(), m.PrefixKey())
}},
mdb.SEARCH: {Name: "search", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
m.PushSearch(mdb.TYPE, "shy", mdb.NAME, "src/main.shy", mdb.TEXT, m.MergeURL2("/chat/cmd/web.wiki.word"))
m.Cmd(mdb.SELECT, m.PrefixKey(), "", mdb.HASH).Table(func(index int, value map[string]string, head []string) {
if arg[1] == "" {
if value[mdb.TYPE] == SPARK {

55
type.go
View File

@ -14,6 +14,9 @@ import (
kit "shylinux.com/x/toolkits"
)
type CommandHandler func(m *Message, c *Context, key string, arg ...string)
type ActionHandler func(m *Message, arg ...string)
type Cache struct {
Name string
Help string
@ -35,7 +38,7 @@ type Command struct {
Help string
Action map[string]*Action
Meta map[string]interface{}
Hand func(m *Message, c *Context, key string, arg ...string)
Hand CommandHandler
List []interface{}
}
type Server interface {
@ -95,6 +98,7 @@ func (c *Context) Register(s *Context, x Server, n ...string) *Context {
s.Merge(s)
return s
}
func (c *Context) Merge(s *Context) *Context {
if c.Commands == nil {
c.Commands = map[string]*Command{}
@ -129,26 +133,47 @@ func (c *Context) Merge(s *Context) *Context {
cmd.List = c.split(cmd.Name)
}
merge := func(pre *Command, before bool, key string, cmd *Command, cb ...CommandHandler) {
last := pre.Hand
pre.Hand = func(m *Message, c *Context, _key string, arg ...string) {
if before {
last(m, c, _key, arg...)
}
m._key, m._cmd = key, cmd
for _, cb := range cb {
if cb != nil {
cb(m, c, key, arg...)
}
}
m._key, m._cmd = _key, pre
if !before {
last(m, c, _key, arg...)
}
}
}
for k, a := range cmd.Action {
// if p, ok := c.Commands[k]; ok && s != c {
if p, ok := c.Commands[k]; ok {
key := key
switch last, next := p.Hand, a.Hand; k {
switch hand := a.Hand; k {
case CTX_INIT:
p.Hand = func(m *Message, c *Context, _key string, arg ...string) {
last(m, c, _key, arg...)
m._key, m._cmd = key, cmd
next(m, arg...)
m._key, m._cmd = _key, p
}
merge(p, true, key, cmd, func(m *Message, c *Context, _key string, arg ...string) {
hand(m, arg...)
})
case CTX_EXIT:
p.Hand = func(m *Message, c *Context, _key string, arg ...string) {
m._key, m._cmd = key, cmd
next(m, arg...)
m._key, m._cmd = _key, p
last(m, c, _key, arg...)
merge(p, false, key, cmd, func(m *Message, c *Context, _key string, arg ...string) {
hand(m, arg...)
})
}
}
if s != c {
switch k {
case "search":
merge(c.Commands[CTX_INIT], true, key, cmd, func(m *Message, c *Context, _key string, arg ...string) {
if m.CommandKey() != "search" {
m.Cmd("search", "create", m.CommandKey(), m.PrefixKey())
}
})
}
}
help := strings.SplitN(a.Help, "", 2)