From 25edf639ae50590c8680eef6215b2912ee984229 Mon Sep 17 00:00:00 2001 From: harveyshao Date: Wed, 30 Mar 2022 19:21:31 +0800 Subject: [PATCH] opt some --- base/mdb/list.go | 2 +- conf.go | 1 + core/code/go.go | 15 +++++++++++++-- core/wiki/field.go | 5 ++++- meta.go | 4 ++-- misc.go | 4 ++-- option.go | 2 +- 7 files changed, 24 insertions(+), 9 deletions(-) diff --git a/base/mdb/list.go b/base/mdb/list.go index f06744c4..20dc0ca6 100644 --- a/base/mdb/list.go +++ b/base/mdb/list.go @@ -75,7 +75,7 @@ func _list_export(m *ice.Message, prefix, chain, file string) { head := kit.Split(m.OptionFields()) m.Grows(prefix, chain, "", "", func(index int, val map[string]interface{}) { if val = kit.GetMeta(val); index == 0 { - if len(head) == 0 || head[0] == "detail" { // 默认表头 + if len(head) == 0 || head[0] == ice.CACHE_DETAIL { // 默认表头 for k := range val { head = append(head, k) } diff --git a/conf.go b/conf.go index a43c2d2a..efd29d7d 100644 --- a/conf.go +++ b/conf.go @@ -205,6 +205,7 @@ const ( // MSG CACHE_FILTER = "cache.filter" CACHE_VALUE = "cache.value" CACHE_FIELD = "cache.field" + CACHE_DETAIL = "detail" ) const ( // RENDER RENDER_RAW = "_raw" diff --git a/core/code/go.go b/core/code/go.go index 6d9e5125..50431f6a 100644 --- a/core/code/go.go +++ b/core/code/go.go @@ -112,6 +112,14 @@ func _go_show(m *ice.Message, arg ...string) { } } } +func _sum_show(m *ice.Message, file string) { + m.Cmd(nfs.CAT, file, func(ls []string, line string) { + m.Push("repos", ls[0]) + m.Push("version", ls[1]) + m.Push("hash", ls[2]) + }) + m.StatusTimeCount() +} func _mod_show(m *ice.Message, file string) { const ( MODULE = "module" @@ -126,7 +134,7 @@ func _mod_show(m *ice.Message, file string) { m.Cmd(nfs.CAT, file, func(ls []string, line string) { switch { case strings.HasPrefix(line, MODULE): - require[ls[1]] = "" + require[ls[1]] = m.Cmdx(cli.SYSTEM, GIT, "describe", "--tags") replace[ls[1]] = nfs.PWD case strings.HasPrefix(line, REQUIRE+" ("): block = REQUIRE @@ -155,6 +163,7 @@ func _mod_show(m *ice.Message, file string) { m.Push(REPLACE, kit.Select("", replace[k])) } m.Sort(REPLACE) + m.StatusTimeCount() } const ( @@ -183,7 +192,9 @@ func init() { m.Cmdy(cli.SYSTEM, GO, "doc", strings.TrimSuffix(arg[1], ice.PT+arg[0]), kit.Dict(cli.CMD_DIR, arg[2])).SetAppend() }}, }, PlugAction())}, - SUM: {Name: "sum", Help: "版本", Action: PlugAction()}, + SUM: {Name: "sum", Help: "版本", Action: ice.MergeAction(map[string]*ice.Action{ + mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { _sum_show(m, path.Join(arg[2], arg[1])) }}, + }, PlugAction())}, MOD: {Name: "mod", Help: "模块", Action: ice.MergeAction(map[string]*ice.Action{ mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { _mod_show(m, path.Join(arg[2], arg[1])) }}, }, PlugAction())}, diff --git a/core/wiki/field.go b/core/wiki/field.go index 9e3add7a..442c37c0 100644 --- a/core/wiki/field.go +++ b/core/wiki/field.go @@ -125,7 +125,10 @@ func init() { ice.RUN: {Name: "run", Help: "执行"}, }, ctx.CmdAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if arg = _name(m, arg); strings.Contains(arg[1], ice.NL) { - arg = append([]string{arg[0], "web.chat.div", "auto.cmd", "split", "opts.text", arg[1]}, arg[2:]...) + arg = kit.Simple(arg[0], "web.chat.div", "auto.cmd", "split", "opts.text", arg[1], arg[2:]) + } + if arg[1] == "args" { + arg = kit.Simple("", arg) } _field_show(m, arg[0], arg[1], arg[2:]...) }}, diff --git a/meta.go b/meta.go index e2f81dc0..8765e617 100644 --- a/meta.go +++ b/meta.go @@ -116,7 +116,7 @@ func (m *Message) Push(key string, value interface{}, arg ...interface{}) *Messa var v interface{} switch k { case KEY, HASH: - if key != "" && key != "detail" { + if key != "" && key != CACHE_DETAIL { v = key break } @@ -133,7 +133,7 @@ func (m *Message) Push(key string, value interface{}, arg ...interface{}) *Messa // 追加数据 switch v := kit.Format(v); key { - case "detail": + case CACHE_DETAIL: m.Add(MSG_APPEND, KEY, k) m.Add(MSG_APPEND, VALUE, v) default: diff --git a/misc.go b/misc.go index bf475624..03102a26 100644 --- a/misc.go +++ b/misc.go @@ -85,7 +85,7 @@ func (m *Message) Split(str string, arg ...string) *Message { // field sp nl } func (m *Message) FieldsIsDetail() bool { - if m.OptionFields() == "detail" { + if m.OptionFields() == CACHE_DETAIL { return true } if len(m.meta[MSG_APPEND]) == 2 && m.meta[MSG_APPEND][0] == KEY && m.meta[MSG_APPEND][1] == VALUE { @@ -95,7 +95,7 @@ func (m *Message) FieldsIsDetail() bool { } func (m *Message) PushDetail(value interface{}, arg ...interface{}) *Message { - return m.Push("detail", value, arg...) + return m.Push(CACHE_DETAIL, value, arg...) } func (m *Message) IsErr(arg ...string) bool { return len(arg) > 0 && m.Result(1) == arg[0] || m.Result(0) == ErrWarn diff --git a/option.go b/option.go index bfd354b5..15ecaeda 100644 --- a/option.go +++ b/option.go @@ -81,7 +81,7 @@ func (m *Message) OptionTemplate() string { } func (m *Message) Fields(length int, fields ...string) string { - return m.Option(MSG_FIELDS, kit.Select(kit.Select("detail", fields, length), m.Option(MSG_FIELDS))) + return m.Option(MSG_FIELDS, kit.Select(kit.Select(CACHE_DETAIL, fields, length), m.Option(MSG_FIELDS))) } func (m *Message) Upload(dir string) { up := kit.Simple(m.Optionv(MSG_UPLOAD))