From 155763119aeb256c066416ecca7ae3cdcc7e718d Mon Sep 17 00:00:00 2001 From: harveyshao Date: Mon, 16 Aug 2021 20:47:19 +0800 Subject: [PATCH] add misc/git/count.go --- base/nfs/dir.go | 6 +++++ misc/git/count.go | 58 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 misc/git/count.go diff --git a/base/nfs/dir.go b/base/nfs/dir.go index 95ac2c44..370b39f2 100644 --- a/base/nfs/dir.go +++ b/base/nfs/dir.go @@ -46,6 +46,12 @@ func _dir_show(m *ice.Message, root string, name string, level int, deep bool, d p := path.Join(root, name, f.Name()) if !(dir_type == TYPE_CAT && f.IsDir() || dir_type == TYPE_DIR && !f.IsDir()) && (dir_reg == nil || dir_reg.MatchString(f.Name())) { + switch cb := m.Optionv(kit.Keycb(DIR)).(type) { + case func(p string): + cb(p) + continue + } + for _, field := range fields { switch field { case kit.MDB_TIME: diff --git a/misc/git/count.go b/misc/git/count.go new file mode 100644 index 00000000..8b8e4f0c --- /dev/null +++ b/misc/git/count.go @@ -0,0 +1,58 @@ +package git + +import ( + "strings" + + ice "github.com/shylinux/icebergs" + "github.com/shylinux/icebergs/base/nfs" + kit "github.com/shylinux/toolkits" +) + +const COUNT = "count" + +func init() { + Index.Merge(&ice.Context{Commands: map[string]*ice.Command{ + COUNT: {Name: "count path auto count", Help: "统计", Action: map[string]*ice.Action{ + COUNT: {Name: "count", Help: "计数", Hand: func(m *ice.Message, arg ...string) { + files := map[string]int{} + lines := map[string]int{} + m.Option(nfs.DIR_DEEP, ice.TRUE) + m.Option(nfs.DIR_TYPE, nfs.TYPE_CAT) + m.Cmdy(nfs.DIR, arg, func(file string) { + if strings.Contains(file, "bin/") { + return + } + switch kit.Ext(file) { + case "sum", "log": + return + } + + files["total"]++ + files[kit.Ext(file)]++ + m.Cmdy(nfs.CAT, file, func(text string, line int) { + if kit.Ext(file) == "go" { + switch { + case strings.HasPrefix(text, "func"): + lines["_func"]++ + case strings.HasPrefix(text, "type"): + lines["_type"]++ + } + } + + lines["total"]++ + lines[kit.Ext(file)]++ + }) + }) + for k := range lines { + m.Push("type", k) + m.Push("files", files[k]) + m.Push("lines", lines[k]) + } + m.SortIntR("lines") + m.StatusTime() + }}, + }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + m.Cmdy(nfs.DIR, arg) + }}, + }}) +}