mirror of
https://shylinux.com/x/ContextOS
synced 2025-04-25 16:58:06 +08:00
tce add ctx.command:add
This commit is contained in:
parent
0f871899af
commit
4fe29a255e
@ -1,5 +1,6 @@
|
||||
source etc/local.shy
|
||||
login root root
|
||||
~ssh
|
||||
dial "shylinux.com:9090"
|
||||
#dial "shylinux.com:9090"
|
||||
command add pwd _
|
||||
|
||||
|
@ -1836,8 +1836,8 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
|
||||
}
|
||||
// }}}
|
||||
}},
|
||||
"context": &Command{Name: "context back|[[home] [find|search] name] [info|list|show|switch|[args]", Help: "查找并操作模块,\n查找起点root:根模块、back:父模块、home:本模块,\n查找方法find:路径匹配、search:模糊匹配,\n查找对象name:支持点分和正则,\n操作类型show:显示信息、switch:切换为当前、start:启动模块、spawn:分裂子模块,args:启动参数",
|
||||
Formats: map[string]int{"back": 0, "home": 0, "find": 1, "search": 1, "info": 1, "list": 0, "show": 0, "switch": 0},
|
||||
"context": &Command{Name: "context back|[[home] [find|search] name] [info|lists|show|switch|[args]", Help: "查找并操作模块,\n查找起点root:根模块、back:父模块、home:本模块,\n查找方法find:路径匹配、search:模糊匹配,\n查找对象name:支持点分和正则,\n操作类型show:显示信息、switch:切换为当前、start:启动模块、spawn:分裂子模块,args:启动参数",
|
||||
Formats: map[string]int{"back": 0, "home": 0, "find": 1, "search": 1, "info": 1, "lists": 0, "show": 0, "switch": 0},
|
||||
Hand: func(m *Message, c *Context, key string, arg ...string) {
|
||||
if m.Has("back") { // {{{
|
||||
m.target = m.source
|
||||
@ -1911,7 +1911,7 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
|
||||
default:
|
||||
m.Echo("%s(%s): %s\n", v.target.Name, v.target.Owner.Name, v.target.Help)
|
||||
}
|
||||
case m.Has("list") || len(m.Meta["detail"]) == 1:
|
||||
case m.Has("lists") || len(m.Meta["detail"]) == 1:
|
||||
m.Travel(v.target, func(msg *Message) bool {
|
||||
target := msg.target
|
||||
m.Echo("%s(", target.Name)
|
||||
@ -1989,13 +1989,11 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
|
||||
}
|
||||
// }}}
|
||||
}},
|
||||
"command": &Command{Name: "command [all] [key [name help]]", Help: "查看或修改命令",
|
||||
"command": &Command{Name: "command [all] add [key [name help]]", Help: "查看或修改命令",
|
||||
Formats: map[string]int{"all": 0, "delete": 0, "void": 0},
|
||||
Hand: func(m *Message, c *Context, key string, arg ...string) {
|
||||
all := m.Has("all") // {{{
|
||||
|
||||
switch len(arg) {
|
||||
case 0:
|
||||
if len(arg) == 0 {
|
||||
m.BackTrace(func(m *Message) bool {
|
||||
if all {
|
||||
m.Echo("%s comands:\n", m.target.Name)
|
||||
@ -2010,6 +2008,53 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
|
||||
}
|
||||
return all
|
||||
})
|
||||
return
|
||||
}
|
||||
switch arg[0] {
|
||||
case "add":
|
||||
if m.target.Caches == nil {
|
||||
m.target.Caches = map[string]*Cache{}
|
||||
}
|
||||
|
||||
if m.target.Commands == nil {
|
||||
m.target.Commands = map[string]*Command{}
|
||||
}
|
||||
|
||||
if _, ok := m.target.Caches["part"]; !ok {
|
||||
m.target.Caches["part"] = &Cache{Name: "part", Value: "0", Help: "part"}
|
||||
}
|
||||
m.target.Commands[m.Cap("part")] = &Command{
|
||||
Name: strings.Join(arg[1:], " "), Help: "part", Hand: func(m *Message, c *Context, key string, args ...string) {
|
||||
list := []string{}
|
||||
j := 0
|
||||
for i := 1; i < len(arg); i++ {
|
||||
if arg[i] == "_" && j < len(args) {
|
||||
list = append(list, args[j])
|
||||
j++
|
||||
continue
|
||||
}
|
||||
list = append(list, arg[i])
|
||||
}
|
||||
list = append(list, args[j:]...)
|
||||
|
||||
msg := m.Spawn(m.target).Cmd(list)
|
||||
m.Copy(msg, "result").Copy(msg, "append")
|
||||
},
|
||||
}
|
||||
m.Capi("part", 1)
|
||||
return
|
||||
case "list":
|
||||
for i := 0; i < m.Capi("part"); i++ {
|
||||
|
||||
if c, ok := m.target.Commands[fmt.Sprintf("%d", i)]; ok {
|
||||
m.Echo("%d: %s\n", i, c.Name)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch len(arg) {
|
||||
case 0:
|
||||
case 1:
|
||||
switch {
|
||||
case m.Has("delete"):
|
||||
|
@ -98,9 +98,13 @@ var Index = &ctx.Context{Name: "mdb", Help: "数据中心",
|
||||
"driver": &ctx.Config{Name: "数据库驱动(mysql)", Value: "mysql", Help: "数据库驱动"},
|
||||
},
|
||||
Commands: map[string]*ctx.Command{
|
||||
"open": &ctx.Command{Name: "open source [driver]", Help: "打开数据库", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||
"open": &ctx.Command{Name: "open source [name]", Help: "打开数据库", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||
m.Assert(len(arg) > 0, "缺少参数") // {{{
|
||||
m.Start(fmt.Sprintf("db%d", Pulse.Capi("nsource", 1)), "数据存储", arg...)
|
||||
name := fmt.Sprintf("db%d", Pulse.Capi("nsource", 1))
|
||||
if len(arg) > 1 {
|
||||
name = arg[1]
|
||||
}
|
||||
m.Start(name, "数据存储", arg...)
|
||||
Pulse.Cap("stream", Pulse.Cap("nsource"))
|
||||
m.Echo(m.Target().Name)
|
||||
// }}}
|
||||
@ -256,6 +260,31 @@ var Index = &ctx.Context{Name: "mdb", Help: "数据中心",
|
||||
return false
|
||||
})
|
||||
}},
|
||||
"show": &ctx.Command{Name: "show table field [where condition]", Help: "执行查询语句",
|
||||
Formats: map[string]int{"where": 1},
|
||||
Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||
msg := m.Spawn(m.Target())
|
||||
|
||||
fields := strings.Join(arg[1:], ",")
|
||||
condition := ""
|
||||
if m.Options("where") {
|
||||
condition = fmt.Sprintf("where %s", m.Option("where"))
|
||||
}
|
||||
|
||||
msg.Cmd("query", fmt.Sprintf("select %s from %s %s", fields, arg[0], condition))
|
||||
m.Echo("%s %s\n", arg[0], condition)
|
||||
for _, k := range msg.Meta["append"] {
|
||||
m.Echo("%s\t", k)
|
||||
}
|
||||
m.Echo("\n")
|
||||
for i := 0; i < len(msg.Meta[msg.Meta["append"][0]]); i++ {
|
||||
for _, k := range msg.Meta["append"] {
|
||||
m.Echo("%s\t", msg.Meta[k][i])
|
||||
}
|
||||
m.Echo("\n")
|
||||
}
|
||||
}},
|
||||
// }}}
|
||||
"list": &ctx.Command{Name: "list add table field [where condition]", Help: "执行查询语句",
|
||||
Formats: map[string]int{"where": 1},
|
||||
Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user