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/nfs"
kit "shylinux.com/x/toolkits"
"shylinux.com/x/toolkits/logs"
)
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)) {
switch kit.Ext(name) {
case nfs.GO:
name = GetFileCmd(name)
case nfs.JS:
m.Push(DISPLAY, FileURI(name))
name = kit.Select(CAN_PLUGIN, GetFileCmd(name))
case nfs.GO:
name = GetFileCmd(name)
default:
if msg := m.Cmd(mdb.RENDER, kit.Ext(name)); msg.Length() > 0 {
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.") {
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.Push(mdb.INDEX, kit.Keys(s.Cap(ice.CTX_FOLLOW), key))
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) {
m.Travel(func(p *ice.Context, s *ice.Context, key string, cmd *ice.Command) {
if key[0] == '/' || key[0] == '_' {
if IsOrderCmd(key) {
return
}
if name != "" && !strings.HasPrefix(key, name) && !strings.Contains(s.Name, name) {
return
}
m.PushSearch(ice.CTX, kit.PathName(1), ice.CMD, kit.FileName(1),
kit.SimpleKV("", s.Cap(ice.CTX_FOLLOW), cmd.Name, cmd.Help),
CONTEXT, s.Cap(ice.CTX_FOLLOW), COMMAND, key, mdb.HELP, cmd.Help,
INDEX, kit.Keys(s.Cap(ice.CTX_FOLLOW), key),
nfs.FILE, FileURI(cmd.GetFileLine()),
m.PushSearch(ice.CTX, kit.PathName(1), ice.CMD, kit.FileName(1), 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),
mdb.HELP, cmd.Help, nfs.FILE, FileURI(cmd.GetFileLine()),
)
})
}
@ -112,20 +109,8 @@ func init() {
var runChecker = []func(*ice.Message, string, string, ...string) bool{}
func AddRunChecker(cb func(*ice.Message, string, string, ...string) bool) { runChecker = append(runChecker, cb) }
func init() {
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 AddRunChecker(cb func(*ice.Message, string, string, ...string) bool) {
runChecker = append(runChecker, cb)
}
func Run(m *ice.Message, arg ...string) {
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 {
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 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 {
return ice.Actions{ice.CTX_INIT: mdb.AutoConfig(args...),
COMMAND: {Hand: func(m *ice.Message, arg ...string) {
if !PodCmd(m, COMMAND, arg) {
m.Cmdy(COMMAND, arg)
}
}},
ice.RUN: {Hand: Run},
}}, ice.RUN: {Hand: Run},
}
}
func FileURI(dir string) string {
if dir == "" {
return ""
}
if strings.Contains(dir, "/go/pkg/mod/") {
} else if strings.Contains(dir, "/go/pkg/mod/") {
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) {
dir = strings.TrimPrefix(dir, ice.Info.Make.Path+ice.PS)
if path.IsAbs(dir) {
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) {
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
return path.Join(ice.PS, ice.REQUIRE, 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 IsOrderCmd(key string) bool { return key[0] == '/' || key[0] == '_' }
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) {
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)} {
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) {
m.Search(cmds, func(key string, cmd *ice.Command) {
if cmd.RawHand != nil {
for k, v := range ice.Info.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)
if file = strings.TrimPrefix(FileURI(kit.Split(cmd.GetFileLine(), ice.DF)[0]), "/require/"); !nfs.ExistsFile(m, file) {
file = path.Join(ice.ISH_PLUGED, file)
}
})
return
@ -227,11 +197,9 @@ func TravelCmd(m *ice.Message, cb func(key, file, line string)) *ice.Message {
if IsOrderCmd(key) {
return
}
if ls := kit.Split(cmd.GetFileLine(), ice.DF); len(ls) > 1 {
cb(kit.Keys(s.Cap(ice.CTX_FOLLOW), key), strings.TrimPrefix(ls[0], kit.Path("")+ice.PS), ls[1])
} else {
m.Warn(true, "not found", cmd.Name, cmd.GetFileLine())
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), kit.Select("1", ls, 1))
}
})
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) {
msg := m.Spawn(m.Source())
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:])
}
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{
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:]...) }},
"list": {Hand: func(m *ice.Message, arg ...string) {
mdb.LIST: {Hand: func(m *ice.Message, arg ...string) {
list := []ice.Any{}
for _, v := range arg[2:] {
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() {
ice.Info.Save = Save
ice.Info.Load = Load

View File

@ -28,16 +28,14 @@ func init() {
Index.MergeCommands(ice.Commands{
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) {
if len(arg) == 0 || arg[1] == CONTEXT { // 模块列表
if len(arg) == 0 || arg[1] == 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)
} 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.Push(nfs.FILE, arg[1])
})
} else { // 命令详情
} else {
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) {
msg := m.Spawn(s)
defer m.Copy(msg)
switch kit.Select(CONTEXT, arg, 1) {
case CONTEXT:
_context_list(msg, s, arg[0])
@ -70,7 +67,6 @@ func Inputs(m *ice.Message, field string) bool {
case ice.CMD:
m.Cmdy(CONTEXT, kit.Select(m.Option(ice.CTX), m.Option(kit.Keys(mdb.EXTRA, ice.CTX))), COMMAND)
case ice.ARG:
default:
return false
}

View File

@ -9,20 +9,11 @@ import (
"shylinux.com/x/toolkits/logs"
)
const MESSAGE = "message"
const OPTION = "option"
const MESSAGE = "message"
func init() {
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) {
if len(arg) > 1 {
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{}
func AddProcess(key string, val ice.Any) { _process[key] = val }
func Process(m *ice.Message, key string, args []string, arg ...string) {
switch cb := _process[key].(type) {
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) {
if len(arg) > 0 && arg[0] == ice.RUN {
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) {
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...)))
}
func ProcessField(m *ice.Message, cmd string, args []string, arg ...string) {
cmd = kit.Select(m.PrefixKey(), cmd)
if len(arg) == 0 || arg[0] != ice.RUN {
if cmd = kit.Select(m.PrefixKey(), cmd); len(arg) == 0 || arg[0] == ice.RUN {
m.Option("_index", m.PrefixKey())
if m.Cmdy(COMMAND, cmd).ProcessField(ACTION, m.ActionKey(), ice.RUN); len(args) > 0 {
m.Push(ARGS, kit.Format(args))
}
return
}
if aaa.Right(m, cmd, arg[1:]) {
m.Cmdy(cmd, arg[1:])
} else {
if aaa.Right(m, cmd, arg[1:]) {
m.Cmdy(cmd, arg[1:])
}
}
}
func ProcessFloat(m *ice.Message, arg ...string) {

View File

@ -6,15 +6,19 @@ import (
kit "shylinux.com/x/toolkits"
)
const (
LISTEN = "listen"
HAPPEN = "happen"
)
const EVENT = "event"
func init() {
Index.MergeCommands(ice.Commands{
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))
}},
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) {
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 {
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 {
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"
)
const (
LISTEN = "listen"
HAPPEN = "happen"
ERROR = "error"
START = "start"
RESTART = "restart"
STOP = "stop"
ERROR = "error"
KILL = "kill"
)
const SIGNAL = "signal"
func init() {
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) {
_signal_listen(m, 2, mdb.NAME, "重启", ice.CMD, "exit 1")
_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) {
_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)
}},
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)
}},
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)))))
}},
}, mdb.HashAction(mdb.SHORT, SIGNAL, mdb.FIELD, "time,signal,name,cmd", mdb.ACTION, HAPPEN)), Hand: func(m *ice.Message, arg ...string) {