diff --git a/base/ssh/ssh.go b/base/ssh/ssh.go index a621aa2e..71bc0411 100644 --- a/base/ssh/ssh.go +++ b/base/ssh/ssh.go @@ -56,6 +56,7 @@ func (f *Frame) parse(m *ice.Message, line string) *Frame { m.Log(ice.LOG_IMPORT, "stdin: %d %v", len(ls), ls) if len(ls) == 1 && ls[0] == "~" { + // 模块列表 ls = []string{"context"} } else if len(ls) > 0 && strings.HasPrefix(ls[0], "~") { // 切换模块 @@ -90,9 +91,32 @@ func (f *Frame) parse(m *ice.Message, line string) *Frame { } } - // 执行命令 + // 解析选项 + ln := []string{} msg := m.Spawns(f.target) - msg.Cmdy(ls[0], ls[1:]) + for i := 0; i < len(ls); i++ { + if ls[i] == "--" { + ln = append(ln, ls[i+1:]...) + break + } else if strings.HasPrefix(ls[i], "-") { + for j := i; j < len(ls); j++ { + if j == len(ls)-1 || strings.HasPrefix(ls[j+1], "-") { + if i == j { + msg.Option(ls[i][1:], "true") + } else { + msg.Option(ls[i][1:], ls[i+1:j+1]) + } + i = j + break + } + } + } else { + ln = append(ln, ls[i]) + } + } + + // 执行命令 + msg.Cmdy(ln[0], ln[1:]) // 转换结果 res := msg.Result() diff --git a/base/web/web.go b/base/web/web.go index 2d2c2c86..dcf635d9 100644 --- a/base/web/web.go +++ b/base/web/web.go @@ -708,18 +708,16 @@ var Index = &ice.Context{Name: "web", Help: "网络模块", }) fallthrough case "dev": - // 系统初始化 - m.Event(ice.SYSTEM_INIT) - fallthrough - case "self": - // 启动服务 - m.Target().Start(m, "self") - fallthrough - default: // 连接上游服务 m.Richs(ice.WEB_SPIDE, nil, "dev", func(key string, value map[string]interface{}) { m.Cmd(ice.WEB_SPACE, "connect", "dev") }) + fallthrough + default: + // 启动服务 + m.Target().Start(m, "self") + // 系统初始化 + m.Event(ice.SYSTEM_INIT) } }}, ice.WEB_SPACE: {Name: "space", Help: "空间站", Meta: kit.Dict("exports", []string{"pod", "name"}), List: kit.List( @@ -839,8 +837,10 @@ var Index = &ice.Context{Name: "web", Help: "网络模块", m.Target().Server().(*Frame).send[id] = m socket.WriteMessage(MSG_MAPS, []byte(m.Format("meta"))) t := time.AfterFunc(kit.Duration(m.Conf(ice.WEB_SPACE, "meta.timeout.c")), func() { - m.Log(ice.LOG_WARN, "timeout") - m.Back(nil) + m.TryCatch(m, true, func(m *ice.Message) { + m.Log(ice.LOG_WARN, "timeout") + m.Back(nil) + }) }) m.Call(true, func(msg *ice.Message) *ice.Message { // 返回结果 @@ -861,11 +861,11 @@ var Index = &ice.Context{Name: "web", Help: "网络模块", if len(arg) > 1 { switch arg[1] { case "启动": - arg = []string{arg[3]} + arg = []string{arg[4]} case "停止", "stop": - m.Cmd(ice.WEB_SPACE, kit.Select(m.Option("name"), arg, 3), "exit", "1") + m.Cmd(ice.WEB_SPACE, kit.Select(m.Option("name"), arg, 4), "exit", "1") time.Sleep(time.Second * 3) - m.Event(ice.DREAM_CLOSE, arg[3]) + m.Event(ice.DREAM_CLOSE, arg[4]) arg = arg[:0] } } diff --git a/core/chat/chat.go b/core/chat/chat.go index 08bc23db..10b7a3ca 100644 --- a/core/chat/chat.go +++ b/core/chat/chat.go @@ -41,7 +41,6 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心", []interface{}{"field", "command", "web.code.docker"}, []interface{}{"field", "repos", "web.code.git"}, []interface{}{"field", "total", "web.code.git"}, - []interface{}{"field", "branch", "web.code.git"}, []interface{}{"field", "status", "web.code.git"}, []interface{}{"storm", "root"}, diff --git a/core/code/code.go b/core/code/code.go index 1d17c0e4..4bda19cc 100644 --- a/core/code/code.go +++ b/core/code/code.go @@ -62,7 +62,7 @@ var Index = &ice.Context{Name: "code", Help: "编程中心", "compile": {Name: "compile", Help: "编译", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) == 0 { // 目录列表 - m.Cmdy("nfs.dir", "", m.Conf("publish", "meta.path"), "time size path") + m.Cmdy("nfs.dir", m.Conf("publish", "meta.path"), "time size path") return } diff --git a/core/team/team.go b/core/team/team.go index 56d20eae..49ae7711 100644 --- a/core/team/team.go +++ b/core/team/team.go @@ -344,31 +344,29 @@ var Index = &ice.Context{Name: "team", Help: "团队中心", // 本月日期 for day := one; day.Before(end); day = day.AddDate(0, 0, 1) { note := []string{ShowDay(m, day)} - m.Info("what %v", note) index := day.Format("2006-01-02") - if arg[0] == "month" { - for i, v := range list[index] { - b, _ := kit.Render(kit.Format(template, name[index][i]), v) - note = append(note, string(b)) - } - m.Push(head[int(day.Weekday())], strings.Join(note, "")) - continue - } - for _, v := range list[index] { - note = append(note, kit.Format(`%s: %s`, v["name"], v["text"])) + for i, v := range list[index] { + b, _ := kit.Render(kit.Format(template, name[index][i]), v) + note = append(note, string(b)) + // note = append(note, kit.Format(`%s: %s`, v["name"], v["text"])) } + if len(note) > 1 { - note[0] = kit.Format(`
%s%d
`, strings.Join(note[1:], "\n"), note[0], len(note)-1) + note[0] = kit.Format(`%s%d`, note[0], len(note)-1) } else { - note[0] = kit.Format(`%s%s`, note[0], "") + note[0] = kit.Format(`%s%s`, note[0], "") + } + + if arg[0] == "month" { + m.Push(head[int(day.Weekday())], strings.Join(note, "")) + } else { + m.Push(head[int(day.Weekday())], note[0]) } - m.Push(head[int(day.Weekday())], note[0]) } // 下月开头 tail := end.AddDate(0, 0, 6-int(end.Weekday())+1) for day := end; end.Weekday() != 0 && day.Before(tail); day = day.AddDate(0, 0, 1) { - m.Info("what %v", day) m.Push(head[int(day.Weekday())], ShowDay(m, day)) } diff --git a/core/wiki/wiki.go b/core/wiki/wiki.go index fb1b9bf7..55a771b6 100644 --- a/core/wiki/wiki.go +++ b/core/wiki/wiki.go @@ -56,6 +56,7 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心", ), )), )}, + "order": {Name: "order", Help: "列表", Value: kit.Data("template", order)}, "table": {Name: "table", Help: "表格", Value: kit.Data("template", table)}, "stack": {Name: "stack", Help: "结构", Value: kit.Data("template", stack)}, @@ -237,7 +238,7 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心", m.Option("output", output) m.Render(m.Conf(cmd, "meta.template")) }}, - "field": {Name: "field name text", Help: "列表", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + "field": {Name: "field name text", Help: "插件", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Option(kit.MDB_TYPE, cmd) m.Option(kit.MDB_NAME, arg[0]) m.Option(kit.MDB_TEXT, arg[1]) @@ -260,6 +261,7 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心", m.Option("meta", data) m.Render(m.Conf(cmd, "meta.template")) }}, + "order": {Name: "order name text", Help: "列表", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Option(kit.MDB_TYPE, cmd) m.Option(kit.MDB_NAME, arg[0]) @@ -383,7 +385,7 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心", reply(m, cmd, arg...) }}, "data": {Name: "data", Help: "数据表格", Meta: kit.Dict("remote", "pod", "display", "wiki/data"), List: kit.List( - kit.MDB_INPUT, "text", "name", "path", + kit.MDB_INPUT, "text", "name", "path", "action", "auto", kit.MDB_INPUT, "button", "name", "执行", "action", "auto", kit.MDB_INPUT, "button", "name", "返回", "cb", "Last", ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { @@ -546,21 +548,10 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心", // 输入补全 switch arg[2] { case "type": - m.Push("type", []string{"spark", "label", "refer", "brief", "chapter", "section", "title"}) + m.Push("type", []string{"spark", "order", "table", "label", "chain", "refer", "brief", "chapter", "section", "title"}) case "path": m.Option("_refresh", "true") - // 文件列表 - m.Option("dir_root", m.Conf("word", "meta.path")) - m.Option("dir_reg", m.Conf("word", "meta.regs")) - m.Cmdy("nfs.dir", kit.Select("./", arg, 3), "path") - m.Sort("time", "time_r") - if len(arg) == 3 || strings.HasSuffix(arg[3], "/") { - // 目录列表 - m.Option("dir_reg", "") - m.Option("dir_type", "dir") - m.Cmdy("nfs.dir", kit.Select("./", arg, 3), "path") - return - } + reply(m, "word", arg[3:]...) } return } @@ -570,8 +561,8 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心", m.Cmdy("word", arg) return } - m.Cmd("word", "action", "追加", arg) + m.Option("scan_mode", "scan") m.Cmdy("ssh.scan", "some", "some", path.Join(m.Conf("word", "meta.path"), arg[0])) }}, diff --git a/misc/git/git.go b/misc/git/git.go index 566205b6..2985ab82 100644 --- a/misc/git/git.go +++ b/misc/git/git.go @@ -11,86 +11,69 @@ import ( "time" ) +func add(m *ice.Message, n string, p string) { + if s, e := os.Stat(m.Option("cmd_dir", path.Join(p, ".git"))); e == nil && s.IsDir() { + ls := strings.SplitN(strings.Trim(m.Cmdx(ice.CLI_SYSTEM, "git", "log", "-n1", `--pretty=format:"%ad %s"`, "--date=iso"), "\""), " ", 4) + m.Rich("repos", nil, kit.Data( + "name", n, "path", p, + "last", ls[3], "time", strings.Join(ls[:2], " "), + "branch", strings.TrimSpace(m.Cmdx(ice.CLI_SYSTEM, "git", "branch")), + "remote", strings.TrimSpace(m.Cmdx(ice.CLI_SYSTEM, "git", "remote", "-v")), + )) + } +} + var Index = &ice.Context{Name: "git", Help: "代码库", Caches: map[string]*ice.Cache{}, Configs: map[string]*ice.Config{ "repos": {Name: "repos", Help: "仓库", Value: kit.Data(kit.MDB_SHORT, "name", "owner", "https://github.com/shylinux")}, + "total": {Name: "repos", Help: "仓库", Value: kit.Data(kit.MDB_SHORT, "name", "skip", kit.Dict("wubi-dict", "true"))}, }, Commands: map[string]*ice.Command{ ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { // 系统项目 wd, _ := os.Getwd() - if s, e := os.Stat(".git"); e == nil && s.IsDir() { - m.Rich("repos", nil, kit.Data( - "name", path.Base(wd), "path", wd, "branch", "master", - "remote", strings.TrimSpace(m.Cmdx(ice.CLI_SYSTEM, "git", "remote", "-v")), - )) - } + add(m, path.Base(wd), wd) // 官方项目 m.Cmd("nfs.dir", "usr", "name path").Table(func(index int, value map[string]string, head []string) { - if s, e := os.Stat(m.Option("cmd_dir", path.Join(value["path"], ".git"))); e == nil && s.IsDir() { - m.Rich("repos", nil, kit.Data( - "name", value["name"], "path", value["path"], "branch", "master", - "remote", strings.TrimSpace(m.Cmdx(ice.CLI_SYSTEM, "git", "remote", "-v")), - )) - } + add(m, value["name"], value["path"]) }) // 应用项目 m.Cmd("nfs.dir", m.Conf(ice.WEB_DREAM, "meta.path"), "name path").Table(func(index int, value map[string]string, head []string) { - if s, e := os.Stat(m.Option("cmd_dir", path.Join(value["path"], ".git"))); e == nil && s.IsDir() { - m.Rich("repos", nil, kit.Data( - "name", value["name"], "path", value["path"], "branch", "master", - "remote", strings.TrimSpace(m.Cmdx(ice.CLI_SYSTEM, "git", "remote", "-v")), - )) - } + add(m, value["name"], value["path"]) }) }}, ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}}, - "repos": {Name: "repos [name [path]]", Help: "仓库", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - if len(arg) > 0 { - m.Rich("repos", nil, kit.Data( - "name", arg[0], "path", kit.Select(path.Join("usr", arg[0]), arg, 1), "branch", "master", - "remote", kit.Select(m.Conf("repos", "meta.owner")+"/"+arg[0], arg, 2), - )) - } - m.Richs("repos", nil, "*", func(key string, value map[string]interface{}) { - m.Push(key, value["meta"], []string{"time", "name", "branch", "path", "remote"}) - }) - m.Sort("name") - }}, - "check": {Name: "check name [path [repos]]", Help: "检查", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + "repos": {Name: "repos [name [path [remote [branch]]]]", Help: "仓库", List: kit.List( + kit.MDB_INPUT, "text", "name", "name", "action", "auto", + kit.MDB_INPUT, "button", "name", "查看", "action", "auto", + kit.MDB_INPUT, "button", "name", "返回", "cb", "Last", + ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) > 1 { - m.Cmd("repos", arg) + if _, e := os.Stat(m.Option("cmd_dir", path.Join(arg[1], ".git"))); e != nil && os.IsNotExist(e) { + // 下载仓库 + m.Cmd(ice.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.Richs("repos", nil, arg[0], func(key string, value map[string]interface{}) { - if _, e := os.Stat(kit.Format(kit.Value(value, "meta.path"))); e != nil && os.IsNotExist(e) { - m.Cmd(ice.CLI_SYSTEM, "git", "clone", kit.Value(value, "meta.remote"), - "-b", kit.Value(value, "meta.branch"), kit.Value(value, "meta.path")) - } + if len(arg) > 0 { + // 仓库详情 + m.Richs("repos", nil, arg[0], func(key string, value map[string]interface{}) { + m.Push("detail", value["meta"]) + }) + return + } + + // 仓库列表 + m.Richs("repos", nil, "*", func(key string, value map[string]interface{}) { + m.Push(key, value["meta"], []string{"time", "name", "branch", "last"}) }) - }}, - "branch": {Name: "branch", Help: "分支", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - prefix := []string{ice.CLI_SYSTEM, "git", "branch"} - m.Richs("repos", nil, kit.Select("*", arg, 0), func(key string, value map[string]interface{}) { - m.Option("cmd_dir", kit.Value(value, "meta.path")) - for _, v := range strings.Split(m.Cmdx(prefix, "-v"), "\n") { - if len(v) > 0 { - m.Push("repos", kit.Value(value, "meta.name")) - m.Push("tags", v[:2]) - vs := strings.SplitN(strings.TrimSpace(v[2:]), " ", 2) - m.Push("branch", vs[0]) - m.Push("last", m.Cmdx(ice.CLI_SYSTEM, "git", "log", "-n", "1", "--pretty=%ad", "--date=short")) - vs = strings.SplitN(strings.TrimSpace(vs[1]), " ", 2) - m.Push("hash", vs[0]) - m.Push("note", strings.TrimSpace(vs[1])) - } - } - }) - m.Sort("repos") + m.Sort("name") }}, "status": {Name: "status repos", Help: "状态", Meta: kit.Dict( "detail", []interface{}{"add", "reset", "remove", kit.Dict("name", "commit", "args", kit.List( @@ -98,14 +81,14 @@ var Index = &ice.Context{Name: "git", Help: "代码库", kit.MDB_INPUT, "text", "name", "name", "value", "some", ))}, ), List: kit.List( - kit.MDB_INPUT, "text", "name", "repos", "action", "auto", + kit.MDB_INPUT, "text", "name", "name", "action", "auto", kit.MDB_INPUT, "button", "name", "查看", "action", "auto", - kit.MDB_INPUT, "button", "name", "返回", "cb", "Last", "action", "auto", + kit.MDB_INPUT, "button", "name", "返回", "cb", "Last", ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { prefix := []string{ice.CLI_SYSTEM, "git"} if len(arg) > 0 && arg[0] == "action" { - m.Richs("repos", nil, m.Option("repos"), func(key string, value map[string]interface{}) { + 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": @@ -123,34 +106,41 @@ var Index = &ice.Context{Name: "git", Help: "代码库", 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("repos", kit.Value(value, "meta.name")) + m.Push("name", kit.Value(value, "meta.name")) m.Push("tags", vs[0]) m.Push("file", vs[1]) } }) }}, "total": {Name: "total", Help: "统计", List: kit.List( - kit.MDB_INPUT, "text", "name", "repos", "action", "auto", + kit.MDB_INPUT, "text", "name", "name", "action", "auto", kit.MDB_INPUT, "button", "name", "查看", "action", "auto", kit.MDB_INPUT, "button", "name", "返回", "cb", "Last", ), 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.Cmdy("sum", kit.Value(value, "meta.path"), arg[1:]) }) return } + // 提交统计 days := 0 commit, adds, dels, rest := 0, 0, 0, 0 m.Richs("repos", nil, "*", func(key string, value map[string]interface{}) { - m.Push("repos", kit.Value(value, "meta.name")) + if m.Conf("total", kit.Keys("meta.skip", kit.Value(value, "meta.name"))) == "true" { + return + } + m.Push("name", kit.Value(value, "meta.name")) m.Copy(m.Cmd("sum", kit.Value(value, "meta.path"), "total", "10000").Table(func(index int, value map[string]string, head []string) { if kit.Int(value["days"]) > days { days = kit.Int(value["days"]) @@ -161,7 +151,7 @@ var Index = &ice.Context{Name: "git", Help: "代码库", rest += kit.Int(value["rest"]) })) }) - m.Push("repos", "total") + m.Push("name", "total") m.Push("days", days) m.Push("commit", commit) m.Push("adds", adds) @@ -258,6 +248,32 @@ var Index = &ice.Context{Name: "git", Help: "代码库", } m.Cmdy("total", arg) }}, + + "check": {Name: "check name [path [repos]]", Help: "检查", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + if len(arg) > 1 { + m.Cmd("repos", arg) + } + }}, + "branch": {Name: "branch", Help: "分支", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + prefix := []string{ice.CLI_SYSTEM, "git", "branch"} + m.Richs("repos", nil, kit.Select("*", arg, 0), func(key string, value map[string]interface{}) { + m.Option("cmd_dir", kit.Value(value, "meta.path")) + for _, v := range strings.Split(m.Cmdx(prefix, "-v"), "\n") { + if len(v) > 0 { + m.Push("time", m.Cmdx(ice.CLI_SYSTEM, "git", "log", "-n", "1", "--pretty=%ad", "--date=iso")) + m.Push("name", kit.Value(value, "meta.name")) + + m.Push("tags", v[:2]) + vs := strings.SplitN(strings.TrimSpace(v[2:]), " ", 2) + m.Push("branch", vs[0]) + vs = strings.SplitN(strings.TrimSpace(vs[1]), " ", 2) + m.Push("hash", vs[0]) + m.Push("last", strings.TrimSpace(vs[1])) + } + } + }) + m.Sort("repos") + }}, }, } diff --git a/type.go b/type.go index 3adc0bc4..096005dd 100644 --- a/type.go +++ b/type.go @@ -1167,7 +1167,9 @@ func (m *Message) Rich(key string, chain interface{}, data interface{}) string { // 通用数据 prefix := kit.Select("", "meta.", kit.Value(data, "meta") != nil) - kit.Value(data, prefix+kit.MDB_TIME, m.Time()) + if kit.Value(data, prefix+kit.MDB_TIME) == nil { + kit.Value(data, prefix+kit.MDB_TIME, m.Time()) + } // 生成键值 h := ""