mirror of
https://shylinux.com/x/ContextOS
synced 2025-04-26 09:14:06 +08:00
add mdb.note
This commit is contained in:
parent
0597557c6b
commit
01da58e29d
@ -0,0 +1,2 @@
|
|||||||
|
~aaa
|
||||||
|
user root shaoying shaoying
|
@ -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]",
|
"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: 删除配置",
|
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) {
|
Hand: func(m *Message, c *Context, key string, arg ...string) (e error) {
|
||||||
if len(arg) > 2 && arg[2] == "list" {
|
if len(arg) > 2 && arg[2] == "list" {
|
||||||
chain := strings.Split(arg[1], ".")
|
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: "数据转换",
|
"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) {
|
Hand: func(m *Message, c *Context, key string, arg ...string) (e error) {
|
||||||
value, arg := m.Optionv(arg[0]), arg[1:]
|
value, arg := m.Optionv(arg[0]), arg[1:]
|
||||||
if v, ok := value.(string); ok {
|
if v, ok := value.(string); ok {
|
||||||
@ -1019,6 +1019,40 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{},
|
|||||||
|
|
||||||
switch val := value.(type) {
|
switch val := value.(type) {
|
||||||
case map[string]interface{}:
|
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 {
|
for k, v := range val {
|
||||||
if m.Option("format") == "object" {
|
if m.Option("format") == "object" {
|
||||||
m.Add("append", k, v)
|
m.Add("append", k, v)
|
||||||
|
@ -636,6 +636,59 @@ func (m *Message) Copy(msg *Message, arg ...string) *Message {
|
|||||||
|
|
||||||
return m
|
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 {
|
func (m *Message) Echo(str string, arg ...interface{}) *Message {
|
||||||
if len(arg) > 0 {
|
if len(arg) > 0 {
|
||||||
return m.Add("result", fmt.Sprintf(str, arg...))
|
return m.Add("result", fmt.Sprintf(str, arg...))
|
||||||
|
@ -68,6 +68,8 @@ var Index = &ctx.Context{Name: "mdb", Help: "数据中心",
|
|||||||
|
|
||||||
"temp": &ctx.Config{Name: "temp", Value: map[string]interface{}{}, Help: "缓存数据"},
|
"temp": &ctx.Config{Name: "temp", Value: map[string]interface{}{}, Help: "缓存数据"},
|
||||||
"temp_view": &ctx.Config{Name: "temp_view", 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{
|
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) {
|
"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])
|
m.Cmdy("show", arg[0], fields, "where", arg[1])
|
||||||
return
|
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
|
||||||
|
}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,11 +206,16 @@ func (nfs *NFS) Read(p []byte) (n int, err error) {
|
|||||||
case termbox.EventMouse:
|
case termbox.EventMouse:
|
||||||
switch ev.Key {
|
switch ev.Key {
|
||||||
case termbox.MouseLeft:
|
case termbox.MouseLeft:
|
||||||
nfs.Term(m, "window", ev.MouseX, ev.MouseY)
|
if m.Confs("term", "mouse.resize") {
|
||||||
nfs.prompt(what).shadow(rest)
|
nfs.Term(m, "window", ev.MouseX, ev.MouseY)
|
||||||
|
nfs.prompt(what).shadow(rest)
|
||||||
|
}
|
||||||
|
|
||||||
case termbox.MouseMiddle:
|
case termbox.MouseMiddle:
|
||||||
case termbox.MouseRight:
|
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.MouseRelease:
|
||||||
case termbox.MouseWheelUp:
|
case termbox.MouseWheelUp:
|
||||||
if scroll_count++; scroll_count > m.Confi("term", "scroll_count") {
|
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{
|
Configs: map[string]*ctx.Config{
|
||||||
"term": &ctx.Config{Name: "term", Value: map[string]interface{}{
|
"term": &ctx.Config{Name: "term", Value: map[string]interface{}{
|
||||||
|
"mouse": map[string]interface{}{
|
||||||
|
"resize": false,
|
||||||
|
},
|
||||||
"width": 80, "height": "24",
|
"width": 80, "height": "24",
|
||||||
|
|
||||||
"left": 0, "top": 0, "right": 80, "bottom": 24,
|
"left": 0, "top": 0, "right": 80, "bottom": 24,
|
||||||
|
@ -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) {
|
"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 {
|
if len(arg) == 0 {
|
||||||
m.Cmdy("ctx.config", "node")
|
m.Cmdy("ctx.config", "node", "format", "table")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,6 +105,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
|||||||
m.Confv("node", node.Append("node.name"), map[string]interface{}{
|
m.Confv("node", node.Append("node.name"), map[string]interface{}{
|
||||||
"module": m.Cap("stream", nfs.Format("target")),
|
"module": m.Cap("stream", nfs.Format("target")),
|
||||||
"create_time": m.Time(),
|
"create_time": m.Time(),
|
||||||
|
"type": "master",
|
||||||
"node": map[string]interface{}{
|
"node": map[string]interface{}{
|
||||||
"name": node.Append("node.name"),
|
"name": node.Append("node.name"),
|
||||||
"type": "master",
|
"type": "master",
|
||||||
@ -166,6 +167,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
|||||||
m.Confv("node", name, map[string]interface{}{
|
m.Confv("node", name, map[string]interface{}{
|
||||||
"module": m.Format("source"),
|
"module": m.Format("source"),
|
||||||
"create_time": m.Time(),
|
"create_time": m.Time(),
|
||||||
|
"type": arg[3],
|
||||||
"node": map[string]interface{}{
|
"node": map[string]interface{}{
|
||||||
"name": name,
|
"name": name,
|
||||||
"type": arg[3],
|
"type": arg[3],
|
||||||
@ -479,6 +481,25 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
|||||||
m.Echo(m.Conf("current"))
|
m.Echo(m.Conf("current"))
|
||||||
return
|
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" {
|
if arg[0] == "node" {
|
||||||
m.Conf("current", arg[1])
|
m.Conf("current", arg[1])
|
||||||
@ -549,6 +570,12 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
|||||||
}
|
}
|
||||||
return
|
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
|
||||||
|
}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,6 +172,9 @@ func (tcp *TCP) Start(m *ctx.Message, arg ...string) bool {
|
|||||||
m.Cmd("tcp.ifconfig").Table(func(line map[string]string) {
|
m.Cmd("tcp.ifconfig").Table(func(line map[string]string) {
|
||||||
ports = append(ports, fmt.Sprintf("%s:%s", line["ip"], addr[len(addr)-1]))
|
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))
|
m.Back(m.Spawn(m.Source()).Put("option", "node.port", ports))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,7 +182,6 @@ func Formats(arg ...interface{}) string {
|
|||||||
}
|
}
|
||||||
return strings.Join(result, " ")
|
return strings.Join(result, " ")
|
||||||
}
|
}
|
||||||
|
|
||||||
func Trans(arg ...interface{}) []string {
|
func Trans(arg ...interface{}) []string {
|
||||||
ls := []string{}
|
ls := []string{}
|
||||||
for _, v := range arg {
|
for _, v := range arg {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user