From eae1d2ac54c051c6c9d6cadfddb2e9c7b2eff797 Mon Sep 17 00:00:00 2001 From: harveyshao Date: Sun, 21 Nov 2021 12:55:40 +0800 Subject: [PATCH] opt spide.go --- base/ctx/context.go | 20 +++++++++++++++++++- misc.go | 4 ++-- misc/git/spide.go | 3 +++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/base/ctx/context.go b/base/ctx/context.go index 5d41a6a5..2cf7ca0c 100644 --- a/base/ctx/context.go +++ b/base/ctx/context.go @@ -1,6 +1,8 @@ package ctx import ( + "strings" + ice "shylinux.com/x/icebergs" kit "shylinux.com/x/toolkits" ) @@ -18,7 +20,23 @@ const CONTEXT = "context" func init() { Index.Merge(&ice.Context{Commands: map[string]*ice.Command{ - CONTEXT: {Name: "context name=web.chat action=context,command,config key auto", Help: "模块", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + CONTEXT: {Name: "context name=web.chat action=context,command,config key auto spide", Help: "模块", Action: ice.MergeAction(map[string]*ice.Action{ + "spide": {Name: "spide", Help: "架构图", Hand: func(m *ice.Message, arg ...string) { + if len(arg) == 0 || arg[1] == CONTEXT { // 模块列表 + m.Cmdy(CONTEXT, kit.Select("ice", arg, 0), CONTEXT) + m.Display("/plugin/story/spide.js", "root", kit.Select("ice", arg, 0), + "field", "name", "split", ".", "prefix", SPIDE) + return + } + if index := kit.Keys(arg[1]); strings.HasSuffix(index, arg[2]) { // 命令列表 + m.Cmdy(CONTEXT, index, COMMAND).Table(func(i int, value map[string]string, head []string) { + m.Push("file", index) + }) + } else { // 命令详情 + m.Cmdy(COMMAND, kit.Keys(index, strings.Split(arg[2], " ")[0])) + } + }}, + }, CmdAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Search(kit.Select(ice.ICE, arg, 0)+ice.PT, func(p *ice.Context, s *ice.Context, key string) { msg := m.Spawn(s) defer m.Copy(msg) diff --git a/misc.go b/misc.go index b5b977aa..5753b270 100644 --- a/misc.go +++ b/misc.go @@ -78,8 +78,8 @@ func (m *Message) Split(str string, field string, sp string, nl string) *Message return m } -func (m *Message) Display(file string) *Message { - m.Option(MSG_DISPLAY, Display0(2, file)["display"]) +func (m *Message) Display(file string, arg ...interface{}) *Message { + m.Option(MSG_DISPLAY, kit.MergeURL(Display0(2, file)["display"], arg...)) return m } func (m *Message) DisplayLocal(file string) *Message { diff --git a/misc/git/spide.go b/misc/git/spide.go index 33144872..1c02ec28 100644 --- a/misc/git/spide.go +++ b/misc/git/spide.go @@ -87,6 +87,9 @@ func init() { }) return } + if !strings.HasSuffix(arg[1], arg[2]) { + return + } // 语法解析 switch m.Option(cli.CMD_DIR, m.Option(nfs.DIR_ROOT)); kit.Ext(arg[1]) {