From 629744f18c364d1f5dd18b3fff9b2a39b0cbb24e Mon Sep 17 00:00:00 2001 From: harveyshao Date: Mon, 9 May 2022 21:31:44 +0800 Subject: [PATCH] opt some --- base/ctx/config.go | 6 --- base/nfs/cat.go | 1 + base/web/serve.go | 5 +-- core/chat/cmd.go | 6 +-- core/chat/website.go | 4 ++ core/code/binpack.go | 16 +++++-- core/code/py.go | 18 +++++--- core/code/sh.go | 3 ++ core/code/vimer.go | 99 +++++++++++++++++++++++++++++++++----------- core/team/todo.go | 3 +- init.go | 3 +- misc/git/status.go | 2 +- render.go | 2 +- 13 files changed, 116 insertions(+), 52 deletions(-) diff --git a/base/ctx/config.go b/base/ctx/config.go index 643e2093..d59b84ba 100644 --- a/base/ctx/config.go +++ b/base/ctx/config.go @@ -34,9 +34,6 @@ func _config_save(m *ice.Message, name string, arg ...string) { for _, k := range arg { if v := msg.Confv(k); v != "" { data[k] = v - if k == "web.code.trpc.oauth" { - m.Debug("wha5 %v %v", k, v) - } } } @@ -46,9 +43,6 @@ func _config_save(m *ice.Message, name string, arg ...string) { m.Log_EXPORT(CONFIG, name, nfs.FILE, p, nfs.SIZE, n) } } - if name == "var/conf/web.code.trpc.json" { - m.Debug("wha5 %v %v %v", name, p, data) - } m.Echo(p) } } diff --git a/base/nfs/cat.go b/base/nfs/cat.go index 7eb11d67..f1723726 100644 --- a/base/nfs/cat.go +++ b/base/nfs/cat.go @@ -143,6 +143,7 @@ const ( CSV = ice.CSV JSON = ice.JSON + PY = "py" TXT = "txt" IML = "iml" XML = "xml" diff --git a/base/web/serve.go b/base/web/serve.go index 512ecac0..19573068 100644 --- a/base/web/serve.go +++ b/base/web/serve.go @@ -148,7 +148,7 @@ func _serve_handle(key string, cmd *ice.Command, msg *ice.Message, w http.Respon if r.ParseForm(); len(r.PostForm) > 0 { for k, v := range r.PostForm { if len(v) > 1 { - msg.Logs("form", k, len(v), v) + msg.Logs("form", k, len(v), kit.Format(v)) } else { msg.Logs("form", k, v) } @@ -196,13 +196,10 @@ func _serve_handle(key string, cmd *ice.Command, msg *ice.Message, w http.Respon // 输出响应 switch args := msg.Optionv(ice.MSG_ARGS).(type) { case []interface{}: - msg.Debug("what %v", args) Render(msg, msg.Option(ice.MSG_OUTPUT), args...) case []string: - msg.Debug("what %v", args) Render(msg, msg.Option(ice.MSG_OUTPUT), args) default: - msg.Debug("what %v", args) Render(msg, msg.Option(ice.MSG_OUTPUT), kit.List()) } } diff --git a/core/chat/cmd.go b/core/chat/cmd.go index 28e54c35..911cc3a6 100644 --- a/core/chat/cmd.go +++ b/core/chat/cmd.go @@ -128,11 +128,11 @@ func init() { } }}, }, mdb.HashAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - if msg := m.Cmd(ctx.COMMAND, arg[0]); msg.Length() > 0 { - m.RenderCmd(arg[0]) + if _cmd_file(m, arg...) { return } - if _cmd_file(m, arg...) { + if msg := m.Cmd(ctx.COMMAND, arg[0]); msg.Length() > 0 { + m.RenderCmd(arg[0]) return } diff --git a/core/chat/website.go b/core/chat/website.go index 6551f477..84c2d72e 100644 --- a/core/chat/website.go +++ b/core/chat/website.go @@ -222,6 +222,10 @@ func init() { }) }}, "show": {Hand: func(m *ice.Message, arg ...string) { + if kit.Ext(arg[0]) == nfs.ZML { + m.RenderCmd("can.parse", m.Cmdx(nfs.CAT, path.Join(SRC_WEBSITE, arg[0]))) + return + } if text := m.Cmd(m.PrefixKey(), ice.PS+arg[0]).Append(mdb.TEXT); text != "" { if res, ok := _website_parse(m, text, arg[1:]...); ok { m.Echo(_website_template2, kit.Format(res)) diff --git a/core/code/binpack.go b/core/code/binpack.go index e488ee0f..26e69f68 100644 --- a/core/code/binpack.go +++ b/core/code/binpack.go @@ -141,17 +141,25 @@ func init() { } _binpack_ctx(m, f) - fmt.Fprintln(f, _binpack_file(m, ice.GO_MOD)) - fmt.Fprintln(f, _binpack_file(m, ice.GO_SUM)) - fmt.Fprintln(f, _binpack_file(m, ice.MAKEFILE)) fmt.Fprintln(f, _binpack_file(m, ice.ETC_MISS_SH)) fmt.Fprintln(f, _binpack_file(m, ice.ETC_INIT_SHY)) fmt.Fprintln(f, _binpack_file(m, ice.ETC_EXIT_SHY)) + fmt.Fprintln(f) + + fmt.Fprintln(f, _binpack_file(m, ice.GO_MOD)) + fmt.Fprintln(f, _binpack_file(m, ice.GO_SUM)) + fmt.Fprintln(f, _binpack_file(m, ice.MAKEFILE)) fmt.Fprintln(f, _binpack_file(m, ice.README_MD)) fmt.Fprintln(f) m.Cmd(mdb.SELECT, m.PrefixKey(), "", mdb.HASH, ice.OptionFields(nfs.PATH)).Tables(func(value map[string]string) { - _binpack_dir(m, f, value[nfs.PATH]) + if s, e := os.Stat(value[nfs.PATH]); e == nil { + if s.IsDir() { + _binpack_dir(m, f, value[nfs.PATH]) + } else { + fmt.Fprintln(f, _binpack_file(m, value[nfs.PATH])) + } + } }) } }}, diff --git a/core/code/py.go b/core/code/py.go index 332abad5..f93adbbe 100644 --- a/core/code/py.go +++ b/core/code/py.go @@ -10,15 +10,25 @@ import ( ) const PY = "py" -const ( - PYTHON2 = "python2" -) func init() { + const PYTHON2 = "python2" Index.Merge(&ice.Context{Commands: map[string]*ice.Command{ PY: {Name: "py", Help: "脚本", Action: map[string]*ice.Action{ ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { m.Cmd(mdb.ENGINE, mdb.CREATE, PY, m.PrefixKey()) + m.Cmd(mdb.RENDER, mdb.CREATE, PY, m.PrefixKey()) + }}, + mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { + if kit.FileExists(kit.Path(arg[2], arg[1])) { + m.Cmdy(cli.SYSTEM, PYTHON2, kit.Path(arg[2], arg[1])) + } else if b, ok := ice.Info.Pack[path.Join(arg[2], arg[1])]; ok && len(b) > 0 { + m.Cmdy(cli.SYSTEM, PYTHON2, "-c", string(b)) + } + if cli.IsSuccess(m) { + m.SetAppend() + } + m.Echo(ice.NL) }}, mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { if kit.FileExists(kit.Path(arg[2], arg[1])) { @@ -28,8 +38,6 @@ func init() { } m.Echo(ice.NL) }}, - }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - }}, }}) } diff --git a/core/code/sh.go b/core/code/sh.go index e78d5d3e..c22af479 100644 --- a/core/code/sh.go +++ b/core/code/sh.go @@ -29,6 +29,9 @@ func init() { } LoadPlug(m, SH) }}, + mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { + m.Cmdy(cli.SYSTEM, SH, "-c", kit.Join(_sh_main_script(m, arg...), ice.NL)).SetAppend() + }}, mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(cli.SYSTEM, SH, "-c", kit.Join(_sh_main_script(m, arg...), ice.NL)).SetAppend() }}, diff --git a/core/code/vimer.go b/core/code/vimer.go index 3e9a1983..633f096d 100644 --- a/core/code/vimer.go +++ b/core/code/vimer.go @@ -24,13 +24,85 @@ func init() { AUTOGEN: {Name: "create main=src/main.go zone name=hi help type=Zone,Hash,Lists,Data,Code list key", Help: "模块", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(AUTOGEN, mdb.CREATE, arg) }}, - web.DREAM: {Name: "dream name=hi repos", Help: "空间", Hand: func(m *ice.Message, arg ...string) { - m.Cmdy(web.DREAM, cli.START, arg) + COMPILE: {Name: "compile", Help: "编译", Hand: func(m *ice.Message, arg ...string) { + if msg := m.Cmd(COMPILE, ice.SRC_MAIN_GO, ice.BIN_ICE_BIN); !cli.IsSuccess(msg) { + _inner_make(m, msg) + } else { + m.Cmd(UPGRADE, cli.RESTART) + } }}, "script": {Name: "script file=hi/hi.js text=", Help: "脚本", Hand: func(m *ice.Message, arg ...string) { m.Option(mdb.TEXT, strings.TrimSpace(m.Option(mdb.TEXT))) m.Cmdy(TEMPLATE, nfs.DEFS) }}, + web.DREAM: {Name: "dream name=hi repos", Help: "空间", Hand: func(m *ice.Message, arg ...string) { + m.Cmdy(web.DREAM, cli.START, arg) + }}, + "website": {Name: "script file=hi.zml@key text@key", Help: "网页", Hand: func(m *ice.Message, arg ...string) { + m.Option(nfs.FILE, path.Join("website", m.Option(nfs.FILE))) + m.Option(mdb.TEXT, strings.TrimSpace(m.Option(mdb.TEXT))) + m.Cmdy(TEMPLATE, nfs.DEFS) + }}, + PUBLISH: {Name: "publish", Help: "发布", Hand: func(m *ice.Message, arg ...string) { + m.Cmdy(PUBLISH, ice.CONTEXTS) + }}, + + mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) { + if arg[0] == mdb.FOREACH && arg[1] == "" { + m.PushSearch(mdb.TYPE, "go", mdb.NAME, "src/main.go", mdb.TEXT, m.MergeCmd("")) + } + }}, + mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) { + switch m.Option(ctx.ACTION) { + case web.DREAM: + m.Cmdy(web.DREAM, mdb.INPUTS, arg) + case "script": + switch arg[0] { + case nfs.FILE: + file, ext := m.Option(nfs.FILE), kit.Ext(m.Option(nfs.FILE)) + for _, t := range []string{nfs.SH, nfs.SHY, nfs.PY, nfs.JS} { + m.Push(nfs.FILE, strings.ReplaceAll(file, ice.PT+ext, ice.PT+t)) + } + case mdb.TEXT: + m.Push(mdb.TEXT, `echo "hello world"`) + m.Push(mdb.TEXT, `chapter "hi"`) + m.Push(mdb.TEXT, `print "hello world"`) + m.Push(mdb.TEXT, `Volcanos("onimport", {help: "导入数据", list:[], _init: function(can, msg, cb, target) { + msg.Echo("hello world") + can.onappend.table(can, msg) + can.onappend.board(can, msg) +}})`) + } + case "website": + switch arg[0] { + case nfs.FILE: + m.Push(nfs.FILE, "hi.zml") + m.Push(nfs.FILE, "hi.iml") + case mdb.TEXT: + m.Push(mdb.TEXT, ` +hi + he + cli.runtime + cli.system + hi/hi.sh + hi/hi.go + hi/hi.js +`) + m.Push(mdb.TEXT, ` +left + username + 系统 + 命令 index cli.system + 共享 index cli.qrcode + 代码 + 趋势 index web.code.git.trend args icebergs action auto + 状态 index web.code.git.status args icebergs +main +`) + } + default: + } + }}, "complete": {Name: "complete", Help: "补全", Hand: func(m *ice.Message, arg ...string) { switch m.Option("key") { case "ice", "*ice": @@ -57,30 +129,7 @@ func init() { } } }}, - "website": {Name: "script file=hi.iml text=", Help: "网页", Hand: func(m *ice.Message, arg ...string) { - m.Option(nfs.FILE, path.Join("website", m.Option(nfs.FILE))) - 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) { - if arg[0] == mdb.FOREACH && arg[1] == "" { - m.PushSearch(mdb.TYPE, "go", mdb.NAME, "src/main.go", mdb.TEXT, m.MergeCmd("")) - } - }}, - mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) { - switch m.Option(ctx.ACTION) { - case web.DREAM: - m.Cmdy(web.DREAM, mdb.INPUTS, arg) - } - }}, - COMPILE: {Name: "compile", Help: "编译", Hand: func(m *ice.Message, arg ...string) { - if msg := m.Cmd(COMPILE, ice.SRC_MAIN_GO, ice.BIN_ICE_BIN); !cli.IsSuccess(msg) { - _inner_make(m, msg) - } else { - m.Cmd(UPGRADE, cli.RESTART) - } - }}, "unpack": {Name: "unpack", Help: "导出文件", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(BINPACK, mdb.EXPORT) }}, diff --git a/core/team/todo.go b/core/team/todo.go index b68bcd43..f406c6ca 100644 --- a/core/team/todo.go +++ b/core/team/todo.go @@ -10,7 +10,7 @@ const TODO = "todo" func init() { Index.Merge(&ice.Context{Commands: map[string]*ice.Command{ - TODO: {Name: "todo hash auto create", Help: "待办", Action: ice.MergeAction(map[string]*ice.Action{ + TODO: {Name: "todo hash auto create export import", Help: "待办", Action: ice.MergeAction(map[string]*ice.Action{ mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(mdb.INPUTS, m.PrefixKey(), "", mdb.HASH, arg) m.Cmdy(TASK, mdb.INPUTS, arg) @@ -23,6 +23,7 @@ func init() { }, mdb.HashAction(mdb.FIELD, "time,hash,zone,name,text")), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Display("/plugin/table.js", "style", "card") mdb.HashSelect(m, arg...).PushAction(cli.START, mdb.REMOVE) + m.PushPodCmd(cmd, arg...) }}, }}) } diff --git a/init.go b/init.go index 436eaa55..c8f4b021 100644 --- a/init.go +++ b/init.go @@ -74,7 +74,6 @@ var Index = &Context{Name: "ice", Help: "冰山模块", Configs: map[string]*Con EXIT: {Name: "exit", Help: "结束", Hand: func(m *Message, c *Context, cmd string, arg ...string) { m.root.Option(EXIT, kit.Select("0", arg, 0)) defer c.Close(m.root.Spawn(), arg...) - defer m.Sleep("1s") m.Cmd("source", ETC_EXIT_SHY) m.root.Cmd(CTX_EXIT) @@ -138,7 +137,7 @@ func Run(arg ...string) string { } Pulse.Cmd(INIT) - defer Pulse.Cmd(EXIT) + // defer Pulse.Cmd(EXIT) if Pulse.Cmdy(arg); strings.TrimSpace(Pulse.Result()) == "" { Pulse.Table() } diff --git a/misc/git/status.go b/misc/git/status.go index 555b3fa1..c4632d9a 100644 --- a/misc/git/status.go +++ b/misc/git/status.go @@ -316,7 +316,7 @@ func init() { m.Option(cli.CMD_DIR, _repos_path(arg[0])) m.Echo(m.Cmdx(cli.SYSTEM, GIT, DIFF)) - m.Action(COMMIT, BRANCH, TAGS) + m.Action(COMMIT, TAGS, BRANCH) files, adds, dels := _status_stat(m, 0, 0, 0) m.Status("files", files, "adds", adds, "dels", dels) diff --git a/render.go b/render.go index db787c6d..db332f8d 100644 --- a/render.go +++ b/render.go @@ -194,7 +194,7 @@ func (m *Message) PushPodCmd(cmd string, arg ...string) { }) } - m.Cmd(SPACE).Table(func(index int, value map[string]string, head []string) { + m.Cmd(SPACE, OptionFields("type,name")).Table(func(index int, value map[string]string, head []string) { switch value[TYPE] { case "server", "worker": if value[NAME] == Info.HostName {