From c8a272d2e390853950d19eb7631babcdddfe6c10 Mon Sep 17 00:00:00 2001 From: shaoying Date: Sun, 20 May 2018 22:16:46 +0800 Subject: [PATCH] ... --- etc/init.shy | 3 +++ src/contexts/cli/cli.go | 51 +++++++++++++++++++++++++---------------- src/contexts/nfs/nfs.go | 3 ++- 3 files changed, 36 insertions(+), 21 deletions(-) diff --git a/etc/init.shy b/etc/init.shy index e7343d81..16b28a44 100644 --- a/etc/init.shy +++ b/etc/init.shy @@ -4,4 +4,7 @@ ~ssh config domain tce dial "shylinux.com:9090" +~nfs + command add git status + command add git branch diff --git a/src/contexts/cli/cli.go b/src/contexts/cli/cli.go index 60bfa553..c5616054 100644 --- a/src/contexts/cli/cli.go +++ b/src/contexts/cli/cli.go @@ -47,8 +47,10 @@ 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 = c + s.target = cli.target + if len(arg) > 0 { + s.target = c + } return s } @@ -103,7 +105,7 @@ func (cli *CLI) Begin(m *ctx.Message, arg ...string) ctx.Server { // {{{ yac.Cmd("train", "num", "num", "mul{", "[1-9][0-9]*", "0[0-9]+", "0x[0-9]+", "}") yac.Cmd("train", "str", "str", "mul{", "\"[^\"]*\"", "'[^']*'", "}") - yac.Cmd("train", "tran", "tran", "mul{", "@", "$", "}", "opt{", "[a-zA-Z0-9]+", "}") + yac.Cmd("train", "tran", "tran", "mul{", "@", "$", "}", "opt{", "[a-zA-Z0-9_]+", "}") yac.Cmd("train", "word", "word", "mul{", "~", "!", "tran", "str", "[a-zA-Z0-9_/.:]+", "}") yac.Cmd("train", "op1", "op1", "mul{", "$", "@", "}") @@ -319,25 +321,34 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心", } } // }}} }}, - "time": &ctx.Command{Name: "time format when", Help: "睡眠, time(ns/us/ms/s/m/h): 时间值(纳秒/微秒/毫秒/秒/分钟/小时)", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) { - t := time.Now() // {{{ - if len(arg) > 1 { - n, e := strconv.Atoi(arg[1]) - m.Assert(e) - t = time.Unix(int64(n), 0) - } + "time": &ctx.Command{Name: "time [parse format when] format when", + Formats: map[string]int{"parse": 2}, + Help: "睡眠, time(ns/us/ms/s/m/h): 时间值(纳秒/微秒/毫秒/秒/分钟/小时)", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) { + t := time.Now() // {{{ + if m.Options("parse") { + f := "2006-01-02 15:04:05" + n, e := time.Parse(f, m.Option("parse")) + m.Assert(e) + t = n + } - f := "" - if len(arg) > 0 { - f = arg[0] - } + if len(arg) > 1 { + n, e := strconv.Atoi(arg[1]) + m.Assert(e) + t = time.Unix(int64(n), 0) + } - if f == "" { - m.Echo("%d", t.Unix()) - } else { - m.Echo(t.Format(f)) - } // }}} - }}, + f := "" + if len(arg) > 0 { + f = arg[0] + } + + if f == "" { + m.Echo("%d", t.Unix()) + } else { + 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" // {{{ switch len(arg) { diff --git a/src/contexts/nfs/nfs.go b/src/contexts/nfs/nfs.go index 577cd5aa..5a468407 100644 --- a/src/contexts/nfs/nfs.go +++ b/src/contexts/nfs/nfs.go @@ -948,13 +948,14 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心", m.Echo(wd) // }}} }}, "git": &ctx.Command{Name: "git", Help: "写入文件, string: 写入内容, pos: 写入位置", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) { - cmd := exec.Command("git", arg...) + cmd := exec.Command("git", arg...) // {{{ if out, e := cmd.CombinedOutput(); e != nil { m.Echo("error: ") m.Echo("%s\n", e) } else { m.Echo(string(out)) } + // }}} }}, }, Index: map[string]*ctx.Context{