From bcf246c9a96efbd9f260edec1810b9a5ae56ad78 Mon Sep 17 00:00:00 2001 From: shaoying Date: Sun, 18 Mar 2018 21:39:24 +0800 Subject: [PATCH] =?UTF-8?q?mac=20mod=20=E5=88=A0=E9=99=A4=E5=AF=B9etc&var?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=E7=9A=84=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- etc/init.shy | 33 --------------------------------- src/context/cli/cli.go | 11 +++++++---- src/context/ctx.go | 19 ++++++++++++------- src/context/nfs/nfs.go | 2 +- 4 files changed, 20 insertions(+), 45 deletions(-) diff --git a/etc/init.shy b/etc/init.shy index 211b5aea..4967c424 100644 --- a/etc/init.shy +++ b/etc/init.shy @@ -1,34 +1 @@ ~aaa login root root - -function plus - var a = 1 - for $a < 10 - ~stdio print $a - let a = $a + 1 - end -end -~yac check -~lex check -~nfs listen ":9494" - -return - if 2 < 1 - let a = 1 +2 - if 3 = 3 - let a = 2 +4 - end - elif 3 > 4 - let a = 1 +6 - else - let a = 2 +2 - end - - for $a < 10 - var b = 1 - for $b < 4 - let b = $b+1 - end - let a = $a + 1 - end -return $a + "hello\n context & message word\ - nice" diff --git a/src/context/cli/cli.go b/src/context/cli/cli.go index 144690e5..905b604c 100644 --- a/src/context/cli/cli.go +++ b/src/context/cli/cli.go @@ -86,7 +86,7 @@ func (cli *CLI) Begin(m *ctx.Message, arg ...string) ctx.Server { // }}} }} cli.Configs["yac"] = &ctx.Config{Name: "词法解析器", Value: "", Help: "命令行词法解析器", Hand: func(m *ctx.Message, x *ctx.Config, arg ...string) string { - if len(arg) > 0 && len(arg[0]) > 0 { + if len(arg) > 0 && len(arg[0]) > 0 { // {{{ cli, ok := m.Target().Server.(*CLI) m.Assert(ok, "模块类型错误") @@ -132,7 +132,7 @@ func (cli *CLI) Begin(m *ctx.Message, arg ...string) ctx.Server { return arg[0] } return x.Value - + // }}} }} cli.Configs["PS1"] = &ctx.Config{Name: "命令行提示符(target/detail)", Value: "target", Help: "命令行提示符,target:显示当前模块,detail:显示详细信息", Hand: func(m *ctx.Message, x *ctx.Config, arg ...string) string { if len(arg) > 0 { // {{{ @@ -226,7 +226,9 @@ func (cli *CLI) Start(m *ctx.Message, arg ...string) bool { if cli.nfs = m.Find("nfs"); m.Has("stdio") { cli.nfs.Cmd("scan", m.Cap("stream", "stdio"), m.Cmd("source", m.Cap("init.shy")).Get("result")) } else { - cli.nfs.Cmd("scan", m.Cap("stream", m.Cap("init.shy"))) + if _, e := os.Stat(m.Cap("init.shy")); e == nil { + cli.nfs.Cmd("scan", m.Cap("stream", m.Cap("init.shy"))) + } } }() } @@ -509,7 +511,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心", } // }}} }}, "cmd": &ctx.Command{Name: "cmd word", Help: "", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) { - if cli, ok := m.Target().Server.(*CLI); m.Assert(ok) && !m.Caps("skip") { + if cli, ok := m.Target().Server.(*CLI); m.Assert(ok) && !m.Caps("skip") { // {{{ msg := m.Spawn(cli.target) if a, ok := cli.alias[arg[0]]; ok { msg.Set("detail", a...) @@ -555,6 +557,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心", } else { m.Set("result", arg...) } + // }}} }}, "var": &ctx.Command{Name: "var a [= exp]", Help: "定义变量, a: 变量名, exp: 表达式", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) { if _, ok := m.Target().Server.(*CLI); m.Assert(ok) && !m.Caps("skip") { // {{{ diff --git a/src/context/ctx.go b/src/context/ctx.go index cb0df356..d81902fa 100644 --- a/src/context/ctx.go +++ b/src/context/ctx.go @@ -510,6 +510,10 @@ func (m *Message) Target(s ...*Context) *Context { // {{{ var i = 0 func (m *Message) Log(action string, ctx *Context, str string, arg ...interface{}) { // {{{ + if !m.Confs("bench.log") { + return + } + if !m.Options("log") { return } @@ -1462,12 +1466,13 @@ var Index = &Context{Name: "ctx", Help: "模块中心", "init.shy": &Config{Name: "启动脚本", Value: "etc/init.shy", Help: "模块启动时自动运行的脚本"}, "bench.log": &Config{Name: "日志文件", Value: "var/bench.log", Help: "模块日志输出的文件", Hand: func(m *Message, x *Config, arg ...string) string { if len(arg) > 0 { // {{{ - if e := os.MkdirAll(path.Dir(arg[0]), os.ModePerm); e == nil { - if l, e := os.Create(x.Value); e == nil { - log.SetOutput(l) - } + // if e := os.MkdirAll(path.Dir(arg[0]), os.ModePerm); e == nil { + if l, e := os.Create(x.Value); e == nil { + log.SetOutput(l) + return arg[0] } - return arg[0] + return "" + // } } return x.Value // }}} @@ -2014,7 +2019,7 @@ func Start(args ...string) { Pulse.Options("log", true) - log.Println("\n\n") + // log.Println("\n\n") Index.Group = "root" Index.Owner = Index.contexts["aaa"] Index.master = Index.contexts["cli"] @@ -2022,7 +2027,7 @@ func Start(args ...string) { m.target.root = Index m.target.Begin(m) } - log.Println() + // log.Println() Pulse.Sess("log", "log").Conf("bench.log", "var/bench.log") for _, m := range Pulse.Search(Pulse.Conf("start")) { diff --git a/src/context/nfs/nfs.go b/src/context/nfs/nfs.go index 1947b7f6..91e73156 100644 --- a/src/context/nfs/nfs.go +++ b/src/context/nfs/nfs.go @@ -411,7 +411,7 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心", m.Put("option", "io", m.Data["io"]) m.Start(fmt.Sprintf("file%d", Pulse.Capi("nfile", 1)), "打开文件", m.Meta["detail"]...) m.Echo(m.Target().Name) - } else if f, e := os.OpenFile(arg[0], os.O_RDWR|os.O_CREATE, os.ModePerm); m.Assert(e) { + } else if f, e := os.OpenFile(arg[0], os.O_RDWR|os.O_CREATE, os.ModePerm); e == nil { m.Put("option", "in", f).Put("option", "out", f) m.Start(fmt.Sprintf("file%d", Pulse.Capi("nfile", 1)), "打开文件", m.Meta["detail"]...) m.Echo(m.Target().Name)