From 56576f958f20e6152076e4ef618e0f761e75b8fd Mon Sep 17 00:00:00 2001 From: harveyshao Date: Tue, 1 Nov 2022 20:00:39 +0800 Subject: [PATCH] opt some --- base/ctx/config.go | 4 ++-- base/web/cache.go | 2 +- conf.go | 31 +++++++++---------------------- core/code/xterm.go | 4 ++-- core/wiki/word.go | 2 +- exec.go | 10 +++------- init.go | 7 +++++++ 7 files changed, 25 insertions(+), 35 deletions(-) diff --git a/base/ctx/config.go b/base/ctx/config.go index 6ef44845..685d0aaa 100644 --- a/base/ctx/config.go +++ b/base/ctx/config.go @@ -139,7 +139,7 @@ func Save(m *ice.Message, arg ...string) *ice.Message { for i, k := range arg { arg[i] = m.Prefix(k) } - return m.Cmd(CONFIG, ice.SAVE, m.Prefix(nfs.JSON), arg) + return m.Cmd(CONFIG, SAVE, m.Prefix(nfs.JSON), arg) } func Load(m *ice.Message, arg ...string) *ice.Message { if len(arg) == 0 { @@ -150,7 +150,7 @@ func Load(m *ice.Message, arg ...string) *ice.Message { for i, k := range arg { arg[i] = m.Prefix(k) } - return m.Cmd(CONFIG, ice.LOAD, m.Prefix(nfs.JSON), arg) + return m.Cmd(CONFIG, LOAD, m.Prefix(nfs.JSON), arg) } func ConfAction(args ...ice.Any) ice.Actions { return ice.Actions{ice.CTX_INIT: mdb.AutoConfig(args...)} diff --git a/base/web/cache.go b/base/web/cache.go index b0469c4b..30871d81 100644 --- a/base/web/cache.go +++ b/base/web/cache.go @@ -158,7 +158,7 @@ func init() { if p := path.Join(arg[0], up[1]); m.Option(ice.MSG_USERPOD) == "" { m.Cmdy(CACHE, WATCH, up[0], p) // 本机文件 } else { // 下发文件 - m.Cmdy(SPIDE, ice.DEV, ice.SAVE, p, SPIDE_GET, MergeURL2(m, path.Join(SHARE_CACHE, up[0]))) + m.Cmdy(SPIDE, ice.DEV, nfs.SAVE, p, SPIDE_GET, MergeURL2(m, path.Join(SHARE_CACHE, up[0]))) } }}, }, mdb.HashAction(mdb.SHORT, mdb.TEXT, mdb.FIELD, "time,hash,size,type,name,text,file")), Hand: func(m *ice.Message, arg ...string) { diff --git a/conf.go b/conf.go index e4d6bfc0..9d9bc524 100644 --- a/conf.go +++ b/conf.go @@ -18,22 +18,10 @@ const ( FAILURE = "failure" PROCESS = "process" - INIT = "init" - EXIT = "exit" - QUIT = "quit" - SAVE = "save" - LOAD = "load" - AUTO = "auto" - VIEW = "view" + HTTP = "http" LIST = "list" BACK = "back" - EXEC = "exec" - - SHOW = "show" - PLAY = "play" - HELP = "help" - HTTP = "http" BASE = "base" CORE = "core" @@ -44,15 +32,15 @@ const ( OPS = "ops" ICE = "ice" - ENV = "env" - RUN = "run" - ERR = "err" - POD = "pod" CTX = "ctx" CMD = "cmd" ARG = "arg" + + ENV = "env" + RUN = "run" RES = "res" + ERR = "err" ) const ( // MOD MOD_DIR = 0750 @@ -178,17 +166,16 @@ const ( // MSG MSG_SOURCE = "_source" MSG_TARGET = "_target" MSG_HANDLE = "_handle" + MSG_DAEMON = "_daemon" + MSG_UPLOAD = "_upload" + MSG_ACTION = "_action" + MSG_STATUS = "_status" MSG_ALIAS = "_alias" MSG_SCRIPT = "_script" MSG_OUTPUT = "_output" MSG_ARGS = "_args" - MSG_UPLOAD = "_upload" - MSG_DAEMON = "_daemon" - MSG_ACTION = "_action" - MSG_STATUS = "_status" - MSG_PROCESS = "_process" MSG_DISPLAY = "_display" MSG_TOOLKIT = "_toolkit" diff --git a/core/code/xterm.go b/core/code/xterm.go index 09e9fe3c..cf705059 100644 --- a/core/code/xterm.go +++ b/core/code/xterm.go @@ -37,7 +37,7 @@ func _xterm_get(m *ice.Message, h string) _xterm { m.Assert(h != "") t := mdb.HashSelectField(m, m.Option(mdb.HASH, h), mdb.TYPE) - mdb.HashModify(m, ice.VIEW, m.Option(ice.MSG_DAEMON)) + mdb.HashModify(m, "view", m.Option(ice.MSG_DAEMON)) return mdb.HashTarget(m, h, func() ice.Any { ls := kit.Split(kit.Select(nfs.SH, t)) cmd := exec.Command(cli.SystemFind(m, ls[0]), ls[1:]...) @@ -53,7 +53,7 @@ func _xterm_get(m *ice.Message, h string) _xterm { buf := make([]byte, ice.MOD_BUFS) for { if n, e := tty.Read(buf); !m.Warn(e) && e == nil { - m.Option(ice.MSG_DAEMON, mdb.HashSelectField(m, h, ice.VIEW)) + m.Option(ice.MSG_DAEMON, mdb.HashSelectField(m, h, "view")) m.Option(mdb.TEXT, string(buf[:n])) m.Debug("what %v", m.FormatMeta()) web.PushNoticeGrow(m) diff --git a/core/wiki/word.go b/core/wiki/word.go index 504e4bb6..b46a365b 100644 --- a/core/wiki/word.go +++ b/core/wiki/word.go @@ -93,7 +93,7 @@ func init() { ice.STORY: {Name: "story", Help: "运行", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(arg[0], ice.RUN, arg[2:]) }}, - ice.PLAY: {Name: "play", Help: "演示"}, + "play": {Name: "play", Help: "演示"}, }, ctx.CmdAction(), mdb.HashAction()), Hand: func(m *ice.Message, arg ...string) { if len(arg) == 0 { arg = append(arg, "src/") diff --git a/exec.go b/exec.go index b729e92e..797efb15 100644 --- a/exec.go +++ b/exec.go @@ -17,12 +17,9 @@ func (m *Message) TryCatch(msg *Message, silent bool, hand ...func(msg *Message) case nil: default: fileline := m.FormatStack(2, 1) - m.Log(LOG_WARN, "catch: %s %s", e, fileline) - m.Log("chain", msg.FormatChain()) - m.Log(LOG_WARN, "catch: %s %s", e, fileline) - m.Log("stack", msg.FormatStack(2, 100)) - m.Log(LOG_WARN, "catch: %s %s", e, fileline) - m.Result(ErrWarn, e, " ", fileline) + m.Log(LOG_WARN, "catch: %s %s", e, fileline).Log("chain", msg.FormatChain()) + m.Log(LOG_WARN, "catch: %s %s", e, fileline).Log("stack", msg.FormatStack(2, 100)) + m.Log(LOG_WARN, "catch: %s %s", e, fileline).Result(ErrWarn, e, " ", fileline) if len(hand) > 1 { m.TryCatch(msg, silent, hand[1:]...) } else if !silent { @@ -30,7 +27,6 @@ func (m *Message) TryCatch(msg *Message, silent bool, hand ...func(msg *Message) } } }() - if len(hand) > 0 { hand[0](msg) } diff --git a/init.go b/init.go index 2f5f396a..a061e805 100644 --- a/init.go +++ b/init.go @@ -51,6 +51,13 @@ func (f *Frame) Close(m *Message, arg ...string) bool { return true } +const ( + INIT = "init" + HELP = "help" + EXIT = "exit" + QUIT = "quit" +) + var Index = &Context{Name: ICE, Help: "冰山模块", Configs: Configs{ HELP: {Value: kit.Data(INDEX, Info.Help)}, }, Commands: Commands{