From ebc9a99756a5aa3b7f6b7b9ebf03b86dda8385e7 Mon Sep 17 00:00:00 2001 From: shaoying Date: Sun, 9 Aug 2020 01:17:22 +0800 Subject: [PATCH] opt git --- core/code/inner.go | 2 +- core/wiki/template.go | 2 +- core/wiki/word.go | 6 +- go.sum | 2 + misc/git/git.go | 235 +++++++++++++++++++++--------------------- misc/git/git.shy | 8 +- 6 files changed, 131 insertions(+), 124 deletions(-) diff --git a/core/code/inner.go b/core/code/inner.go index d1627b60..43917681 100644 --- a/core/code/inner.go +++ b/core/code/inner.go @@ -80,7 +80,7 @@ func init() { } _inner_list(m, _inner_ext(arg[1]), arg[1], arg[0]) }}, - VIMER: {Name: "vimer path=usr/demo file=hi.sh line=1 刷新:button=auto 编辑:button 保存:button 运行:button 项目:button", Help: "编辑器", Meta: kit.Dict( + VIMER: {Name: "vimer path=usr/demo file=hi.sh line=1 刷新:button=auto 保存:button 运行:button 项目:button", Help: "编辑器", Meta: kit.Dict( "display", "/plugin/local/code/vimer.js", "style", "editor", ), Action: map[string]*ice.Action{ web.UPLOAD: {Name: "upload path name", Help: "上传", Hand: func(m *ice.Message, arg ...string) { diff --git a/core/wiki/template.go b/core/wiki/template.go index b06eecbd..ecca5b74 100644 --- a/core/wiki/template.go +++ b/core/wiki/template.go @@ -19,7 +19,7 @@ var refer = `` -var spark = `

{{.Option "text"}}

` +var spark = `

{{.Option "text"}}

` var chart = ` 1 { if _, e := os.Stat(path.Join(arg[1], ".git")); e != nil && os.IsNotExist(e) { // 下载仓库 - m.Cmd(cli.SYSTEM, "git", "clone", "-b", kit.Select("master", arg, 3), - kit.Select(m.Conf("repos", "meta.owner")+"/"+arg[0], arg, 2), arg[1]) - add(m, arg[0], arg[1]) + m.Cmd(cli.SYSTEM, GIT, "clone", "-b", kit.Select("master", arg, 3), + kit.Select(m.Conf(REPOS, "meta.owner")+"/"+arg[0], arg, 2), arg[1]) + _repos_insert(m, arg[0], arg[1]) } } if len(arg) > 0 { // 仓库详情 - m.Richs("repos", nil, arg[0], func(key string, value map[string]interface{}) { - m.Push("detail", value["meta"]) + m.Richs(REPOS, nil, arg[0], func(key string, value map[string]interface{}) { + m.Push("detail", value[kit.MDB_META]) }) return } // 仓库列表 - m.Richs("repos", nil, "*", func(key string, value map[string]interface{}) { - m.Push(key, value["meta"], []string{"time", "name", "branch", "last"}) + m.Richs(REPOS, nil, kit.MDB_FOREACH, func(key string, value map[string]interface{}) { + m.Push(key, value[kit.MDB_META], []string{kit.MDB_TIME, kit.MDB_NAME, "branch", "last"}) }) - m.Sort("name") + m.Sort(kit.MDB_NAME) }}, - "total": {Name: "total name=auto auto", Help: "提交统计", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + TOTAL: {Name: "total name=auto auto", Help: "提交统计", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) > 0 { // 提交详情 - m.Richs("repos", nil, arg[0], func(key string, value map[string]interface{}) { + m.Richs(REPOS, nil, arg[0], func(key string, value map[string]interface{}) { m.Cmdy("_sum", kit.Value(value, "meta.path"), arg[1:]) }) return @@ -132,8 +109,8 @@ var Index = &ice.Context{Name: "git", Help: "代码库", days := 0 commit, adds, dels, rest := 0, 0, 0, 0 wg := &sync.WaitGroup{} - m.Richs("repos", nil, "*", func(key string, value map[string]interface{}) { - if m.Conf("total", kit.Keys("meta.skip", kit.Value(value, "meta.name"))) == "true" { + m.Richs(REPOS, nil, kit.MDB_FOREACH, func(key string, value map[string]interface{}) { + if m.Conf(TOTAL, kit.Keys("meta.skip", kit.Value(value, "meta.name"))) == "true" { return } wg.Add(1) @@ -161,52 +138,10 @@ var Index = &ice.Context{Name: "git", Help: "代码库", m.Push("rest", rest) m.Sort("rest", "int_r") }}, - "status": {Name: "status name=auto auto", Help: "文件状态", Meta: kit.Dict( - "detail", []interface{}{"add", "reset", "remove", kit.Dict("name", "commit", "args", kit.List( - kit.MDB_INPUT, "select", "name", "type", "values", []string{"add", "opt"}, - kit.MDB_INPUT, "text", "name", "name", "value", "some", - ))}, - ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - prefix := []string{cli.SYSTEM, "git"} - - if len(arg) > 1 && arg[0] == "action" { - m.Richs("repos", nil, m.Option("name"), func(key string, value map[string]interface{}) { - m.Option("cmd_dir", kit.Value(value, "meta.path")) - switch arg[1] { - case "add": - m.Cmdy(prefix, arg[1], m.Option("file")) - case "reset": - m.Cmdy(prefix, arg[1], m.Option("file")) - case "checkout": - m.Cmdy(prefix, arg[1], m.Option("file")) - case "commit": - m.Cmdy(prefix, arg[1], "-m", m.Option("comment")) - } - }) - return - } - - m.Richs("repos", nil, kit.Select("*", arg, 0), func(key string, value map[string]interface{}) { - if m.Option("cmd_dir", kit.Value(value, "meta.path")); len(arg) > 0 { - // 更改详情 - m.Echo(m.Cmdx(prefix, "diff")) - return - } - - // 更改列表 - for _, v := range strings.Split(strings.TrimSpace(m.Cmdx(prefix, "status", "-sb")), "\n") { - vs := strings.SplitN(strings.TrimSpace(v), " ", 2) - m.Push("name", kit.Value(value, "meta.name")) - m.Push("tags", vs[0]) - m.Push("file", vs[1]) - } - }) - }}, - "_sum": {Name: "_sum [path] [total] [count|date] args...", Help: "统计", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) > 0 { if s, e := os.Stat(arg[0] + "/.git"); e == nil && s.IsDir() { - m.Option("cmd_dir", arg[0]) + m.Option(cli.CMD_DIR, arg[0]) arg = arg[1:] } } @@ -278,42 +213,42 @@ var Index = &ice.Context{Name: "git", Help: "代码库", m.Push("rest", count_add-count_del) } }}, - - "trend": {Name: "trend name=auto begin_time=@date auto", Help: "趋势图", Meta: kit.Dict( + TREND: {Name: "trend name=auto begin_time=@date auto", Help: "趋势图", Meta: kit.Dict( "display", "/plugin/story/trend.js", ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) == 0 { m.Option("_display", "table") } - m.Cmdy("total", arg) + m.Cmdy(TOTAL, arg) }}, - - "spide": {Name: "spide path=auto file=auto auto", Help: "结构图", Meta: kit.Dict( + SPIDE: {Name: "spide path=auto file=auto auto", Help: "结构图", Meta: kit.Dict( "display", "/plugin/story/spide.js", ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - if len(arg) > 0 && arg[0] == "inner" { - arg[1] = path.Join("usr", arg[1]) - m.Cmdy("web.code.inner", arg[1:]) - return - } - if len(arg) == 0 { + // 仓库列表 m.Option("_display", "table") - m.Cmdy("total", arg) + m.Cmdy(TOTAL, arg) return } if len(arg) == 1 { + // 目录列表 m.Option(nfs.DIR_DEEP, "true") m.Cmdy(nfs.DIR, mdb.RENDER, nfs.DIR, "", path.Join("usr", arg[0])) return } + if len(arg) > 1 && arg[0] == "inner" { + // 代码详情 + arg[1] = path.Join("usr", arg[1]) + m.Cmdy("web.code.inner", arg[1:]) + return + } + tags := "" m.Option(cli.CMD_DIR, path.Join("usr", arg[0])) if strings.HasSuffix(arg[1], ".go") { tags = m.Cmdx(cli.SYSTEM, "gotags", arg[1]) for _, line := range strings.Split(tags, "\n") { - m.Debug("line: %v", line) if len(line) == 0 || strings.HasPrefix(line, "!_") { continue } @@ -353,9 +288,71 @@ var Index = &ice.Context{Name: "git", Help: "代码库", m.Push("line", "1") } } - m.Sort("line", "int") }}, + + "status": {Name: "status name=auto auto 提交:button", Help: "文件状态", Meta: kit.Dict( + "提交", kit.List("_input", "text", "name", "text"), + ), Action: map[string]*ice.Action{ + "submit": {Name: "submit", Help: "提交", Hand: func(m *ice.Message, arg ...string) { + m.Cmdy(cli.SYSTEM, "commit", "-am", arg[0]) + }}, + }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + prefix := []string{cli.SYSTEM, "git"} + if len(arg) > 1 && arg[0] == "action" { + m.Richs("repos", nil, m.Option("name"), func(key string, value map[string]interface{}) { + m.Option("cmd_dir", kit.Value(value, "meta.path")) + switch arg[1] { + case "add": + m.Cmdy(prefix, arg[1], m.Option("file")) + case "reset": + m.Cmdy(prefix, arg[1], m.Option("file")) + case "checkout": + m.Cmdy(prefix, arg[1], m.Option("file")) + case "commit": + m.Cmdy(prefix, arg[1], "-m", m.Option("comment")) + } + }) + return + } + + m.Richs("repos", nil, kit.Select("*", arg, 0), func(key string, value map[string]interface{}) { + if m.Option("cmd_dir", kit.Value(value, "meta.path")); len(arg) > 0 { + // 更改详情 + m.Echo(m.Cmdx(prefix, "diff")) + return + } + + // 更改列表 + for _, v := range strings.Split(strings.TrimSpace(m.Cmdx(prefix, "status", "-sb")), "\n") { + vs := strings.SplitN(strings.TrimSpace(v), " ", 2) + m.Push("name", kit.Value(value, "meta.name")) + m.Push("tags", vs[0]) + m.Push("file", vs[1]) + } + }) + }}, + + code.INSTALL: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + m.Option("cmd_dir", m.Conf("install", "meta.path")) + m.Cmd(cli.SYSTEM, "git", "clone", m.Conf("git", "meta.source")) + + m.Option("cmd_dir", path.Join(m.Conf("install", "meta.path"), "git")) + m.Cmd(cli.SYSTEM, "make", "configure") + m.Cmd(cli.SYSTEM, "./configure", "--prefix="+kit.Path("usr/local")) + + m.Cmd(cli.SYSTEM, "make", "-j4") + m.Cmd(cli.SYSTEM, "make", "install") + }}, + code.PREPARE: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + kit.Fetch(m.Confv("git", "meta.config"), func(conf string, value interface{}) { + kit.Fetch(value, func(key string, value string) { + m.Cmd(cli.SYSTEM, "git", "config", "--global", conf+"."+key, value) + }) + }) + }}, + code.PROJECT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + }}, }, } diff --git a/misc/git/git.shy b/misc/git/git.shy index 043de52b..ae6baf43 100644 --- a/misc/git/git.shy +++ b/misc/git/git.shy @@ -7,5 +7,11 @@ refer "官网" ` ` chapter "应用" +field "代码统计" web.code.git.total +field "提交趋势" web.code.git.trend args icebergs +field "代码结构" web.code.git.spide args icebergs + field status web.code.git.status -field total web.code.git.total + +chapter "项目" +field icebergs web.code.inner args `[ usr/icebergs misc/git/git.go ]`