From 85db6fb81765b5dc89bf44a2ebb90881dc1b31d7 Mon Sep 17 00:00:00 2001 From: shaoying Date: Sun, 1 Jul 2018 19:15:04 +0800 Subject: [PATCH] mac pro some --- etc/shy.vim | 9 ++++++-- src/contexts/cli/cli.go | 46 +++++++++++++++++------------------------ src/contexts/ctx.go | 4 ++-- src/contexts/web/web.go | 26 +++-------------------- 4 files changed, 31 insertions(+), 54 deletions(-) diff --git a/etc/shy.vim b/etc/shy.vim index cf16dc7f..8ea7d3dc 100644 --- a/etc/shy.vim +++ b/etc/shy.vim @@ -13,8 +13,13 @@ syn keyword shStatement break cd chdir continue eval exec exit kill newgrp pwd r syn keyword shStatement source return function syn keyword shStatement if else elif end for syn keyword shStatement let var -syn keyword shStatement cache -syn keyword shStatement config + +syn match shStatement "\(^\|\t\|$(\)cache" +syn match shStatement "\(^\|\t\|$(\)config" +syn match shStatement "\(^\|\t\|$(\)detail" +syn match shStatement "\(^\|\t\|$(\)option" +syn match shStatement "\(^\|\t\|$(\)append" +syn match shStatement "\(^\|\t\|$(\)result" syn keyword shCommand command syn keyword shCommand open diff --git a/src/contexts/cli/cli.go b/src/contexts/cli/cli.go index cd2b2b25..3d8f0364 100644 --- a/src/contexts/cli/cli.go +++ b/src/contexts/cli/cli.go @@ -270,6 +270,8 @@ func (cli *CLI) Close(m *ctx.Message, arg ...string) bool { // {{{ if _, ok := m.Source().Server.(*CLI); ok { // p.target = cli.target } + msg := m.Sesss("nfs") + msg.Target().Close(msg) case m.Source(): if m.Name == "aaa" { if !cli.Context.Close(m.Spawn(cli.Context), arg...) { @@ -285,13 +287,13 @@ func (cli *CLI) Close(m *ctx.Message, arg ...string) bool { // {{{ var Pulse *ctx.Message var Index = &ctx.Context{Name: "cli", Help: "管理中心", - Caches: map[string]*ctx.Cache{}, - Configs: map[string]*ctx.Config{ - "time": &ctx.Config{Name: "time", Value: "0", Help: "所有模块的当前目录", Hand: func(m *ctx.Message, x *ctx.Config, arg ...string) string { + Caches: map[string]*ctx.Cache{ + "time": &ctx.Cache{Name: "time", Value: "0", Help: "所有模块的当前目录", Hand: func(m *ctx.Message, x *ctx.Cache, arg ...string) string { t := time.Now().Unix() return fmt.Sprintf("%d", t) }}, }, + Configs: map[string]*ctx.Config{}, Commands: map[string]*ctx.Command{ "alias": &ctx.Command{Name: "alias [short [long]]|[delete short]", Help: "查看、定义或删除命令别名, short: 命令别名, long: 命令原名, delete: 删除别名", 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") { // {{{ @@ -322,30 +324,26 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心", } } // }}} }}, - "time": &ctx.Command{Name: "time [parse when] format when", + "time": &ctx.Command{Name: "time [parse when] when", Form: map[string]int{"parse": 1}, Help: "睡眠, time(ns/us/ms/s/m/h): 时间值(纳秒/微秒/毫秒/秒/分钟/小时)", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) { t := time.Now() // {{{ + f := "2006-01-02 15:04:05" + if len(arg) > 0 { + if i, e := strconv.Atoi(arg[0]); e == nil { + t = time.Unix(int64(i), 0) + } + } if m.Options("parse") { - f := "2006-01-02 15:04:05" n, e := time.ParseInLocation(f, m.Option("parse"), time.Local) m.Assert(e) t = n } - f := "" - if len(arg) > 0 { - n, e := strconv.Atoi(arg[0]) - m.Assert(e) - t = time.Unix(int64(n), 0) - f = "2006-01-02 15:04:05" - } - - if f == "" { - m.Echo("%d", t.Unix()) - } else { - m.Echo(t.Format(f)) - } // }}} + m.Echo("%d", t.Unix()) + m.Echo(" ") + m.Echo(t.Format(f)) + // }}} }}, "express": &ctx.Command{Name: "express exp", Help: "表达式运算", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) { result := "false" // {{{ @@ -569,19 +567,13 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心", case "@": m.Echo(msg.Conf(arg[1])) } - case 4: - switch arg[0] { - case "$": - m.Echo(arg[2]) - case "@": - m.Echo(arg[2]) - } default: + last := len(arg) - 1 switch arg[0] { case "$": - m.Result(0, "cache", arg[1:]) + m.Result(0, arg[2:last]) case "@": - m.Result(0, "config", arg[1:]) + m.Result(0, arg[2:last]) } } } else { diff --git a/src/contexts/ctx.go b/src/contexts/ctx.go index 6e0ef921..a3f5e55e 100644 --- a/src/contexts/ctx.go +++ b/src/contexts/ctx.go @@ -2434,7 +2434,7 @@ var Index = &Context{Name: "ctx", Help: "模块中心", // }}} }}, - "detail": &Command{Name: "detail [index]", Help: "查看或添加参数", Hand: func(m *Message, c *Context, key string, arg ...string) { + "detail": &Command{Name: "detail [index [value...]]", Help: "查看或添加参数", Hand: func(m *Message, c *Context, key string, arg ...string) { msg := m.Sesss("cli", false) // {{{ switch len(arg) { case 0: @@ -2475,7 +2475,7 @@ var Index = &Context{Name: "ctx", Help: "模块中心", case 0: m.Echo("%v\n", msg.Meta["result"]) default: - msg.Set("result", arg...) + msg.Result(-2, arg) } // }}} }}, "append": &Command{Name: "append [key [value...]]", Help: "查看或添加附加值", Hand: func(m *Message, c *Context, key string, arg ...string) { diff --git a/src/contexts/web/web.go b/src/contexts/web/web.go index 5fa2ff6d..b04d3c00 100644 --- a/src/contexts/web/web.go +++ b/src/contexts/web/web.go @@ -17,7 +17,6 @@ import ( // {{{ "mime/multipart" "path/filepath" - "bufio" "fmt" "io" "os" @@ -200,7 +199,6 @@ func (web *WEB) Spawn(m *ctx.Message, c *ctx.Context, arg ...string) ctx.Server // }}} func (web *WEB) Begin(m *ctx.Message, arg ...string) ctx.Server { // {{{ - m.Sesss("cli", "cli") web.Context.Master(nil) web.Caches["route"] = &ctx.Cache{Name: "请求路径", Value: "/" + web.Context.Name + "/", Help: "请求路径"} web.Caches["register"] = &ctx.Cache{Name: "已初始化(yes/no)", Value: "no", Help: "模块是否已初始化"} @@ -277,7 +275,7 @@ func (web *WEB) Start(m *ctx.Message, arg ...string) bool { // {{{ m.Log("info", nil, "protocol [%s]", m.Cap("protocol")) web.Server = &http.Server{Addr: m.Cap("address"), Handler: web} - web.Configs["logheaders"] = &ctx.Config{Name: "日志输出报文头(yes/no)", Value: "yes", Help: "日志输出报文头"} + web.Configs["logheaders"] = &ctx.Config{Name: "日志输出报文头(yes/no)", Value: "no", Help: "日志输出报文头"} m.Capi("nserve", 1) if web.Message = m; m.Cap("protocol") == "https" { @@ -524,27 +522,9 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", } }) case "script": - cli := m.Find("cli") - lex := m.Find("lex") mux.Trans(m, arg[1], func(m *ctx.Message, c *ctx.Context, key string, a ...string) { - f, e := os.Open(arg[2]) - line, bio := "", bufio.NewReader(f) - if e != nil { - line = arg[2] - } - - for { - if line = strings.TrimSpace(line); line != "" { - lex.Cmd("split", line, "void") - cli.Wait = make(chan bool) - cli.Cmd(lex.Meta["result"]) - m.Meta["result"] = cli.Meta["result"] - } - - if line, e = bio.ReadString('\n'); e != nil { - break - } - } + msg := m.Find("cli").Cmd("source", arg[2]) + m.Copy(msg, "result").Copy(msg, "append") }) } } // }}}