From 66008f3a8a58cc9f05936df6c1b2377bd9af4d69 Mon Sep 17 00:00:00 2001 From: shaoying Date: Tue, 15 May 2018 15:28:09 +0800 Subject: [PATCH] mod cli.source to sync --- etc/init.shy | 11 ++++++----- src/contexts/cli/cli.go | 4 +++- src/contexts/ctx.go | 7 +++++++ src/contexts/mdb/mdb.go | 7 +------ src/contexts/nfs/nfs.go | 3 ++- src/contexts/web/web.go | 2 +- 6 files changed, 20 insertions(+), 14 deletions(-) diff --git a/etc/init.shy b/etc/init.shy index dba1dbaf..f35290f2 100644 --- a/etc/init.shy +++ b/etc/init.shy @@ -1,6 +1,7 @@ -source etc/local.shy -login root root -~ssh -#dial "shylinux.com:9090" - command add pwd _ +~aaa + login root root + +~ssh + config domain ctx + dial "shylinux.com:9090" diff --git a/src/contexts/cli/cli.go b/src/contexts/cli/cli.go index 47a85623..60bfa553 100644 --- a/src/contexts/cli/cli.go +++ b/src/contexts/cli/cli.go @@ -47,7 +47,8 @@ func (cli *CLI) Spawn(m *ctx.Message, c *ctx.Context, arg ...string) ctx.Server s.lex = cli.lex s.yac = cli.yac s.nfs = cli.nfs - s.target = cli.target + // s.target = cli.target + s.target = c return s } @@ -659,6 +660,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心", "source": &ctx.Command{Name: "source file", Help: "运行脚本, file: 脚本文件名", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) { if _, ok := m.Target().Server.(*CLI); m.Assert(ok) && !m.Caps("skip") { // {{{ m.Start(fmt.Sprintf("%s_%d_%s", key, m.Optioni("level", m.Capi("level")+1), arg[0]), "脚本文件", arg[0]) + <-m.Target().Exit } // }}} }}, "return": &ctx.Command{Name: "return result...", Help: "结束脚本, rusult: 返回值", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) { diff --git a/src/contexts/ctx.go b/src/contexts/ctx.go index cf723fd7..653a27e4 100644 --- a/src/contexts/ctx.go +++ b/src/contexts/ctx.go @@ -306,7 +306,9 @@ func (c *Context) Close(m *Message, arg ...string) bool { // {{{ delete(c.context.contexts, c.Name) c.context = nil if c.Exit != nil { + m.Log("info", nil, "before exit<-") c.Exit <- true + m.Log("info", nil, "after exit<-") } } return true @@ -1279,6 +1281,11 @@ func (m *Message) Start(name string, help string, arg ...string) bool { // {{{ return m.Set("detail", arg...).target.Spawn(m, name, help).Begin(m).Start(m) } +// }}} +func (m *Message) Starts(name string, help string, arg ...string) bool { // {{{ + return m.Set("detail", arg...).target.Spawn(m, name, help).Begin(m).Start(m) +} + // }}} func (m *Message) Exec(key string, arg ...string) string { // {{{ diff --git a/src/contexts/mdb/mdb.go b/src/contexts/mdb/mdb.go index fd47fd7b..1df4c0c2 100644 --- a/src/contexts/mdb/mdb.go +++ b/src/contexts/mdb/mdb.go @@ -55,11 +55,7 @@ func (mdb *MDB) Start(m *ctx.Message, arg ...string) bool { // {{{ if len(arg) > 0 { m.Cap("source", arg[0]) } - if len(arg) > 1 { - m.Cap("driver", arg[1]) - } else { - m.Cap("driver", Pulse.Conf("driver")) - } + m.Cap("driver", Pulse.Conf("driver")) if m.Cap("source") == "" || m.Cap("driver") == "" { return false } @@ -284,7 +280,6 @@ var Index = &ctx.Context{Name: "mdb", Help: "数据中心", 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) { diff --git a/src/contexts/nfs/nfs.go b/src/contexts/nfs/nfs.go index 0a6fce64..744c0181 100644 --- a/src/contexts/nfs/nfs.go +++ b/src/contexts/nfs/nfs.go @@ -556,7 +556,8 @@ func (nfs *NFS) Start(m *ctx.Message, arg ...string) bool { // {{{ } } - cli := m.Reply() + // cli := m.Reply() + cli := m.Sesss("cli") nfs.cli = cli yac := m.Sesss("yac", cli.Conf("yac")) bio := bufio.NewScanner(nfs) diff --git a/src/contexts/web/web.go b/src/contexts/web/web.go index 12e479cf..50791fbf 100644 --- a/src/contexts/web/web.go +++ b/src/contexts/web/web.go @@ -437,7 +437,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", part, e := writer.CreateFormFile(m.Option("file"), filepath.Base(m.Meta["file"][1])) m.Assert(e) - io.Copy(part, file) + n, e := io.Copy(part, file) for i := 0; i < len(arg)-1; i += 2 { writer.WriteField(arg[0], arg[1]) }