From 8d3bb899b1cfc86fb9ad995ff87d33e244cf6a55 Mon Sep 17 00:00:00 2001 From: "shylinux@163.com" Date: Mon, 12 Sep 2022 14:14:16 +0800 Subject: [PATCH] opt some --- base/cli/forever.go | 6 ++++-- base/cli/system.go | 16 +++++++++++++++ base/ctx/command.go | 47 +++++++++++++++++++++----------------------- core/code/binpack.go | 21 ++++++++++++++++++++ core/code/inner.go | 4 +++- init.go | 9 +++++++++ misc.go | 8 ++------ misc/git/status.go | 3 ++- option.go | 4 ---- 9 files changed, 79 insertions(+), 39 deletions(-) diff --git a/base/cli/forever.go b/base/cli/forever.go index 1363d73b..e2983b73 100644 --- a/base/cli/forever.go +++ b/base/cli/forever.go @@ -59,12 +59,14 @@ func init() { for { logs.Println("run %s", kit.Join(arg, ice.SP)) - if m.Sleep300ms(); IsSuccess(m.Cmd(SYSTEM, arg)) { + msg := m.Cmd(SYSTEM, arg) + if m.Sleep300ms(); IsSuccess(msg) { logs.Println() logs.Println(ice.EXIT) // 正常退出 break } else { - logs.Println() + m.Sleep("10s") + logs.Println("what %v", msg.FormatMeta()) } } }}, diff --git a/base/cli/system.go b/base/cli/system.go index 6078b079..6ee621a0 100644 --- a/base/cli/system.go +++ b/base/cli/system.go @@ -39,6 +39,18 @@ func _system_cmd(m *ice.Message, arg ...string) *exec.Cmd { // bin = file // 当前目录 // } // } + if bin == "" { + if file := _system_find(m, arg[0], ice.BIN, nfs.PWD); file != "" { + m.Logs(mdb.SELECT, "mirrors cmd", file) + bin = file // 当前目录 + } + } + if bin == "" && !strings.Contains(arg[0], ice.PS) { + if file := _system_find(m, arg[0]); file != "" { + m.Logs(mdb.SELECT, "systems cmd", file) + bin = file // 系统命令 + } + } if bin == "" && !strings.Contains(arg[0], ice.PS) { m.Cmd(MIRRORS, CMD, arg[0]) if file := _system_find(m, arg[0]); file != "" { @@ -46,6 +58,7 @@ func _system_cmd(m *ice.Message, arg ...string) *exec.Cmd { bin = file // 软件镜像 } } + cmd := exec.Command(bin, arg[1:]...) // 运行目录 @@ -155,6 +168,9 @@ func init() { m.Cmdy(nfs.CAT, ice.ETC_PATH) }}, MAN: {Name: "man", Help: "文档", Hand: func(m *ice.Message, arg ...string) { + if len(arg) == 1 { + arg = append(arg, "") + } m.Option(CMD_ENV, "COLUMNS", kit.Int(kit.Select("1920", m.Option("width")))/12) m.Cmdy(SYSTEM, "sh", "-c", kit.Format("man %s %s|col -b", kit.Select("", arg[1], arg[1] != "1"), arg[0])) if IsSuccess(m) && m.Append(CMD_ERR) == "" { diff --git a/base/ctx/command.go b/base/ctx/command.go index 97c1b0b9..ae481111 100644 --- a/base/ctx/command.go +++ b/base/ctx/command.go @@ -98,32 +98,14 @@ func init() { } }}, "tags": {Name: "tags", Help: "索引", Hand: func(m *ice.Message, arg ...string) { - m.Travel(func(p *ice.Context, s *ice.Context, key string, cmd *ice.Command) { - if key[0] == '/' || key[0] == '_' { - return // 内部命令 - } - - var ls []string - if cmd.RawHand != nil { - switch h := cmd.RawHand.(type) { - case string: - ls = kit.Split(h, ":") - default: - ls = kit.Split(kit.FileLine(cmd.RawHand, 100), ":") - } - } else if cmd.Hand != nil { - return - ls = kit.Split(kit.FileLine(cmd.Hand, 100), ":") - } else { - return - } + TravelCmd(m, func(key, file, line string) { m.Push("name", key) - m.Push("file", strings.TrimPrefix(ls[0], kit.Path("")+ice.PS)) - m.Push("line", ls[1]) + m.Push("file", file) + m.Push("line", line) }) m.Sort("name") m.Tables(func(value ice.Maps) { - m.Echo("%s\t%s\t%s;\" m\n", value["name"], value["file"], value["line"]) + m.Echo("%s\t%s\t%s;\" f\n", value["name"], value["file"], value["line"]) }) m.Cmd("nfs.save", "tags", m.Result()) }}, @@ -154,15 +136,15 @@ func CmdAction(args ...ice.Any) ice.Actions { m.Cmd(CONFIG, "reset", arg[0]) case "help": if file := strings.ReplaceAll(GetCmdFile(m, arg[0]), ".go", ".shy"); nfs.ExistsFile(m, file) { - m.ProcessStory("web.wiki.word", file) + ProcessFloat(m, "web.wiki.word", file) } case "script": if file := strings.ReplaceAll(GetCmdFile(m, arg[0]), ".go", ".js"); nfs.ExistsFile(m, file) { - m.ProcessStory("web.code.inner", file) + ProcessFloat(m, "web.code.inner", file) } case "source": if file := GetCmdFile(m, arg[0]); nfs.ExistsFile(m, file) { - m.ProcessStory("web.code.inner", file) + ProcessFloat(m, "web.code.inner", file) } } return @@ -173,6 +155,11 @@ func CmdAction(args ...ice.Any) ice.Actions { }}, } } +func ProcessFloat(m *ice.Message, arg ...string) { + m.Option(ice.MSG_PROCESS, "_float") + m.Option(ice.PROCESS_ARG, arg) + m.Cmdy(COMMAND, arg[0]) +} func ProcessField(m *ice.Message, cmd string, args []string, arg ...string) { if len(arg) > 0 && arg[0] == ice.RUN { m.Cmdy(cmd, arg[1:]) @@ -266,3 +253,13 @@ func GetCmdFile(m *ice.Message, cmds string) (file string) { }) return } +func TravelCmd(m *ice.Message, cb func(key, file, line string)) { + m.Travel(func(p *ice.Context, s *ice.Context, key string, cmd *ice.Command) { + if key[0] == '/' || key[0] == '_' { + return // 内部命令 + } + + ls := kit.Split(cmd.GetFileLine(), ":") + cb(key, strings.TrimPrefix(ls[0], kit.Path("")+ice.PS), ls[1]) + }) +} diff --git a/core/code/binpack.go b/core/code/binpack.go index 5ca0a6b3..8a83b195 100644 --- a/core/code/binpack.go +++ b/core/code/binpack.go @@ -9,6 +9,7 @@ import ( "strings" ice "shylinux.com/x/icebergs" + "shylinux.com/x/icebergs/base/ctx" "shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/nfs" kit "shylinux.com/x/toolkits" @@ -116,6 +117,26 @@ func init() { } } }) + + list := map[string]bool{} + ctx.TravelCmd(m, func(key, file, line string) { + dir := path.Dir(file) + if strings.HasPrefix(dir, ice.SRC) { + return + } + if list[dir] { + return + } + list[dir] = true + + m.Cmd(nfs.DIR, dir, nfs.PATH, kit.Dict(nfs.DIR_ROOT, nfs.PWD, nfs.DIR_REG, ".*.(shy|js)")).Tables(func(value ice.Maps) { + if list[value[nfs.PATH]] { + return + } + list[value[nfs.PATH]] = true + _binpack_file(m, w, value[nfs.PATH]) + }) + }) } } diff --git a/core/code/inner.go b/core/code/inner.go index f0969c7a..153c1b5c 100644 --- a/core/code/inner.go +++ b/core/code/inner.go @@ -186,7 +186,9 @@ func init() { m.StatusTimeCount(mdb.INDEX, 0) }}, nfs.TAGS: {Name: "tags", Help: "索引", Hand: func(m *ice.Message, arg ...string) { - _inner_tags(m, m.Option(nfs.PATH), arg[0]) + if _inner_tags(m, m.Option(nfs.PATH), arg[0]); m.Length() == 0 { + _inner_tags(m, "", arg[0]) + } }}, cli.MAKE: {Name: "make", Help: "构建", Hand: func(m *ice.Message, arg ...string) { _inner_make(m, m.Cmd(cli.SYSTEM, cli.MAKE, arg)) diff --git a/init.go b/init.go index 03a03c59..45c1bd6e 100644 --- a/init.go +++ b/init.go @@ -70,6 +70,15 @@ var Index = &Context{Name: ICE, Help: "冰山模块", Configs: Configs{ QUIT: {Name: "quit", Help: "结束", Hand: func(m *Message, arg ...string) { os.Exit(0) }}, + "some": {Name: "quit", Help: "结束", Hand: func(m *Message, arg ...string) { + m.OptionFields("detail") + m.Push("modpath", kit.ModPath(m.root.Travel)) + m.Push("modname", kit.ModName(m.root.Travel)) + m.Push("pathname", kit.PathName(m.root.Travel)) + m.Push("filename", kit.FileName(m.root.Travel)) + m.Push("funcname", kit.FuncName(m.root.Travel)) + m.Push("fileline", kit.FileLine(m.root.Travel, 100)) + }}, EXIT: {Name: "exit", Help: "退出", Hand: func(m *Message, arg ...string) { defer m.Target().Close(m.root.Spawn(), arg...) m.root.Option(EXIT, kit.Select("0", arg, 0)) diff --git a/misc.go b/misc.go index 746e83b3..db00aa86 100644 --- a/misc.go +++ b/misc.go @@ -260,9 +260,7 @@ func (c *Context) _command(m *Message, cmd *Command, key string, arg ...string) } } - m._target = kit.FileLine(cmd.Hand, 3) - if cmd.RawHand != nil { - // m._target = kit.FileLine(cmd.RawHand, 3) + if m._target = kit.FileLine(cmd.Hand, 3); cmd.RawHand != nil { m._target = kit.Format(cmd.RawHand) } if key == "select" { @@ -307,9 +305,7 @@ func (c *Context) _action(m *Message, cmd *Command, key string, sub string, h *A } } - m._target = kit.FileLine(h.Hand, 3) - if cmd.RawHand != nil { - // m._target = kit.FileLine(cmd.RawHand, 3) + if m._target = kit.FileLine(h.Hand, 3); cmd.RawHand != nil { m._target = kit.Format(cmd.RawHand) } m.Log(LOG_CMDS, "%s.%s %s %d %v", c.Name, key, sub, len(arg), arg, diff --git a/misc/git/status.go b/misc/git/status.go index 80ec6e3b..a8d2f953 100644 --- a/misc/git/status.go +++ b/misc/git/status.go @@ -111,7 +111,8 @@ func _status_each(m *ice.Message, title string, cmds ...string) { m.ProcessHold() } func _status_stat(m *ice.Message, files, adds, dels int) (int, int, int) { - for _, v := range kit.Split(_git_cmds(m, DIFF, "--shortstat"), ice.FS) { + res := _git_cmds(m, DIFF, "--shortstat") + for _, v := range kit.Split(res, ice.FS, ice.FS) { n := kit.Int(kit.Split(strings.TrimSpace(v))[0]) switch { case strings.Contains(v, "file"): diff --git a/option.go b/option.go index 6eff7388..921c5834 100644 --- a/option.go +++ b/option.go @@ -127,10 +127,6 @@ func (m *Message) ProcessDisplay(arg ...Any) { m.Option(MSG_DISPLAY, arg...) } -func (m *Message) ProcessStory(arg ...Any) { - m.Option(MSG_PROCESS, "_story") - m.Option(PROCESS_ARG, arg...) -} func (m *Message) ProcessField(arg ...Any) { m.Process(PROCESS_FIELD) m.Option(FIELD_PREFIX, arg...)