1
0
forked from x/icebergs
This commit is contained in:
harveyshao 2022-11-24 00:28:33 +08:00
parent ad0a0e95df
commit 8a9bb181a5
8 changed files with 89 additions and 120 deletions

View File

@ -9,17 +9,25 @@ import (
"shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/nfs" "shylinux.com/x/icebergs/base/nfs"
kit "shylinux.com/x/toolkits" kit "shylinux.com/x/toolkits"
"shylinux.com/x/toolkits/logs"
) )
func _command_list(m *ice.Message, name string) *ice.Message { func _command_list(m *ice.Message, name string) *ice.Message {
if name == "" {
for k, v := range m.Source().Commands {
if IsOrderCmd(k) {
continue
}
m.Push(mdb.KEY, k).Push(mdb.NAME, v.Name).Push(mdb.HELP, v.Help)
}
return m.Sort(mdb.KEY)
}
if nfs.ExistsFile(m, path.Join(ice.SRC, name)) { if nfs.ExistsFile(m, path.Join(ice.SRC, name)) {
switch kit.Ext(name) { switch kit.Ext(name) {
case nfs.GO:
name = GetFileCmd(name)
case nfs.JS: case nfs.JS:
m.Push(DISPLAY, FileURI(name)) m.Push(DISPLAY, FileURI(name))
name = kit.Select(CAN_PLUGIN, GetFileCmd(name)) name = kit.Select(CAN_PLUGIN, GetFileCmd(name))
case nfs.GO:
name = GetFileCmd(name)
default: default:
if msg := m.Cmd(mdb.RENDER, kit.Ext(name)); msg.Length() > 0 { if msg := m.Cmd(mdb.RENDER, kit.Ext(name)); msg.Length() > 0 {
m.Push(ARGS, kit.Format(kit.List(name))) m.Push(ARGS, kit.Format(kit.List(name)))
@ -30,15 +38,6 @@ func _command_list(m *ice.Message, name string) *ice.Message {
if strings.HasPrefix(name, "can.") { if strings.HasPrefix(name, "can.") {
return m.Push(mdb.INDEX, name) return m.Push(mdb.INDEX, name)
} }
if name == "" {
for k, v := range m.Source().Commands {
if k[0] == '/' || k[0] == '_' {
continue
}
m.Push(mdb.KEY, k).Push(mdb.NAME, v.Name).Push(mdb.HELP, v.Help)
}
return m.Sort(mdb.KEY)
}
m.Spawn(m.Source()).Search(name, func(p *ice.Context, s *ice.Context, key string, cmd *ice.Command) { m.Spawn(m.Source()).Search(name, func(p *ice.Context, s *ice.Context, key string, cmd *ice.Command) {
m.Push(mdb.INDEX, kit.Keys(s.Cap(ice.CTX_FOLLOW), key)) m.Push(mdb.INDEX, kit.Keys(s.Cap(ice.CTX_FOLLOW), key))
m.Push(mdb.NAME, kit.Format(cmd.Name)) m.Push(mdb.NAME, kit.Format(cmd.Name))
@ -50,17 +49,15 @@ func _command_list(m *ice.Message, name string) *ice.Message {
} }
func _command_search(m *ice.Message, kind, name, text string) { func _command_search(m *ice.Message, kind, name, text string) {
m.Travel(func(p *ice.Context, s *ice.Context, key string, cmd *ice.Command) { m.Travel(func(p *ice.Context, s *ice.Context, key string, cmd *ice.Command) {
if key[0] == '/' || key[0] == '_' { if IsOrderCmd(key) {
return return
} }
if name != "" && !strings.HasPrefix(key, name) && !strings.Contains(s.Name, name) { if name != "" && !strings.HasPrefix(key, name) && !strings.Contains(s.Name, name) {
return return
} }
m.PushSearch(ice.CTX, kit.PathName(1), ice.CMD, kit.FileName(1), m.PushSearch(ice.CTX, kit.PathName(1), ice.CMD, kit.FileName(1), kit.SimpleKV("", s.Cap(ice.CTX_FOLLOW), cmd.Name, cmd.Help),
kit.SimpleKV("", s.Cap(ice.CTX_FOLLOW), cmd.Name, cmd.Help), CONTEXT, s.Cap(ice.CTX_FOLLOW), COMMAND, key, INDEX, kit.Keys(s.Cap(ice.CTX_FOLLOW), key),
CONTEXT, s.Cap(ice.CTX_FOLLOW), COMMAND, key, mdb.HELP, cmd.Help, mdb.HELP, cmd.Help, nfs.FILE, FileURI(cmd.GetFileLine()),
INDEX, kit.Keys(s.Cap(ice.CTX_FOLLOW), key),
nfs.FILE, FileURI(cmd.GetFileLine()),
) )
}) })
} }
@ -112,20 +109,8 @@ func init() {
var runChecker = []func(*ice.Message, string, string, ...string) bool{} var runChecker = []func(*ice.Message, string, string, ...string) bool{}
func AddRunChecker(cb func(*ice.Message, string, string, ...string) bool) { runChecker = append(runChecker, cb) } func AddRunChecker(cb func(*ice.Message, string, string, ...string) bool) {
func init() { runChecker = append(runChecker, cb)
AddRunChecker(func(m *ice.Message, cmd, sub string, arg ...string) bool {
switch sub {
case mdb.REMOVE:
m.Cmd(CONFIG, mdb.REMOVE, cmd)
return true
case mdb.SELECT:
ProcessFloat(m, CONFIG, cmd)
return true
default:
return false
}
})
} }
func Run(m *ice.Message, arg ...string) { func Run(m *ice.Message, arg ...string) {
if len(arg) > 3 && arg[1] == ACTION && arg[2] == CONFIG { if len(arg) > 3 && arg[1] == ACTION && arg[2] == CONFIG {
@ -144,56 +129,49 @@ func PodCmd(m *ice.Message, arg ...ice.Any) bool {
if m.Option(ice.POD, ""); len(kit.Simple(m.Optionv(ice.MSG_UPLOAD))) == 1 { if m.Option(ice.POD, ""); len(kit.Simple(m.Optionv(ice.MSG_UPLOAD))) == 1 {
m.Cmdy("cache", "upload").Option(ice.MSG_UPLOAD, m.Append(mdb.HASH), m.Append(mdb.NAME), m.Append(nfs.SIZE)) m.Cmdy("cache", "upload").Option(ice.MSG_UPLOAD, m.Append(mdb.HASH), m.Append(mdb.NAME), m.Append(nfs.SIZE))
} }
m.Cmdy(append(kit.List(ice.SPACE, pod), arg...)) m.Cmdy(append(kit.List(ice.SPACE, pod), arg...)...)
return true return true
} }
return false return false
} }
func CmdHandler(args ...ice.Any) ice.Handler { return func(m *ice.Message, arg ...string) { m.Cmdy(args...) } } func CmdHandler(args ...ice.Any) ice.Handler {
return func(m *ice.Message, arg ...string) { m.Cmdy(args...) }
}
func CmdAction(args ...ice.Any) ice.Actions { func CmdAction(args ...ice.Any) ice.Actions {
return ice.Actions{ice.CTX_INIT: mdb.AutoConfig(args...), return ice.Actions{ice.CTX_INIT: mdb.AutoConfig(args...),
COMMAND: {Hand: func(m *ice.Message, arg ...string) { COMMAND: {Hand: func(m *ice.Message, arg ...string) {
if !PodCmd(m, COMMAND, arg) { if !PodCmd(m, COMMAND, arg) {
m.Cmdy(COMMAND, arg) m.Cmdy(COMMAND, arg)
} }
}}, }}, ice.RUN: {Hand: Run},
ice.RUN: {Hand: Run},
} }
} }
func FileURI(dir string) string { func FileURI(dir string) string {
if dir == "" { if dir == "" {
return "" return ""
} } else if strings.Contains(dir, "/go/pkg/mod/") {
if strings.Contains(dir, "/go/pkg/mod/") {
return path.Join(ice.PS, ice.REQUIRE, strings.Split(dir, "/go/pkg/mod/")[1]) return path.Join(ice.PS, ice.REQUIRE, strings.Split(dir, "/go/pkg/mod/")[1])
} }
if ice.Info.Make.Path != "" && strings.HasPrefix(dir, ice.Info.Make.Path+ice.PS) { if path.IsAbs(dir) {
dir = strings.TrimPrefix(dir, ice.Info.Make.Path+ice.PS) if strings.HasPrefix(dir, kit.Path("")+ice.PS) {
dir = strings.TrimPrefix(dir, kit.Path("")+ice.PS)
} else if ice.Info.Make.Path != "" && strings.HasPrefix(dir, ice.Info.Make.Path+ice.PS) {
dir = strings.TrimPrefix(dir, ice.Info.Make.Path+ice.PS)
}
} else if nfs.ExistsFile(ice.Pulse, path.Join(ice.SRC, dir)) {
dir = path.Join(ice.SRC, dir)
} }
if strings.HasPrefix(dir, kit.Path("")+ice.PS) { return path.Join(ice.PS, ice.REQUIRE, dir)
dir = strings.TrimPrefix(dir, kit.Path("")+ice.PS)
}
if strings.HasPrefix(dir, ice.USR) {
return path.Join(ice.PS, ice.REQUIRE, dir)
}
if strings.HasPrefix(dir, ice.SRC) {
return path.Join(ice.PS, ice.REQUIRE, dir)
}
if nfs.ExistsFile(ice.Pulse, path.Join(ice.SRC, dir)) {
return path.Join(ice.PS, ice.REQUIRE, ice.SRC, dir)
}
return dir
} }
func FileCmd(dir string) string { return FileURI(kit.ExtChange(strings.Split(dir, ice.DF)[0], nfs.GO)) } func FileCmd(dir string) string { return FileURI(kit.ExtChange(strings.Split(dir, ice.DF)[0], nfs.GO)) }
func AddFileCmd(dir, key string) { ice.Info.File[FileCmd(dir)] = key } func AddFileCmd(dir, key string) { ice.Info.File[FileCmd(dir)] = key }
func IsOrderCmd(key string) bool { return key[0] == '/' || key[0] == '_' } func IsOrderCmd(key string) bool { return key[0] == '/' || key[0] == '_' }
func GetFileCmd(dir string) string { func GetFileCmd(dir string) string {
if strings.HasPrefix(dir, ice.ISH_PLUGED) {
dir = path.Join(ice.PS, ice.REQUIRE, strings.TrimPrefix(dir, ice.ISH_PLUGED))
}
if strings.HasPrefix(dir, ice.REQUIRE+ice.PS) { if strings.HasPrefix(dir, ice.REQUIRE+ice.PS) {
dir = ice.PS + dir dir = ice.PS + dir
} else if strings.HasPrefix(dir, ice.ISH_PLUGED) {
dir = path.Join(ice.PS, ice.REQUIRE, strings.TrimPrefix(dir, ice.ISH_PLUGED))
} }
for _, dir := range []string{dir, path.Join(ice.PS, ice.REQUIRE, ice.Info.Make.Module, dir), path.Join(ice.PS, ice.REQUIRE, ice.Info.Make.Module, ice.SRC, dir)} { for _, dir := range []string{dir, path.Join(ice.PS, ice.REQUIRE, ice.Info.Make.Module, dir), path.Join(ice.PS, ice.REQUIRE, ice.Info.Make.Module, ice.SRC, dir)} {
if cmd, ok := ice.Info.File[FileCmd(dir)]; ok { if cmd, ok := ice.Info.File[FileCmd(dir)]; ok {
@ -208,16 +186,8 @@ func GetFileCmd(dir string) string {
} }
func GetCmdFile(m *ice.Message, cmds string) (file string) { func GetCmdFile(m *ice.Message, cmds string) (file string) {
m.Search(cmds, func(key string, cmd *ice.Command) { m.Search(cmds, func(key string, cmd *ice.Command) {
if cmd.RawHand != nil { if file = strings.TrimPrefix(FileURI(kit.Split(cmd.GetFileLine(), ice.DF)[0]), "/require/"); !nfs.ExistsFile(m, file) {
for k, v := range ice.Info.File { file = path.Join(ice.ISH_PLUGED, file)
if v == cmds {
file = strings.Replace(k, "/require/", ice.ISH_PLUGED, 1)
break
}
}
} else {
file = kit.Split(logs.FileLines(cmd.Hand), ice.DF)[0]
file = strings.TrimPrefix(file, kit.Path("")+ice.PS)
} }
}) })
return return
@ -227,10 +197,8 @@ func TravelCmd(m *ice.Message, cb func(key, file, line string)) *ice.Message {
if IsOrderCmd(key) { if IsOrderCmd(key) {
return return
} }
if ls := kit.Split(cmd.GetFileLine(), ice.DF); len(ls) > 1 { if ls := kit.Split(cmd.GetFileLine(), ice.DF); !m.Warn(len(ls) == 0, ice.ErrNotFound, key) {
cb(kit.Keys(s.Cap(ice.CTX_FOLLOW), key), strings.TrimPrefix(ls[0], kit.Path("")+ice.PS), ls[1]) cb(kit.Keys(s.Cap(ice.CTX_FOLLOW), key), strings.TrimPrefix(ls[0], kit.Path("")+ice.PS), kit.Select("1", ls, 1))
} else {
m.Warn(true, "not found", cmd.Name, cmd.GetFileLine())
} }
}) })
return m return m

View File

@ -51,7 +51,7 @@ func _config_load(m *ice.Message, name string, arg ...string) {
func _config_make(m *ice.Message, key string, arg ...string) { func _config_make(m *ice.Message, key string, arg ...string) {
msg := m.Spawn(m.Source()) msg := m.Spawn(m.Source())
if len(arg) > 1 { if len(arg) > 1 {
if strings.HasPrefix(arg[1], "@") { if strings.HasPrefix(arg[1], ice.AT) {
arg[1] = msg.Cmdx(nfs.CAT, arg[1][1:]) arg[1] = msg.Cmdx(nfs.CAT, arg[1][1:])
} }
msg.Confv(key, arg[0], kit.Parse(nil, "", arg[1:]...)) msg.Confv(key, arg[0], kit.Parse(nil, "", arg[1:]...))
@ -83,7 +83,7 @@ func init() {
CONFIG: {Name: "config key auto", Help: "配置", Actions: ice.Actions{ CONFIG: {Name: "config key auto", Help: "配置", Actions: ice.Actions{
SAVE: {Hand: func(m *ice.Message, arg ...string) { _config_save(m, arg[0], arg[1:]...) }}, SAVE: {Hand: func(m *ice.Message, arg ...string) { _config_save(m, arg[0], arg[1:]...) }},
LOAD: {Hand: func(m *ice.Message, arg ...string) { _config_load(m, arg[0], arg[1:]...) }}, LOAD: {Hand: func(m *ice.Message, arg ...string) { _config_load(m, arg[0], arg[1:]...) }},
"list": {Hand: func(m *ice.Message, arg ...string) { mdb.LIST: {Hand: func(m *ice.Message, arg ...string) {
list := []ice.Any{} list := []ice.Any{}
for _, v := range arg[2:] { for _, v := range arg[2:] {
list = append(list, v) list = append(list, v)
@ -104,6 +104,19 @@ func init() {
}}, }},
}) })
} }
func init() {
AddRunChecker(func(m *ice.Message, cmd, sub string, arg ...string) bool {
switch sub {
case mdb.SELECT:
ProcessFloat(m, CONFIG, cmd)
case mdb.REMOVE:
m.Cmd(CONFIG, mdb.REMOVE, cmd)
default:
return false
}
return true
})
}
func init() { func init() {
ice.Info.Save = Save ice.Info.Save = Save
ice.Info.Load = Load ice.Info.Load = Load

View File

@ -28,16 +28,14 @@ func init() {
Index.MergeCommands(ice.Commands{ Index.MergeCommands(ice.Commands{
CONTEXT: {Name: "context name=web action=context,command,config key auto spide", Help: "模块", Actions: ice.MergeActions(ice.Actions{ CONTEXT: {Name: "context name=web action=context,command,config key auto spide", Help: "模块", Actions: ice.MergeActions(ice.Actions{
"spide": {Name: "spide", Help: "架构图", Hand: func(m *ice.Message, arg ...string) { "spide": {Name: "spide", Help: "架构图", Hand: func(m *ice.Message, arg ...string) {
if len(arg) == 0 || arg[1] == CONTEXT { // 模块列表 if len(arg) == 0 || arg[1] == CONTEXT {
m.Cmdy(CONTEXT, kit.Select(ice.ICE, arg, 0), CONTEXT) m.Cmdy(CONTEXT, kit.Select(ice.ICE, arg, 0), CONTEXT)
DisplayStorySpide(m, lex.PREFIX, m.ActionKey(), nfs.ROOT, kit.Select(ice.ICE, arg, 0), lex.SPLIT, ice.PT) DisplayStorySpide(m, lex.PREFIX, m.ActionKey(), nfs.ROOT, kit.Select(ice.ICE, arg, 0), lex.SPLIT, ice.PT)
} else if index := kit.Keys(arg[1]); strings.HasSuffix(index, arg[2]) {
} else if index := kit.Keys(arg[1]); strings.HasSuffix(index, arg[2]) { // 命令列表
m.Cmdy(CONTEXT, index, COMMAND, func(value ice.Maps) { m.Cmdy(CONTEXT, index, COMMAND, func(value ice.Maps) {
m.Push(nfs.FILE, arg[1]) m.Push(nfs.FILE, arg[1])
}) })
} else {
} else { // 命令详情
m.Cmdy(COMMAND, kit.Keys(index, strings.Split(arg[2], ice.SP)[0])) m.Cmdy(COMMAND, kit.Keys(index, strings.Split(arg[2], ice.SP)[0]))
} }
}}, }},
@ -48,7 +46,6 @@ func init() {
m.Search(arg[0]+ice.PT, func(p *ice.Context, s *ice.Context, key string) { m.Search(arg[0]+ice.PT, func(p *ice.Context, s *ice.Context, key string) {
msg := m.Spawn(s) msg := m.Spawn(s)
defer m.Copy(msg) defer m.Copy(msg)
switch kit.Select(CONTEXT, arg, 1) { switch kit.Select(CONTEXT, arg, 1) {
case CONTEXT: case CONTEXT:
_context_list(msg, s, arg[0]) _context_list(msg, s, arg[0])
@ -70,7 +67,6 @@ func Inputs(m *ice.Message, field string) bool {
case ice.CMD: case ice.CMD:
m.Cmdy(CONTEXT, kit.Select(m.Option(ice.CTX), m.Option(kit.Keys(mdb.EXTRA, ice.CTX))), COMMAND) m.Cmdy(CONTEXT, kit.Select(m.Option(ice.CTX), m.Option(kit.Keys(mdb.EXTRA, ice.CTX))), COMMAND)
case ice.ARG: case ice.ARG:
default: default:
return false return false
} }

View File

@ -9,20 +9,11 @@ import (
"shylinux.com/x/toolkits/logs" "shylinux.com/x/toolkits/logs"
) )
const MESSAGE = "message"
const OPTION = "option" const OPTION = "option"
const MESSAGE = "message"
func init() { func init() {
Index.MergeCommands(ice.Commands{ Index.MergeCommands(ice.Commands{
MESSAGE: {Name: "message", Help: "消息", Hand: func(m *ice.Message, arg ...string) {
t := reflect.TypeOf(m)
for i := 0; i < t.NumMethod(); i++ {
method := t.Method(i)
p := logs.FileLine(method.Func.Interface())
m.Push(mdb.NAME, method.Name)
m.Push(mdb.TEXT, strings.Split(p, ice.ICEBERGS+"/")[1])
}
}},
OPTION: {Name: "option", Help: "选项", Hand: func(m *ice.Message, arg ...string) { OPTION: {Name: "option", Help: "选项", Hand: func(m *ice.Message, arg ...string) {
if len(arg) > 1 { if len(arg) > 1 {
if msg, ok := m.Optionv("message").(*ice.Message); ok { if msg, ok := m.Optionv("message").(*ice.Message); ok {
@ -30,5 +21,14 @@ func init() {
} }
} }
}}, }},
MESSAGE: {Name: "message auto", Help: "消息", Hand: func(m *ice.Message, arg ...string) {
t := reflect.TypeOf(m)
for i := 0; i < t.NumMethod(); i++ {
method := t.Method(i)
p := logs.FileLine(method.Func.Interface())
m.Push(mdb.NAME, method.Name)
m.Push(mdb.TEXT, strings.Split(p, ice.ICEBERGS+ice.PS)[1])
}
}},
}) })
} }

View File

@ -11,7 +11,6 @@ const PROCESS = "process"
var _process = map[string]ice.Any{} var _process = map[string]ice.Any{}
func AddProcess(key string, val ice.Any) { _process[key] = val } func AddProcess(key string, val ice.Any) { _process[key] = val }
func Process(m *ice.Message, key string, args []string, arg ...string) { func Process(m *ice.Message, key string, args []string, arg ...string) {
switch cb := _process[key].(type) { switch cb := _process[key].(type) {
case func(*ice.Message, []string, ...string): case func(*ice.Message, []string, ...string):
@ -30,11 +29,10 @@ func Process(m *ice.Message, key string, args []string, arg ...string) {
func ProcessCommand(m *ice.Message, cmd string, val []string, arg ...string) { func ProcessCommand(m *ice.Message, cmd string, val []string, arg ...string) {
if len(arg) > 0 && arg[0] == ice.RUN { if len(arg) > 0 && arg[0] == ice.RUN {
m.Cmdy(cmd, arg[1:]) m.Cmdy(cmd, arg[1:])
return } else {
m.Cmdy(COMMAND, cmd).Push(ice.ARG, kit.Format(val))
m.ProcessField(cmd, ice.RUN)
} }
m.Cmdy(COMMAND, cmd)
m.ProcessField(cmd, ice.RUN)
m.Push(ice.ARG, kit.Format(val))
} }
func ProcessCommandOpt(m *ice.Message, arg []string, args ...string) { func ProcessCommandOpt(m *ice.Message, arg []string, args ...string) {
if len(arg) > 0 && arg[0] == ice.RUN { if len(arg) > 0 && arg[0] == ice.RUN {
@ -43,16 +41,15 @@ func ProcessCommandOpt(m *ice.Message, arg []string, args ...string) {
m.Push("opt", kit.Format(m.OptionSimple(args...))) m.Push("opt", kit.Format(m.OptionSimple(args...)))
} }
func ProcessField(m *ice.Message, cmd string, args []string, arg ...string) { func ProcessField(m *ice.Message, cmd string, args []string, arg ...string) {
cmd = kit.Select(m.PrefixKey(), cmd) if cmd = kit.Select(m.PrefixKey(), cmd); len(arg) == 0 || arg[0] == ice.RUN {
if len(arg) == 0 || arg[0] != ice.RUN {
m.Option("_index", m.PrefixKey()) m.Option("_index", m.PrefixKey())
if m.Cmdy(COMMAND, cmd).ProcessField(ACTION, m.ActionKey(), ice.RUN); len(args) > 0 { if m.Cmdy(COMMAND, cmd).ProcessField(ACTION, m.ActionKey(), ice.RUN); len(args) > 0 {
m.Push(ARGS, kit.Format(args)) m.Push(ARGS, kit.Format(args))
} }
return } else {
} if aaa.Right(m, cmd, arg[1:]) {
if aaa.Right(m, cmd, arg[1:]) { m.Cmdy(cmd, arg[1:])
m.Cmdy(cmd, arg[1:]) }
} }
} }
func ProcessFloat(m *ice.Message, arg ...string) { func ProcessFloat(m *ice.Message, arg ...string) {

View File

@ -6,15 +6,19 @@ import (
kit "shylinux.com/x/toolkits" kit "shylinux.com/x/toolkits"
) )
const (
LISTEN = "listen"
HAPPEN = "happen"
)
const EVENT = "event" const EVENT = "event"
func init() { func init() {
Index.MergeCommands(ice.Commands{ Index.MergeCommands(ice.Commands{
EVENT: {Name: "event event id auto listen happen", Help: "事件流", Actions: ice.MergeActions(ice.Actions{ EVENT: {Name: "event event id auto listen happen", Help: "事件流", Actions: ice.MergeActions(ice.Actions{
LISTEN: {Name: "listen event cmd", Help: "监听", Hand: func(m *ice.Message, arg ...string) { LISTEN: {Name: "listen event cmd", Hand: func(m *ice.Message, arg ...string) {
mdb.ZoneInsert(m, m.OptionSimple(EVENT, ice.CMD)) mdb.ZoneInsert(m, m.OptionSimple(EVENT, ice.CMD))
}}, }},
HAPPEN: {Name: "happen event arg", Help: "触发", Hand: func(m *ice.Message, arg ...string) { HAPPEN: {Name: "happen event arg", Hand: func(m *ice.Message, arg ...string) {
mdb.ZoneSelect(m.Spawn(ice.OptionFields("")), m.Option(EVENT)).Tables(func(value ice.Maps) { mdb.ZoneSelect(m.Spawn(ice.OptionFields("")), m.Option(EVENT)).Tables(func(value ice.Maps) {
m.Cmdy(kit.Split(value[ice.CMD]), m.Option(EVENT), arg[2:], ice.OptionFields("")).Cost() m.Cmdy(kit.Split(value[ice.CMD]), m.Option(EVENT), arg[2:], ice.OptionFields("")).Cost()
}) })
@ -35,8 +39,8 @@ func Watch(m *ice.Message, key string, arg ...string) *ice.Message {
if len(arg) == 0 { if len(arg) == 0 {
arg = append(arg, m.PrefixKey()) arg = append(arg, m.PrefixKey())
} }
return m.Cmd("gdb.event", LISTEN, EVENT, key, ice.CMD, kit.Join(arg, ice.SP)) return m.Cmd(EVENT, LISTEN, EVENT, key, ice.CMD, kit.Join(arg, ice.SP))
} }
func Event(m *ice.Message, key string, arg ...ice.Any) *ice.Message { func Event(m *ice.Message, key string, arg ...ice.Any) *ice.Message {
return m.Cmdy("gdb.event", HAPPEN, EVENT, kit.Select(kit.Keys(m.CommandKey(), m.ActionKey()), key), arg) return m.Cmdy(EVENT, HAPPEN, EVENT, kit.Select(kit.Keys(m.CommandKey(), m.ActionKey()), key), arg)
} }

View File

@ -1,6 +0,0 @@
chapter "gdb"
field "协程池" routine
field "信号量" signal
field "事件流" event
field "定时器" timer

View File

@ -41,20 +41,17 @@ const (
PID = "pid" PID = "pid"
) )
const ( const (
LISTEN = "listen" ERROR = "error"
HAPPEN = "happen"
START = "start" START = "start"
RESTART = "restart" RESTART = "restart"
STOP = "stop" STOP = "stop"
ERROR = "error"
KILL = "kill" KILL = "kill"
) )
const SIGNAL = "signal" const SIGNAL = "signal"
func init() { func init() {
Index.MergeCommands(ice.Commands{ Index.MergeCommands(ice.Commands{
SIGNAL: {Name: "signal signal auto listen", Help: "信号", Actions: ice.MergeActions(ice.Actions{ SIGNAL: {Name: "signal signal auto listen", Help: "信号", Actions: ice.MergeActions(ice.Actions{
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
_signal_listen(m, 2, mdb.NAME, "重启", ice.CMD, "exit 1") _signal_listen(m, 2, mdb.NAME, "重启", ice.CMD, "exit 1")
_signal_listen(m, 3, mdb.NAME, "退出", ice.CMD, "exit 0") _signal_listen(m, 3, mdb.NAME, "退出", ice.CMD, "exit 0")
@ -70,13 +67,13 @@ func init() {
HAPPEN: {Name: "happen signal", Help: "触发", Hand: func(m *ice.Message, arg ...string) { HAPPEN: {Name: "happen signal", Help: "触发", Hand: func(m *ice.Message, arg ...string) {
_signal_action(m, m.Option(SIGNAL)) _signal_action(m, m.Option(SIGNAL))
}}, }},
RESTART: {Name: "restart pid", Help: "触发", Hand: func(m *ice.Message, arg ...string) { RESTART: {Name: "restart pid", Help: "重启", Hand: func(m *ice.Message, arg ...string) {
_signal_process(m, m.Option(PID), syscall.SIGINT) _signal_process(m, m.Option(PID), syscall.SIGINT)
}}, }},
STOP: {Name: "stop pid", Help: "触发", Hand: func(m *ice.Message, arg ...string) { STOP: {Name: "stop pid", Help: "停止", Hand: func(m *ice.Message, arg ...string) {
_signal_process(m, m.Option(PID), syscall.SIGQUIT) _signal_process(m, m.Option(PID), syscall.SIGQUIT)
}}, }},
KILL: {Name: "kill pid signal", Help: "触发", Hand: func(m *ice.Message, arg ...string) { KILL: {Name: "kill pid signal", Help: "结束", Hand: func(m *ice.Message, arg ...string) {
_signal_process(m, m.Option(PID), syscall.Signal(kit.Int(kit.Select("9", m.Option(SIGNAL))))) _signal_process(m, m.Option(PID), syscall.Signal(kit.Int(kit.Select("9", m.Option(SIGNAL)))))
}}, }},
}, mdb.HashAction(mdb.SHORT, SIGNAL, mdb.FIELD, "time,signal,name,cmd", mdb.ACTION, HAPPEN)), Hand: func(m *ice.Message, arg ...string) { }, mdb.HashAction(mdb.SHORT, SIGNAL, mdb.FIELD, "time,signal,name,cmd", mdb.ACTION, HAPPEN)), Hand: func(m *ice.Message, arg ...string) {