diff --git a/etc/common.shy b/etc/common.shy index e69de29b..ad7ecfd5 100644 --- a/etc/common.shy +++ b/etc/common.shy @@ -0,0 +1,2 @@ +~aaa + user root shaoying shaoying diff --git a/src/contexts/ctx/ctx_init.go b/src/contexts/ctx/ctx_init.go index 00bfca65..e0675769 100644 --- a/src/contexts/ctx/ctx_init.go +++ b/src/contexts/ctx/ctx_init.go @@ -798,7 +798,7 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{}, }}, "config": &Command{Name: "config [all] [export key..] [save|load file key...] [list|map arg...] [create map|list|string key name help] [delete key]", Help: "配置管理, export: 导出配置, save: 保存配置到文件, load: 从文件加载配置, create: 创建配置, delete: 删除配置", - Form: map[string]int{"format": 1}, + Form: map[string]int{"format": 1, "fields": -1}, Hand: func(m *Message, c *Context, key string, arg ...string) (e error) { if len(arg) > 2 && arg[2] == "list" { chain := strings.Split(arg[1], ".") @@ -962,7 +962,7 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{}, }}, "trans": &Command{Name: "trans option [type|data|json] limit 10 [index...]", Help: "数据转换", - Form: map[string]int{"format": 1}, + Form: map[string]int{"format": 1, "fields": -1}, Hand: func(m *Message, c *Context, key string, arg ...string) (e error) { value, arg := m.Optionv(arg[0]), arg[1:] if v, ok := value.(string); ok { @@ -1019,6 +1019,40 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{}, switch val := value.(type) { case map[string]interface{}: + if m.Option("format") == "table" { + fields := []string{} + has := map[string]bool{} + if m.Options("fields") { + fields = m.Optionv("fields").([]string) + } else { + for _, v := range val { + if line, ok := v.(map[string]interface{}); ok { + for k, _ := range line { + if h, ok := has[k]; ok && h { + continue + } + has[k], fields = true, append(fields, k) + } + } + } + sort.Strings(fields) + } + + m.Log("fuck", "what %v", fields) + m.Log("fuck", "what %v", m.Meta) + for k, v := range val { + if line, ok := v.(map[string]interface{}); ok { + m.Add("append", "key", k) + for _, field := range fields { + m.Add("append", field, kit.Format(line[field])) + } + } + } + m.Log("fuck", "what %v", m.Meta) + m.Table() + break + } + for k, v := range val { if m.Option("format") == "object" { m.Add("append", k, v) diff --git a/src/contexts/ctx/ctx_type.go b/src/contexts/ctx/ctx_type.go index df675dbd..a107d307 100644 --- a/src/contexts/ctx/ctx_type.go +++ b/src/contexts/ctx/ctx_type.go @@ -636,6 +636,59 @@ func (m *Message) Copy(msg *Message, arg ...string) *Message { return m } +func (m *Message) CopyFuck(msg *Message, arg ...string) *Message { + if m == msg { + return m + } + + for i := 0; i < len(arg); i++ { + meta := arg[i] + + switch meta { + case "target": + m.target = msg.target + case "callback": + m.callback = msg.callback + case "detail", "result": + if len(msg.Meta[meta]) > 0 { + m.Add(meta, msg.Meta[meta][0], msg.Meta[meta][1:]) + } + case "option", "append": + if msg.Meta == nil { + msg.Meta = map[string][]string{} + } + if msg.Meta[meta] == nil { + break + } + if i == len(arg)-1 { + arg = append(arg, msg.Meta[meta]...) + } + + for i++; i < len(arg); i++ { + if v, ok := msg.Data[arg[i]]; ok { + m.Put(meta, arg[i], v) + } else if v, ok := msg.Meta[arg[i]]; ok { + m.Add(meta, arg[i], v) // TODO fuck Add + } + } + default: + if msg.Hand { + meta = "append" + } else { + meta = "option" + } + + if v, ok := msg.Data[arg[i]]; ok { + m.Put(meta, arg[i], v) + } + if v, ok := msg.Meta[arg[i]]; ok { + m.Add(meta, arg[i], v) + } + } + } + + return m +} func (m *Message) Echo(str string, arg ...interface{}) *Message { if len(arg) > 0 { return m.Add("result", fmt.Sprintf(str, arg...)) diff --git a/src/contexts/mdb/mdb.go b/src/contexts/mdb/mdb.go index 4a244957..5f6df739 100644 --- a/src/contexts/mdb/mdb.go +++ b/src/contexts/mdb/mdb.go @@ -68,6 +68,8 @@ var Index = &ctx.Context{Name: "mdb", Help: "数据中心", "temp": &ctx.Config{Name: "temp", Value: map[string]interface{}{}, Help: "缓存数据"}, "temp_view": &ctx.Config{Name: "temp_view", Value: map[string]interface{}{}, Help: "缓存数据"}, + + "note": &ctx.Config{Name: "note", Value: map[string]interface{}{}, Help: "缓存数据"}, }, Commands: map[string]*ctx.Command{ "temp": &ctx.Command{Name: "temp [type [meta [data]]] [tid [node|ship|data] [chain... [select ...]]]", Form: map[string]int{"select": -1, "limit": 1}, Help: "缓存数据", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { @@ -466,6 +468,36 @@ var Index = &ctx.Context{Name: "mdb", Help: "数据中心", m.Cmdy("show", arg[0], fields, "where", arg[1]) return }}, + + "note": &ctx.Command{Name: "note [meta data]....", Help: "记事", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { + sync := len(arg) > 0 && arg[0] == "sync" + if sync { + m.Cmdy("ssh.sh", "sub", "context", "mdb", "note", arg) + m.Set("result").Table() + arg = arg[1:] + } + + if len(arg) == 0 { + msg := m.Cmd("mdb.config", "note", "format", "table", "fields", "create_time", "type", "title") + m.CopyFuck(msg, "append") + m.Set("result").Table() + return + } + + h, _ := kit.Hash("uniq") + data := map[string]interface{}{ + "create_time": m.Time(), + "type": arg[0], + "title": arg[1], + "content": arg[2], + } + for i := 3; i < len(arg)-1; i += 2 { + kit.Chain(data, data[arg[i]], arg[i+1]) + } + m.Conf("note", h, data) + m.Echo(h) + return + }}, }, } diff --git a/src/contexts/nfs/nfs.go b/src/contexts/nfs/nfs.go index 1878a688..c17e0ae1 100644 --- a/src/contexts/nfs/nfs.go +++ b/src/contexts/nfs/nfs.go @@ -206,11 +206,16 @@ func (nfs *NFS) Read(p []byte) (n int, err error) { case termbox.EventMouse: switch ev.Key { case termbox.MouseLeft: - nfs.Term(m, "window", ev.MouseX, ev.MouseY) - nfs.prompt(what).shadow(rest) + if m.Confs("term", "mouse.resize") { + nfs.Term(m, "window", ev.MouseX, ev.MouseY) + nfs.prompt(what).shadow(rest) + } + case termbox.MouseMiddle: case termbox.MouseRight: - nfs.Term(m, "resize", ev.MouseX, ev.MouseY) + if m.Confs("term", "mouse.resize") { + nfs.Term(m, "resize", ev.MouseX, ev.MouseY) + } case termbox.MouseRelease: case termbox.MouseWheelUp: if scroll_count++; scroll_count > m.Confi("term", "scroll_count") { @@ -1034,6 +1039,9 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心", }, Configs: map[string]*ctx.Config{ "term": &ctx.Config{Name: "term", Value: map[string]interface{}{ + "mouse": map[string]interface{}{ + "resize": false, + }, "width": 80, "height": "24", "left": 0, "top": 0, "right": 80, "bottom": 24, diff --git a/src/contexts/ssh/ssh.go b/src/contexts/ssh/ssh.go index a39989f5..d14a94e3 100644 --- a/src/contexts/ssh/ssh.go +++ b/src/contexts/ssh/ssh.go @@ -57,7 +57,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心", }}, "remote": &ctx.Command{Name: "remote auto|dial|listen args...", Help: "远程连接", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { if len(arg) == 0 { - m.Cmdy("ctx.config", "node") + m.Cmdy("ctx.config", "node", "format", "table") return } @@ -105,6 +105,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心", m.Confv("node", node.Append("node.name"), map[string]interface{}{ "module": m.Cap("stream", nfs.Format("target")), "create_time": m.Time(), + "type": "master", "node": map[string]interface{}{ "name": node.Append("node.name"), "type": "master", @@ -166,6 +167,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心", m.Confv("node", name, map[string]interface{}{ "module": m.Format("source"), "create_time": m.Time(), + "type": arg[3], "node": map[string]interface{}{ "name": name, "type": arg[3], @@ -479,6 +481,25 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心", m.Echo(m.Conf("current")) return } + if arg[0] == "sub" { + m.Confm("node", func(name string, node map[string]interface{}) { + if node["type"] == "master" { + return + } + msg := m.Cmd("ssh.remote", name, arg[1:]) + if len(msg.Meta["append"]) > 0 && !msg.Has("node") { + line := len(msg.Meta[msg.Meta["append"][0]]) + for i := 0; i < line; i++ { + msg.Add("append", "node", m.Conf("runtime", "node.route")+"."+name) + } + msg.Set("result").Table() + } + m.CopyFuck(msg, "append") + m.CopyFuck(msg, "result") + return + }) + return + } if arg[0] == "node" { m.Conf("current", arg[1]) @@ -549,6 +570,12 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心", } return }}, + "sync": &ctx.Command{Name: "sync", Help: "同步数据", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { + m.Confm("node", func(name string, node map[string]string) { + + }) + return + }}, }, } diff --git a/src/contexts/tcp/tcp.go b/src/contexts/tcp/tcp.go index 6ea9d887..d3870362 100644 --- a/src/contexts/tcp/tcp.go +++ b/src/contexts/tcp/tcp.go @@ -172,6 +172,9 @@ func (tcp *TCP) Start(m *ctx.Message, arg ...string) bool { m.Cmd("tcp.ifconfig").Table(func(line map[string]string) { ports = append(ports, fmt.Sprintf("%s:%s", line["ip"], addr[len(addr)-1])) }) + if len(ports) == 0 { + ports = append(ports, fmt.Sprintf("%s:%s", "127.0.0.1", addr[len(addr)-1])) + } m.Back(m.Spawn(m.Source()).Put("option", "node.port", ports)) } diff --git a/src/toolkit/kit.go b/src/toolkit/kit.go index c0c9884e..126deff6 100644 --- a/src/toolkit/kit.go +++ b/src/toolkit/kit.go @@ -182,7 +182,6 @@ func Formats(arg ...interface{}) string { } return strings.Join(result, " ") } - func Trans(arg ...interface{}) []string { ls := []string{} for _, v := range arg {