From 47ea2e37a553eed51c1b08df2d064210601ce67a Mon Sep 17 00:00:00 2001 From: harveyshao Date: Wed, 4 May 2022 23:24:10 +0800 Subject: [PATCH] add parse --- base/cli/runtime.go | 1 + base/nfs/cat.go | 11 ++++++----- core/chat/cmd.go | 35 +++++++++++++++++++++++++++++++++-- info.go | 44 +++++++++++++++++++++++++++++++++++++------- logs.go | 3 +++ misc/vim/tags.go | 3 +++ render.go | 7 ++----- 7 files changed, 85 insertions(+), 19 deletions(-) diff --git a/base/cli/runtime.go b/base/cli/runtime.go index 6406b9ff..adb19de3 100644 --- a/base/cli/runtime.go +++ b/base/cli/runtime.go @@ -199,6 +199,7 @@ func init() { m.Push(mdb.NAME, v) } m.Sort(nfs.FILE) + m.StatusTimeCount() }}, "route": {Name: "route", Help: "接口命令", Hand: func(m *ice.Message, arg ...string) { for k, v := range ice.Info.Route { diff --git a/base/nfs/cat.go b/base/nfs/cat.go index 140225c8..91200652 100644 --- a/base/nfs/cat.go +++ b/base/nfs/cat.go @@ -139,13 +139,14 @@ const ( JS = ice.JS GO = ice.GO SH = ice.SH + SHY = ice.SHY CSV = ice.CSV JSON = ice.JSON - YML = "yml" - IML = "iml" - TXT = "txt" - SHY = "shy" - SVG = "svg" + + YML = "yml" + IML = "iml" + TXT = "txt" + SVG = "svg" PWD = "./" ) diff --git a/core/chat/cmd.go b/core/chat/cmd.go index 278f7ebd..12bf7785 100644 --- a/core/chat/cmd.go +++ b/core/chat/cmd.go @@ -5,6 +5,7 @@ import ( "strings" ice "shylinux.com/x/icebergs" + "shylinux.com/x/icebergs/base/cli" "shylinux.com/x/icebergs/base/ctx" "shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/nfs" @@ -25,7 +26,7 @@ func init() { m.Cmdy(CMD, mdb.CREATE, mdb.TYPE, "csv", mdb.NAME, "web.wiki.data") m.Cmdy(CMD, mdb.CREATE, mdb.TYPE, "json", mdb.NAME, "web.wiki.json") - for _, k := range []string{"sh", "go", "js", "mod", "sum"} { + for _, k := range []string{"mod", "sum"} { m.Cmdy(CMD, mdb.CREATE, mdb.TYPE, k, mdb.NAME, "web.code.inner") } }}, @@ -35,6 +36,12 @@ func init() { return // 目录 } + if mdb.HashSelect(m.Spawn(), path.Join(arg...)).Table(func(index int, value map[string]string, head []string) { + m.RenderCmd(value[mdb.NAME]) + }).Length() > 0 { + return // 命令 + } + p := path.Join(m.Config(nfs.PATH), path.Join(arg...)) if mdb.HashSelect(m.Spawn(), kit.Ext(m.R.URL.Path)).Table(func(index int, value map[string]string, head []string) { m.RenderCmd(value[mdb.NAME], p) @@ -42,6 +49,30 @@ func init() { return // 插件 } + switch p := path.Join(arg...); kit.Ext(p) { + case nfs.JS: + if cmd := ice.GetFileCmd(p); cmd != "" { + m.Display(ice.FileURI(p)) + m.RenderCmd(cmd) + } + return + case nfs.GO: + if cmd := ice.GetFileCmd(p); cmd != "" { + m.RenderCmd(cmd) + } + return + case nfs.SH: + if cmd := ice.GetFileCmd(p); cmd != "" { + msg := m.Cmd(cmd, ice.OptionFields("")) + if msg.Length() > 0 { + msg.Table() + } + m.Cmdy(cli.SYSTEM, "sh", p, msg.Result()) + m.RenderResult() + } + return + } + if m.PodCmd(ctx.COMMAND, arg[0]) { if !m.IsErr() { m.RenderCmd(arg[0], arg[1:]) // 远程命令 @@ -74,7 +105,7 @@ func init() { m.ProcessLocation(arg[0]) return } - switch kit.Ext(path.Join(arg...)) { + switch p := path.Join(arg...); kit.Ext(p) { case "html": m.RenderResult(m.Cmdx(nfs.CAT, path.Join(ice.SRC, path.Join(arg...)))) return diff --git a/info.go b/info.go index 4a4463ac..13561581 100644 --- a/info.go +++ b/info.go @@ -64,11 +64,7 @@ source: https://shylinux.com/x/icebergs names: map[string]interface{}{}, } -func FileCmd(dir string) string { - dir = strings.Split(dir, DF)[0] - dir = strings.ReplaceAll(dir, ".js", ".go") - dir = strings.ReplaceAll(dir, ".sh", ".go") - +func FileURI(dir string) string { if strings.Contains(dir, "go/pkg/mod") { return path.Join("/require", strings.Split(dir, "go/pkg/mod")[1]) } @@ -86,5 +82,39 @@ func FileCmd(dir string) string { } return dir } -func AddFileCmd(dir, key string) { Info.File[FileCmd(dir)] = key } -func GetFileCmd(dir string) string { return Info.File[FileCmd(dir)] } +func FileCmd(dir string) string { + dir = strings.Split(dir, DF)[0] + dir = strings.ReplaceAll(dir, ".js", ".go") + dir = strings.ReplaceAll(dir, ".sh", ".go") + return FileURI(dir) +} +func AddFileCmd(dir, key string) { + Info.File[FileCmd(dir)] = key +} +func GetFileCmd(dir string) string { + if strings.HasPrefix(dir, "require/") { + dir = "/" + dir + } + for _, dir := range []string{dir, "/require/"+Info.Make.Module+"/"+dir}{ + if cmd, ok := Info.File[FileCmd(dir)]; ok { + return cmd + } + p := path.Dir(dir) + if cmd, ok := Info.File[FileCmd(path.Join(p, path.Base(p)+".go"))]; ok { + return cmd + } + for k, v := range Info.File { + if strings.HasPrefix(k, p) { + return v + } + } + } + return "" +} +func FileRequire(n int) string { + p := kit.Split(kit.FileLine(n, 100), DF)[0] + if strings.Contains(p, "go/pkg/mod") { + return path.Join("/require", strings.Split(p, "go/pkg/mod")[1]) + } + return path.Join("/require/" + kit.ModPath(n), path.Base(p)) +} diff --git a/logs.go b/logs.go index 4de8a039..ef1623e8 100644 --- a/logs.go +++ b/logs.go @@ -112,6 +112,9 @@ func (m *Message) Error(err bool, str string, arg ...interface{}) bool { return false } func (m *Message) Debug(str string, arg ...interface{}) { + if str == "" { + str = m.FormatMeta() + } m.log(LOG_DEBUG, str, arg...) } diff --git a/misc/vim/tags.go b/misc/vim/tags.go index c1cce54e..967fed25 100644 --- a/misc/vim/tags.go +++ b/misc/vim/tags.go @@ -60,6 +60,9 @@ func init() { m.ProcessCommand(code.INNER, m.OptionSplit("path,file,line"), arg...) }}, INPUT: {Name: "input name text", Help: "补全", Hand: func(m *ice.Message, arg ...string) { + if m.Option(mdb.TEXT) == "" { + return + } mdb.ZoneSelectCB(m, kit.Slice(kit.Split(m.Option(mdb.TEXT), ice.PT), -1)[0], func(value map[string]string) { if !strings.Contains(value[mdb.NAME], m.Option(mdb.NAME)) { return diff --git a/render.go b/render.go index 1c197d85..db787c6d 100644 --- a/render.go +++ b/render.go @@ -89,6 +89,7 @@ func (m *Message) RenderCmd(index string, args ...interface{}) { list = kit.Format(kit.List(kit.Dict( INDEX, index, ARGS, kit.Simple(args), msg.AppendSimple(NAME, HELP), INPUTS, kit.UnMarshal(msg.Append(LIST)), FEATURE, kit.UnMarshal(msg.Append(META)), + "display", m.Option(MSG_DISPLAY), ))) } m.Echo(kit.Format(` @@ -285,11 +286,7 @@ func DisplayRequire(n int, file string, arg ...string) map[string]string { file = kit.Keys(kit.FileName(n+1), JS) } if !strings.HasPrefix(file, HTTP) && !strings.HasPrefix(file, PS) { - if kit.FileExists("src/" + file) { - file = path.Join(PS, REQUIRE, "src/", file) - } else { - file = path.Join(PS, REQUIRE, kit.ModPath(n+1, file)) - } + file = path.Join(PS, path.Join(path.Dir(FileRequire(n+2)), file)) } return DisplayBase(file, arg...) }