From a92d298f120604484dc0191076f571129830a36e Mon Sep 17 00:00:00 2001 From: shylinux Date: Mon, 24 Aug 2020 23:04:47 +0800 Subject: [PATCH] add get.pull --- core/chat/action.go | 1 - misc/git/git.go | 29 ++++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/core/chat/action.go b/core/chat/action.go index 9706bc06..cd7c28b4 100644 --- a/core/chat/action.go +++ b/core/chat/action.go @@ -146,7 +146,6 @@ func _action_show(m *ice.Message, river, storm, index string, arg ...string) { return } - m.Debug("what %v", cmds) if p := m.Option(POD); p != "" { if len(cmds) > 1 && cmds[1] == "action" { switch cmds[2] { diff --git a/misc/git/git.go b/misc/git/git.go index f53abe7e..078f065a 100644 --- a/misc/git/git.go +++ b/misc/git/git.go @@ -55,6 +55,7 @@ var Index = &ice.Context{Name: GIT, Help: "代码库", "wubi-dict", "true", "word-dict", "true", ), )}, + "progress": {Name: "progress", Help: "进度", Value: kit.Data()}, }, Commands: map[string]*ice.Command{ ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { @@ -292,7 +293,7 @@ var Index = &ice.Context{Name: GIT, Help: "代码库", m.Sort("line", "int") }}, - "status": {Name: "status name=auto auto 提交:button", Help: "文件状态", Meta: kit.Dict( + "status": {Name: "status name=auto auto 提交:button 下载:button", Help: "文件状态", Meta: kit.Dict( "提交", kit.List( "_input", "select", "name", "action", "values", []string{"opt", "add"}, "_input", "text", "name", "text", "value", "some", @@ -327,6 +328,32 @@ var Index = &ice.Context{Name: GIT, Help: "代码库", } m.Cmdy(cli.SYSTEM, "git", "push") }}, + "pull": {Name: "pull", Help: "下载", Hand: func(m *ice.Message, arg ...string) { + if m.Richs("progress", "", m.Option("_progress"), func(key string, value map[string]interface{}) { + m.Push("count", value["count"]) + m.Push("total", value["total"]) + m.Push("name", value["name"]) + }) != nil { + return + } + + count, total := 0, len(m.Confm(REPOS, "hash")) + h := m.Rich("progress", "", kit.Dict("progress", 0, "count", count, "total", total)) + m.Gos(m, func(m *ice.Message) { + m.Richs(REPOS, nil, kit.Select(kit.MDB_FOREACH, arg, 0), func(key string, value map[string]interface{}) { + count++ + m.Conf("progress", kit.Keys("hash", h, "name"), kit.Value(value, "meta.name")) + m.Conf("progress", kit.Keys("hash", h, "count"), count) + m.Conf("progress", kit.Keys("hash", h, "progress"), count*100/total) + m.Option(cli.CMD_DIR, kit.Value(value, "meta.path")) + m.Echo(m.Cmdx(cli.SYSTEM, GIT, "pull")) + }) + }) + m.Option("_progress", h) + m.Push("count", count) + m.Push("total", total) + m.Push("name", "") + }}, }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Richs(REPOS, nil, kit.Select(kit.MDB_FOREACH, arg, 0), func(key string, value map[string]interface{}) { if m.Option(cli.CMD_DIR, kit.Value(value, "meta.path")); len(arg) > 0 {