From 12758d813d6e2c9a152b7d8ac6660d654551e5a4 Mon Sep 17 00:00:00 2001 From: shylinux Date: Thu, 16 Mar 2023 23:05:30 +0800 Subject: [PATCH] opt code --- base/ctx/command.go | 12 ------ base/ctx/config.go | 19 ++------- base/mdb/mdb.go | 1 + base/mdb/zone.go | 3 +- base/nfs/dir.go | 12 ++++++ base/nfs/save.go | 1 + base/web/render.go | 21 +++++----- base/web/serve.go | 9 +++- core/chat/footer.go | 15 +++++++ core/code/autogen.go | 45 ++++++++------------ core/code/bench.go | 9 ++-- core/code/binpack.go | 24 ++++++----- core/code/case.go | 97 +++++++------------------------------------- core/code/inner.go | 22 ---------- core/code/repos.go | 3 ++ core/code/xterm.go | 1 + core/wiki/word.go | 11 ----- info.go | 2 + logs.go | 29 +++++++++++++ 19 files changed, 137 insertions(+), 199 deletions(-) diff --git a/base/ctx/command.go b/base/ctx/command.go index ba4cbd75..b1bc5990 100644 --- a/base/ctx/command.go +++ b/base/ctx/command.go @@ -106,19 +106,7 @@ 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 Run(m *ice.Message, arg ...string) { - if len(arg) > 3 && arg[1] == ACTION && arg[2] == CONFIG { - for _, check := range runChecker { - if check(m, arg[0], arg[3], arg...) { - return - } - } - } if !PodCmd(m, arg) && aaa.Right(m, arg) { m.Cmdy(arg) } diff --git a/base/ctx/config.go b/base/ctx/config.go index b890c08a..e4e9986f 100644 --- a/base/ctx/config.go +++ b/base/ctx/config.go @@ -96,7 +96,7 @@ const CONFIG = "config" func init() { Index.MergeCommands(ice.Commands{ - CONFIG: {Name: "config key auto", Help: "配置", Actions: ice.Actions{ + CONFIG: {Name: "config key auto remove", 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:]...) }}, mdb.LIST: {Hand: func(m *ice.Message, arg ...string) { @@ -107,7 +107,8 @@ func init() { m.Confv(arg[0], arg[1], list) }}, mdb.REMOVE: {Name: "remove key sub", Hand: func(m *ice.Message, arg ...string) { - m.Conf(m.Option("key"), m.Option("sub"), "") + m.Cmd(mdb.EXPORT, m.Option(mdb.KEY), m.Option(mdb.SUB), mdb.HASH, path.Join(ice.VAR_TRASH, kit.Keys(m.Option(mdb.KEY), m.Option(mdb.SUB)))) + nfs.Trash(m, path.Join(ice.VAR_DATA, m.Option(mdb.KEY))) m.Go(func() { m.Cmd(ice.EXIT, 1) }) }}, }, Hand: func(m *ice.Message, arg ...string) { @@ -116,23 +117,11 @@ func init() { } else { _config_make(m, arg[0], arg[1:]...) DisplayStoryJSON(m) + m.Action(mdb.REMOVE) } }}, }) } -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 diff --git a/base/mdb/mdb.go b/base/mdb/mdb.go index 07320c50..7ae4bad1 100644 --- a/base/mdb/mdb.go +++ b/base/mdb/mdb.go @@ -144,6 +144,7 @@ const ( JSON = "json" CSV = "csv" + SUB = "sub" ) const MDB = "mdb" diff --git a/base/mdb/zone.go b/base/mdb/zone.go index 61252f44..6eec8578 100644 --- a/base/mdb/zone.go +++ b/base/mdb/zone.go @@ -197,7 +197,8 @@ func ZoneSelect(m *ice.Message, arg ...string) *ice.Message { if m.Cmdy(SELECT, m.PrefixKey(), "", ZONE, arg, logs.FileLineMeta(-1)); len(arg) == 0 { m.PushAction(m.Config(ACTION), REMOVE).StatusTimeCount().Sort(ZoneShort(m)) } else if len(arg) == 1 { - m.StatusTimeCountTotal(_mdb_getmeta(m, "", kit.Keys(HASH, HashSelectField(m, arg[0], HASH)), COUNT)) + // m.StatusTimeCountTotal(_mdb_getmeta(m, m.PrefixKey(), kit.Keys(HASH, HashSelectField(m, arg[0], HASH)), COUNT)) + m.StatusTimeCount() } return m } diff --git a/base/nfs/dir.go b/base/nfs/dir.go index 4c7613a7..749e0501 100644 --- a/base/nfs/dir.go +++ b/base/nfs/dir.go @@ -214,6 +214,18 @@ func init() { }) } +func Relative(m *ice.Message, p string) string { + var bind = []string{ + "usr/icebergs/core/chat/", "usr/volcanos/panel/", + "usr/icebergs/core/", "usr/volcanos/plugin/local/", + } + for i := 0; i < len(bind); i += 2 { + if strings.HasPrefix(p, bind[i]) { + return strings.Replace(p, bind[i], bind[i+1], 1) + } + } + return p +} func SplitPath(m *ice.Message, p string) []string { if ls := kit.Split(p, ice.PS); len(ls) == 1 { return []string{PWD, ls[0]} diff --git a/base/nfs/save.go b/base/nfs/save.go index d2cb44db..36e820b4 100644 --- a/base/nfs/save.go +++ b/base/nfs/save.go @@ -90,6 +90,7 @@ const LINK = "link" func init() { Index.MergeCommands(ice.Commands{ DEFS: {Name: "defs file text run", Help: "默认", Hand: func(m *ice.Message, arg ...string) { + OptionFiles(m, DiskFile) _defs_file(m, arg[0], arg[1:]...) }}, SAVE: {Name: "save file text run", Help: "保存", Hand: func(m *ice.Message, arg ...string) { diff --git a/base/web/render.go b/base/web/render.go index 618ab4cb..3aeaeb77 100644 --- a/base/web/render.go +++ b/base/web/render.go @@ -85,19 +85,11 @@ func Render(m *ice.Message, cmd string, args ...ice.Any) bool { m.W.Write([]byte(arg[0])) default: - for _, k := range kit.Simple(m.Optionv("option"), m.Optionv("_option")) { - if m.Option(k) == "" { - m.Set(k) - } - } - for _, k := range []string{"sessid", "cmds", "fields", "_option", "_handle", "_output"} { - m.Set(k) - } if cmd != "" && cmd != ice.RENDER_RAW { m.Echo(kit.Format(cmd, args...)) } RenderType(m.W, nfs.JSON, "") - fmt.Fprint(m.W, m.FormatMeta()) + m.DumpMeta(m.W) } return true } @@ -159,10 +151,19 @@ func CookieName(url string) string { } func RenderIndex(m *ice.Message, repos string, file ...string) *ice.Message { + if m.IsCliUA() { + return m.RenderDownload(path.Join(ice.USR_INTSHELL, kit.Select(ice.INDEX_SH, path.Join(file...)))) + } + return m.RenderDownload(path.Join(ice.USR_VOLCANOS, kit.Select("page/"+ice.INDEX_HTML, path.Join(file...)))) + if repos == "" { repos = kit.Select(ice.VOLCANOS, ice.INTSHELL, m.IsCliUA()) } - return m.RenderDownload(path.Join(m.Conf(SERVE, kit.Keym(repos, nfs.PATH)), kit.Select(m.Conf(SERVE, kit.Keym(repos, INDEX)), path.Join(file...)))) + p := func() string { + defer mdb.RLock(m, "web.serve")() + return path.Join(m.Conf(SERVE, kit.Keym(repos, nfs.PATH)), kit.Select(m.Conf(SERVE, kit.Keym(repos, INDEX)), path.Join(file...))) + } + return m.RenderDownload(p()) } func RenderMain(m *ice.Message, pod, index string, arg ...ice.Any) *ice.Message { if script := m.Cmdx(Space(m, pod), nfs.CAT, kit.Select(ice.SRC_MAIN_JS, index)); script != "" { diff --git a/base/web/serve.go b/base/web/serve.go index dc7bc80f..4d8e513a 100644 --- a/base/web/serve.go +++ b/base/web/serve.go @@ -65,10 +65,11 @@ func _serve_main(m *ice.Message, w http.ResponseWriter, r *http.Request) bool { } if r.Method == http.MethodGet && r.URL.Path != PP(SPACE) && !strings.HasPrefix(r.URL.Path, "/code/bash") { repos := kit.Select(ice.INTSHELL, ice.VOLCANOS, strings.Contains(r.Header.Get(UserAgent), MOZILLA)) + dir := kit.Select(ice.USR_INTSHELL, ice.USR_VOLCANOS, strings.Contains(r.Header.Get(UserAgent), MOZILLA)) if p := path.Join(ice.USR, repos, r.URL.Path); r.URL.Path != ice.PS && nfs.ExistsFile(m, p) { Render(m.Spawn(w, r), ice.RENDER_DOWNLOAD, p) return false - } else if msg := gdb.Event(m.Spawn(w, r), SERVE_REWRITE, r.Method, r.URL.Path, path.Join(m.Conf(SERVE, kit.Keym(repos, nfs.PATH)), r.URL.Path), repos); msg.Option(ice.MSG_OUTPUT) != "" { + } else if msg := gdb.Event(m.Spawn(w, r), SERVE_REWRITE, r.Method, r.URL.Path, path.Join(dir, r.URL.Path), repos); msg.Option(ice.MSG_OUTPUT) != "" { Render(msg, msg.Option(ice.MSG_OUTPUT), kit.List(msg.Optionv(ice.MSG_ARGS))...) return false } @@ -194,7 +195,11 @@ func init() { Index.MergeCommands(ice.Commands{ "/exit": {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(ice.EXIT) }}, SERVE: {Name: "serve name auto start", Help: "服务器", Actions: ice.MergeActions(ice.Actions{ - ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { cli.NodeInfo(m, ice.Info.Pathname, WORKER) }}, + ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { + cli.NodeInfo(m, ice.Info.Pathname, WORKER) + ice.Info.Intshell = path.Join(m.Conf(SERVE, kit.Keym(ice.INTSHELL, nfs.PATH)), kit.Select(m.Conf(SERVE, kit.Keym(ice.INTSHELL, INDEX)))) + ice.Info.Volcanos = path.Join(m.Conf(SERVE, kit.Keym(ice.VOLCANOS, nfs.PATH)), kit.Select(m.Conf(SERVE, kit.Keym(ice.VOLCANOS, INDEX)))) + }}, cli.START: {Name: "start dev proto host port=9020 nodename username usernick", Hand: func(m *ice.Message, arg ...string) { _serve_start(m) }}, diff --git a/core/chat/footer.go b/core/chat/footer.go index a073351b..15f2a28f 100644 --- a/core/chat/footer.go +++ b/core/chat/footer.go @@ -5,6 +5,7 @@ import ( "shylinux.com/x/icebergs/base/aaa" "shylinux.com/x/icebergs/base/cli" "shylinux.com/x/icebergs/base/ctx" + "shylinux.com/x/icebergs/base/nfs" "shylinux.com/x/icebergs/base/web" kit "shylinux.com/x/toolkits" ) @@ -21,6 +22,20 @@ func init() { } } }}, + ice.HELP: {Hand: func(m *ice.Message, arg ...string) { + ctx.ProcessField(m, web.WIKI_WORD, func() string { return kit.ExtChange(ctx.GetCmdFile(m, arg[0]), nfs.SHY) }, arg...) + }}, + nfs.SCRIPT: {Hand: func(m *ice.Message, arg ...string) { + ctx.ProcessField(m, web.CODE_VIMER, func() []string { + return nfs.SplitPath(m, kit.ExtChange(nfs.Relative(m, ctx.GetCmdFile(m, arg[0])), nfs.JS)) + }, arg...) + }}, + nfs.SOURCE: {Hand: func(m *ice.Message, arg ...string) { + ctx.ProcessField(m, web.CODE_VIMER, func() []string { return nfs.SplitPath(m, ctx.GetCmdFile(m, arg[0])) }, arg...) + }}, + ctx.CONFIG: {Hand: func(m *ice.Message, arg ...string) { + ctx.ProcessField(m, ctx.CONFIG, arg, arg...) + }}, }, ctx.CmdAction(), aaa.WhiteAction(ctx.COMMAND, ice.RUN)), Hand: func(m *ice.Message, arg ...string) { m.Result(kit.Select(m.Config(TITLE), ice.Info.Make.Email)) }}, diff --git a/core/code/autogen.go b/core/code/autogen.go index 10fbce98..3557ea9f 100644 --- a/core/code/autogen.go +++ b/core/code/autogen.go @@ -16,7 +16,7 @@ import ( kit "shylinux.com/x/toolkits" ) -func _defs_list(m *ice.Message) string { +func _autogen_list(m *ice.Message) string { return m.OptionDefault(mdb.LIST, ice.Maps{ "Zone": "zone id auto insert", "Hash": "hash auto create", @@ -26,7 +26,6 @@ func _defs_list(m *ice.Message) string { }[m.Option(mdb.TYPE)]) } func _autogen_source(m *ice.Message, main, file string) { - main = kit.ExtChange(main, SHY) m.Cmd(nfs.DEFS, main, nfs.Template(m, ice.SRC_MAIN_SHY)) m.Cmd(nfs.PUSH, main, ssh.SOURCE+ice.SP+strings.TrimPrefix(file, ice.SRC+ice.PS)+ice.NL) } @@ -53,9 +52,6 @@ func _autogen_import(m *ice.Message, main string, ctx string, mod string) { } func _autogen_version(m *ice.Message) string { if mod := _autogen_mod(m, ice.GO_MOD); !nfs.ExistsFile(m, ".git") { - m.Cmdy(cli.SYSTEM, GIT, ice.INIT) - m.Cmd(cli.SYSTEM, GIT, nfs.REMOTE, "add", nfs.ORIGIN, "https://"+mod) - m.Cmd(cli.SYSTEM, GIT, "add", ice.GO_MOD, ice.SRC, ice.ETC_MISS_SH) m.Cmd(REPOS, mdb.CREATE, nfs.ORIGIN, "https://"+mod, mdb.NAME, path.Base(mod), nfs.PATH, nfs.PWD) } m.Cmd(nfs.DEFS, ".gitignore", nfs.Template(m, "gitignore")) @@ -69,13 +65,14 @@ func _autogen_version(m *ice.Message) string { } func _autogen_gits(m *ice.Message, arg ...string) string { res := []string{} - kit.Fetch(_autogen_git(m, arg...), func(k string, v string) { + kit.For(_autogen_git(m, arg...), func(k, v string) { res = append(res, kit.Format(` %s: "%s",`, kit.Capital(k), strings.TrimSpace(v))) }) return kit.Join(res, ice.NL) } func _autogen_git(m *ice.Message, arg ...string) ice.Map { - return kit.Dict(nfs.PATH, kit.Path(""), mdb.TIME, m.Time(), arg, + return kit.Dict( + mdb.TIME, m.Time(), nfs.PATH, kit.Path(""), arg, mdb.HASH, m.Cmdx(cli.SYSTEM, GIT, "log", "-n1", `--pretty=%H`), nfs.REMOTE, m.Cmdx(cli.SYSTEM, GIT, "config", "remote.origin.url"), nfs.BRANCH, m.Cmdx(cli.SYSTEM, GIT, "rev-parse", "--abbrev-ref", "HEAD"), @@ -92,24 +89,22 @@ func _autogen_mod(m *ice.Message, file string) (mod string) { } else { host = path.Join(host, "x", path.Base(kit.Path(""))) } - m.Cmd(nfs.DEFS, file, kit.Format(nfs.Template(m, ice.GO_MOD), host)) + m.Cmd(nfs.DEFS, file, nfs.Template(m, ice.GO_MOD, host)) m.Cmd(nfs.CAT, file, func(line string) { kit.If(strings.HasPrefix(line, nfs.MODULE), func() { mod = kit.Split(line, ice.SP)[1] }) }) return } -const ( - GIT = "git" - - USR_RELEASE_CONF_GO = "usr/release/conf.go" - USR_RELEASE_BINPACK_GO = "usr/release/binpack.go" -) const AUTOGEN = "autogen" func init() { + const ( + USR_RELEASE_CONF_GO = "usr/release/conf.go" + USR_RELEASE_BINPACK_GO = "usr/release/binpack.go" + ) Index.MergeCommands(ice.Commands{ - AUTOGEN: {Name: "autogen path auto version module script", Help: "生成", Actions: ice.Actions{ + AUTOGEN: {Name: "autogen path auto script module version", Help: "生成", Actions: ice.Actions{ mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) { switch arg[0] { case cli.MAIN: @@ -120,28 +115,24 @@ func init() { m.Push(arg[0], Prefix(m.Option(mdb.ZONE), m.Option(mdb.NAME))) } }}, + nfs.SCRIPT: {Help: "脚本", Hand: func(m *ice.Message, arg ...string) { + m.Cmd(nfs.DEFS, ice.ETC_MISS_SH, nfs.Template(m, ice.ETC_MISS_SH)) + m.Cmdy(nfs.DIR, ice.ETC_MISS_SH).Cmdy(nfs.CAT, ice.ETC_MISS_SH) + }}, nfs.MODULE: {Name: "module name*=hi help type*=Zone,Hash,Data,Code,Lang main*=main.go@key zone key", Help: "模块", Hand: func(m *ice.Message, arg ...string) { m.OptionDefault(mdb.ZONE, m.Option(mdb.NAME), mdb.HELP, m.Option(mdb.NAME)) m.OptionDefault(mdb.KEY, Prefix(m.Option(mdb.ZONE), m.Option(mdb.NAME))) m.Option(nfs.FILE, path.Join(m.Option(mdb.ZONE), kit.Keys(m.Option(mdb.NAME), GO))) - m.Option(mdb.TEXT, kit.Format("`name:\"list %s\" help:\"%s\"`", _defs_list(m), m.Option(mdb.HELP))) - nfs.OptionFiles(m, nfs.DiskFile) + m.Option(mdb.TEXT, kit.Format("`name:\"list %s\" help:\"%s\"`", _autogen_list(m), m.Option(mdb.HELP))) + defer _autogen_version(m.Spawn()) if p := path.Join(ice.SRC, kit.ExtChange(m.Option(nfs.FILE), SHY)); !nfs.ExistsFile(m, p) { - _autogen_source(m, path.Join(ice.SRC, m.Option(cli.MAIN)), p) + _autogen_source(m, kit.ExtChange(path.Join(ice.SRC, m.Option(cli.MAIN)), SHY), p) _autogen_script(m, p) } if p := path.Join(ice.SRC, m.Option(nfs.FILE)); !nfs.ExistsFile(m, p) { _autogen_import(m, path.Join(ice.SRC, m.Option(cli.MAIN)), m.Option(mdb.ZONE), _autogen_mod(m, ice.GO_MOD)) _autogen_module(m, p) } - _autogen_version(m.Spawn()) - }}, - nfs.SCRIPT: {Help: "脚本", Hand: func(m *ice.Message, arg ...string) { - m.Cmd(nfs.DEFS, ice.ETC_MISS_SH, nfs.Template(m, ice.ETC_MISS_SH)) - defer m.Cmdy(nfs.CAT, ice.ETC_MISS_SH) - m.Cmdy(nfs.DIR, ice.ETC_MISS_SH) - m.Cmdy(nfs.DIR, ice.GO_MOD) - m.Cmdy(nfs.DIR, ice.GO_SUM) }}, DEVPACK: {Help: "开发", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(WEBPACK, mdb.REMOVE) }}, WEBPACK: {Help: "打包", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(WEBPACK, mdb.CREATE) }}, @@ -158,8 +149,6 @@ func init() { m.Cmdy(nfs.CAT, _autogen_version(m)) }}, VERSION: {Help: "版本", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(nfs.CAT, _autogen_version(m)) }}, - }, Hand: func(m *ice.Message, arg ...string) { - m.Cmdy(nfs.CAT, kit.Select(path.Base(ice.SRC_VERSION_GO), arg, 0), kit.Dict(nfs.DIR_ROOT, ice.SRC)) }}, }) } diff --git a/core/code/bench.go b/core/code/bench.go index 03102d75..f33cb6a8 100644 --- a/core/code/bench.go +++ b/core/code/bench.go @@ -38,8 +38,7 @@ func _bench_http(m *ice.Message, target string, arg ...string) { n, _ := io.Copy(ioutil.Discard, res.Body) atomic.AddInt64(&ndata, n) }); m.Assert(e) { - m.Echo("nconn: %d total: %d ndata: %s\n", nconn, nreqs*nconn, kit.FmtSize(ndata)).Echo(s.Show()) - m.ProcessInner() + m.Echo("nconn: %d total: %d ndata: %s\n", nconn, nreqs*nconn, kit.FmtSize(ndata)).Echo(s.Show()).ProcessInner() } } func _bench_redis(m *ice.Message, target string, arg ...string) { @@ -58,8 +57,8 @@ const BENCH = "bench" func init() { Index.MergeCommands(ice.Commands{ BENCH: {Name: "bench zone id auto insert", Help: "性能压测", Actions: ice.MergeActions(ice.Actions{ - mdb.INSERT: {Name: "insert zone*=some type*=http,redis name=demo text*='http://localhost:9020' nconn=3 nreqs=10"}, - ice.RUN: {Name: "run", Help: "执行", Hand: func(m *ice.Message, arg ...string) { + mdb.INSERT: {Name: "insert zone*=demo type*=http,redis name=demo text*='http://localhost:9020/chat/cmd/run/web.chat.favor' nconn=10 nreqs=100"}, + ice.RUN: {Hand: func(m *ice.Message, arg ...string) { switch m.Option(mdb.TYPE) { case HTTP: _bench_http(m, m.Option(mdb.TEXT)) @@ -68,7 +67,7 @@ func init() { } }}, }, mdb.ZoneAction(mdb.FIELD, "time,id,type,name,text,nconn,nreqs")), Hand: func(m *ice.Message, arg ...string) { - mdb.ZoneSelect(m, arg...).PushAction(kit.Select(mdb.REMOVE, ice.RUN, len(arg) > 0)) + mdb.ZoneSelect(m, arg...).PushAction(kit.Select(ice.RUN, mdb.REMOVE, len(arg) == 0)) }}, }) } diff --git a/core/code/binpack.go b/core/code/binpack.go index be98a8c1..6778d10e 100644 --- a/core/code/binpack.go +++ b/core/code/binpack.go @@ -25,7 +25,9 @@ func _binpack_file(m *ice.Message, w io.Writer, arg ...string) { } switch path.Base(arg[0]) { case ice.GO_MOD, ice.GO_SUM: - return + if !strings.HasPrefix(arg[0], ice.SRC_TEMPLATE) { + return + } } switch arg[0] { case ice.SRC_VERSION_GO, ice.SRC_BINPACK_GO, ice.ETC_LOCAL_SHY: @@ -54,23 +56,23 @@ func _binpack_all(m *ice.Message) { for _, p := range []string{ice.ETC_MISS_SH, ice.ETC_INIT_SHY, ice.ETC_EXIT_SHY, ice.README_MD, ice.MAKEFILE, ice.LICENSE} { _binpack_file(m, w, p) } - list, cache := map[string]bool{}, kit.Select(ice.USR_REQUIRE, m.Cmdx(cli.SYSTEM, GO, "env", "GOMODCACHE")) + list, cache := map[string]string{}, kit.Select(ice.USR_REQUIRE, m.Cmdx(cli.SYSTEM, GO, "env", "GOMODCACHE")) + const _mod_ = "/pkg/mod/" for k := range ice.Info.File { switch ls := strings.Split(k, ice.PS); ls[2] { case ice.SRC: case ice.USR: - list[path.Join(kit.Slice(ls, 2, -1)...)] = true + list[path.Join(kit.Slice(ls, 2, -1)...)] = "" default: - list[path.Join(cache, path.Join(kit.Slice(ls, 2, -1)...))] = true + p := path.Join(cache, path.Join(kit.Slice(ls, 2, -1)...)) + _ls := strings.Split(strings.Split(p, _mod_)[1], ice.PS) + list[path.Join(nfs.USR, strings.Split(_ls[2], ice.AT)[0], path.Join(kit.Slice(_ls, 3)...))] = p } } - for _, p := range kit.SortedKey(list) { - m.Cmd(nfs.DIR, p, nfs.PATH, kit.Dict(nfs.DIR_ROOT, nfs.PWD, nfs.DIR_REG, kit.ExtReg(SH, SHY, PY, JS, CSS, HTML))).Tables(func(value ice.Maps) { - if strings.Contains(value[nfs.PATH], "/go/pkg/mod/") { - _binpack_file(m, w, value[nfs.PATH], ice.USR_REQUIRE+strings.Split(value[nfs.PATH], "/go/pkg/mod/")[1]) - } else { - _binpack_file(m, w, value[nfs.PATH]) - } + for _, k := range kit.SortedKey(list) { + v := kit.Select(k, list[k]) + m.Cmd(nfs.DIR, nfs.PWD, nfs.PATH, kit.Dict(nfs.DIR_ROOT, v, nfs.DIR_REG, kit.ExtReg(SH, SHY, PY, JS, CSS, HTML))).Tables(func(value ice.Maps) { + _binpack_file(m, w, kit.Path(v, value[nfs.PATH]), path.Join(k, value[nfs.PATH])) }) } mdb.HashSelects(m).Sort(nfs.PATH).Tables(func(value ice.Maps) { diff --git a/core/code/case.go b/core/code/case.go index 30de9502..85ef529a 100644 --- a/core/code/case.go +++ b/core/code/case.go @@ -1,9 +1,6 @@ package code import ( - "path" - "strings" - ice "shylinux.com/x/icebergs" "shylinux.com/x/icebergs/base/cli" "shylinux.com/x/icebergs/base/mdb" @@ -16,19 +13,14 @@ const CASE = "case" func init() { Index.MergeCommands(ice.Commands{ - CASE: {Name: "case dev zone id auto", Help: "用例", Actions: ice.MergeActions(ice.Actions{ - mdb.CREATE: {Name: "create name address", Help: "创建", Hand: func(m *ice.Message, arg ...string) { - m.Cmdy(web.SPIDE, mdb.CREATE, arg) - }}, - mdb.INSERT: {Name: "insert zone name=hi cmd=POST,GET api arg:textarea res:textarea", Help: "添加"}, - + CASE: {Name: "case dev zone id auto insert", Help: "用例", Actions: ice.MergeActions(ice.Actions{ + mdb.INSERT: {Name: "insert zone*=demo name=hi cmd=GET,POST api*=/chat/cmd/web.chat.favor arg:textarea res:textarea"}, cli.CHECK: {Name: "check", Help: "检查", Hand: func(m *ice.Message, arg ...string) { - if m.ProcessInner(); len(arg) > 0 { + if m.ProcessInner(); len(arg) > 1 { success := 0 - m.Cmd(m.PrefixKey(), arg[0], func(value ice.Maps) { - m.Push(mdb.TIME, m.Time()) - m.Push(mdb.ID, value[mdb.ID]) - if err := m.Cmdx(m.PrefixKey(), cli.CHECK, value); err == ice.OK { + m.Cmd("", arg[0], arg[1], func(value ice.Maps) { + m.Push(mdb.TIME, m.Time()).Push(mdb.ID, value[mdb.ID]) + if err := m.Cmdx("", cli.CHECK, value); err == ice.OK { m.Push(ice.ERR, cli.Color(m, cli.GREEN, err)) success++ } else { @@ -41,9 +33,7 @@ func init() { m.StatusTimeCount(ice.SUCCESS, success) return } - - res := kit.UnMarshal(m.Cmdx(m.PrefixKey(), ice.RUN)) - if m.Option(ice.RES) != "" { + if res := kit.UnMarshal(m.Cmdx("", ice.RUN)); m.Option(ice.RES) != "" { for k, v := range kit.KeyValue(nil, "", kit.UnMarshal(m.Option(ice.RES))) { if v != kit.Value(res, k) { m.Echo(kit.Formats(res)) @@ -53,74 +43,17 @@ func init() { } m.Echo(ice.OK) }}, - ice.RUN: {Name: "run", Help: "运行", Hand: func(m *ice.Message, arg ...string) { - m.Option(web.SPIDE_HEADER, web.ContentType, web.ContentJSON) - m.Echo(kit.Formats(kit.UnMarshal(m.Cmdx(web.SPIDE, m.Option(ice.DEV), web.SPIDE_RAW, - m.Option(ice.CMD), m.Option(cli.API), web.SPIDE_DATA, m.Option(ice.ARG))))) - m.Info(`curl "` + m.Option(cli.API) + `" -H "Content-Type: application/json"` + ` -d '` + m.Option(ice.ARG) + `'`) - m.ProcessDisplay("/plugin/story/json.js") + ice.RUN: {Hand: func(m *ice.Message, arg ...string) { + m.Option(web.SPIDE_HEADER, web.ContentType, web.ContentJSON, web.UserAgent, "Mozilla/5.0") + m.Cmdy(web.SPIDE, m.Option(ice.DEV), web.SPIDE_RAW, m.Option(ice.CMD), m.Option(cli.API), web.SPIDE_DATA, m.Option(ice.ARG)).ProcessInner() + m.StatusTime(nfs.SCRIPT, `curl "`+kit.MergeURL2(m.Cmd(web.SPIDE, m.Option(ice.DEV)).Append(web.CLIENT_ORIGIN), m.Option(cli.API))+`" -H "Content-Type: application/json"`+` -d '`+m.Option(ice.ARG)+`'`) }}, - }, mdb.ZoneAction(mdb.SHORT, mdb.ZONE, mdb.FIELD, "time,id,name,cmd,api,arg,res")), Hand: func(m *ice.Message, arg ...string) { + }, mdb.ZoneAction(mdb.FIELD, "time,id,name,cmd,api,arg,res")), Hand: func(m *ice.Message, arg ...string) { if len(arg) == 0 { - m.Cmdy(web.SPIDE).RenameAppend("client.name", "dev", "client.url", "address").Action(mdb.CREATE) - return + m.Cmdy(web.SPIDE).RenameAppend(web.CLIENT_NAME, ice.DEV, web.CLIENT_URL, "address") + } else if mdb.ZoneSelect(m, arg[1:]...); len(arg) > 1 { + m.PushAction(ice.RUN, cli.CHECK).Action(cli.CHECK) } - - defer m.StatusTimeCount() - if mdb.ZoneSelect(m, arg[1:]...); len(arg) == 1 { - m.Action(mdb.INSERT, mdb.EXPORT, mdb.IMPORT) - m.PushAction(mdb.INSERT, cli.CHECK, mdb.REMOVE) - } else { - m.Action(mdb.INSERT, cli.CHECK) - m.PushAction(ice.RUN, cli.CHECK) - } - }}, - "test": {Name: "test path func auto run case", Help: "测试用例", Actions: ice.Actions{ - "run": {Name: "run", Help: "运行", Hand: func(m *ice.Message, arg ...string) { - // cli.Follow(m, "run", func() { - m.Option(cli.CMD_DIR, kit.Select(path.Dir(arg[0]), arg[0], strings.HasSuffix(arg[0], "/"))) - m.Cmdy(cli.SYSTEM, "go", "test", nfs.PWD, "-v", "-run="+arg[1]) - // }) - }}, - "case": {Name: "case", Help: "用例", Hand: func(m *ice.Message, arg ...string) { - msg := m.Spawn() - if strings.HasSuffix(arg[0], "/") { - msg.Option(cli.CMD_DIR, arg[0]) - msg.Split(msg.Cmdx(cli.SYSTEM, "grep", "-r", "func Test.*(", nfs.PWD), "file:line", ":", "\n") - msg.Tables(func(value ice.Maps) { - if strings.HasPrefix(strings.TrimSpace(value["line"]), "//") { - return - } - ls := kit.Split(value["line"], " (", " (", " (") - m.Push("file", value["file"]) - m.Push("func", strings.TrimPrefix(ls[1], "Test")) - }) - } else { - for _, line := range kit.Split(m.Cmdx(cli.SYSTEM, "grep", "^func Test.*(", arg[0]), "\n", "\n", "\n") { - ls := kit.Split(line, " (", " (", " (") - m.Push("func", strings.TrimPrefix(ls[1], "Test")) - } - } - }}, - }, Hand: func(m *ice.Message, arg ...string) { - if len(arg) == 0 || arg[0] == "" { - m.Cmdy(nfs.DIR, nfs.PWD) - return - } - if len(arg) == 1 { - if strings.HasSuffix(arg[0], "/") { - m.Cmdy(nfs.DIR, arg[0]) - } else { - for _, line := range kit.Split(m.Cmdx(cli.SYSTEM, "grep", "^func Test.*(", arg[0]), "\n", "\n", "\n") { - ls := kit.Split(line, " (", " (", " (") - m.Push("func", strings.TrimPrefix(ls[1], "Test")) - } - } - return - } - - m.Option(cli.CMD_DIR, kit.Select(path.Dir(arg[0]), arg[0], strings.HasSuffix(arg[0], "/"))) - m.Cmdy(cli.SYSTEM, "go", "test", nfs.PWD, "-v", "-run="+arg[1]) }}, }) } diff --git a/core/code/inner.go b/core/code/inner.go index 9f7b9a87..127d3c6f 100644 --- a/core/code/inner.go +++ b/core/code/inner.go @@ -12,7 +12,6 @@ import ( "shylinux.com/x/icebergs/base/lex" "shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/nfs" - "shylinux.com/x/icebergs/base/web" kit "shylinux.com/x/toolkits" ) @@ -132,27 +131,6 @@ func init() { } }}, }) - ctx.AddRunChecker(func(m *ice.Message, cmd, check string, arg ...string) bool { - process := func(m *ice.Message, file string) bool { - ctx.ProcessFloat(m, kit.Simple(web.CODE_INNER, nfs.SplitPath(m, file))...) - return true - } - switch check { - case nfs.SCRIPT: - if file := kit.ExtChange(ctx.GetCmdFile(m, cmd), nfs.JS); nfs.ExistsFile(m, file) { - return process(m, file) - } else if strings.HasPrefix(file, bind[0]) { - if file := strings.Replace(file, bind[0], bind[1], 1); nfs.ExistsFile(m, file) { - return process(m, file) - } - } - case nfs.SOURCE: - if file := ctx.GetCmdFile(m, cmd); nfs.ExistsFile(m, file) { - return process(m, file) - } - } - return false - }) } func InnerPath(arg ...string) (dir, file string) { p := strings.TrimPrefix(path.Join(arg...), kit.Path("")+ice.PS) diff --git a/core/code/repos.go b/core/code/repos.go index a22d94aa..cf5f9e63 100644 --- a/core/code/repos.go +++ b/core/code/repos.go @@ -5,6 +5,9 @@ import ( "shylinux.com/x/icebergs/base/nfs" ) +const ( + GIT = "git" +) const REPOS = nfs.REPOS func init() { diff --git a/core/code/xterm.go b/core/code/xterm.go index 7aec81f5..c29468df 100644 --- a/core/code/xterm.go +++ b/core/code/xterm.go @@ -153,5 +153,6 @@ func init() { } func ProcessXterm(m *ice.Message, cmds, text string, arg ...string) { + m.Option(nfs.PATH, "") m.Cmdy(ctx.COMMAND, XTERM).Push(ctx.ARGS, kit.Format([]string{m.Cmdx(XTERM, mdb.CREATE, mdb.TYPE, cmds, mdb.NAME, kit.Select("", arg, 0), mdb.TEXT, text)})).ProcessField(XTERM) } diff --git a/core/wiki/word.go b/core/wiki/word.go index 7b2e8a11..d556e3d7 100644 --- a/core/wiki/word.go +++ b/core/wiki/word.go @@ -7,7 +7,6 @@ import ( "shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/nfs" "shylinux.com/x/icebergs/base/ssh" - "shylinux.com/x/icebergs/base/web" "shylinux.com/x/icebergs/misc/git" kit "shylinux.com/x/toolkits" ) @@ -58,16 +57,6 @@ func init() { } }}, }) - ctx.AddRunChecker(func(m *ice.Message, cmd, check string, arg ...string) bool { - switch check { - case ice.HELP: - if file := kit.ExtChange(ctx.GetCmdFile(m, cmd), nfs.SHY); nfs.ExistsFile(m, file) { - ctx.ProcessFloat(m, web.WIKI_WORD, file) - } - return true - } - return false - }) } func WordAction(template string, arg ...ice.Any) ice.Actions { return ice.Actions{ice.CTX_INIT: mdb.AutoConfig(append([]ice.Any{nfs.TEMPLATE, template}, arg...)...)} diff --git a/info.go b/info.go index f0365382..40fb9c45 100644 --- a/info.go +++ b/info.go @@ -21,6 +21,8 @@ var Info = struct { Pathname string Username string Password string + Intshell string + Volcanos string Domain string NodeType string diff --git a/logs.go b/logs.go index 1534da56..0993c2aa 100644 --- a/logs.go +++ b/logs.go @@ -1,6 +1,9 @@ package ice import ( + "bufio" + "encoding/json" + "fmt" "io" "runtime" "strings" @@ -180,6 +183,32 @@ func (m *Message) FormatCost() string { func (m *Message) FormatSize() string { return kit.Format("%dx%d %v", m.Length(), len(m.meta[MSG_APPEND]), kit.Simple(m.meta[MSG_APPEND])) } +func (m *Message) DumpMeta(w io.Writer) { + m.meta[MSG_OPTION] = kit.Filters(m.meta[MSG_OPTION], "sessid", "cmds", "fields", "_option", "_handle", "_output", "", "_name", "_index", "log.caller", "aaa.checker") + kit.For(m.meta[MSG_OPTION], func(i int, k string) { + kit.If(len(m.meta[k]) == 0 || len(m.meta[k]) == 1 && m.meta[k][0] == "", func() { m.meta[MSG_OPTION][i] = "" }) + }) + bio := bufio.NewWriter(w) + defer bio.Flush() + echo := func(k string) { + if len(m.meta[k]) == 0 { + return + } + kit.If(k != MSG_DETAIL, func() { fmt.Fprintln(bio, FS) }) + fmt.Fprint(bio, kit.Format(" %q: ", k)) + b, _ := json.Marshal(m.meta[k]) + bio.Write(b) + } + fmt.Fprintln(bio, "{") + defer fmt.Fprintln(bio, "}") + echo(MSG_DETAIL) + echo(MSG_OPTION) + kit.For(m.meta[MSG_OPTION], func(k string) { echo(k) }) + kit.For(m.meta[MSG_APPEND], func(k string) { echo(k) }) + echo(MSG_APPEND) + echo(MSG_RESULT) + fmt.Fprintln(bio) +} func (m *Message) FormatMeta() string { return kit.Format(m.meta) }