1
0
forked from x/ContextOS
This commit is contained in:
shaoying 2018-05-20 22:16:46 +08:00
parent 4d422f8efb
commit c8a272d2e3
3 changed files with 36 additions and 21 deletions

View File

@ -4,4 +4,7 @@
~ssh ~ssh
config domain tce config domain tce
dial "shylinux.com:9090" dial "shylinux.com:9090"
~nfs
command add git status
command add git branch

View File

@ -47,8 +47,10 @@ func (cli *CLI) Spawn(m *ctx.Message, c *ctx.Context, arg ...string) ctx.Server
s.lex = cli.lex s.lex = cli.lex
s.yac = cli.yac s.yac = cli.yac
s.nfs = cli.nfs s.nfs = cli.nfs
// s.target = cli.target s.target = cli.target
s.target = c if len(arg) > 0 {
s.target = c
}
return s 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", "num", "num", "mul{", "[1-9][0-9]*", "0[0-9]+", "0x[0-9]+", "}")
yac.Cmd("train", "str", "str", "mul{", "\"[^\"]*\"", "'[^']*'", "}") 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", "word", "word", "mul{", "~", "!", "tran", "str", "[a-zA-Z0-9_/.:]+", "}")
yac.Cmd("train", "op1", "op1", "mul{", "$", "@", "}") 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) { "time": &ctx.Command{Name: "time [parse format when] format when",
t := time.Now() // {{{ Formats: map[string]int{"parse": 2},
if len(arg) > 1 { Help: "睡眠, time(ns/us/ms/s/m/h): 时间值(纳秒/微秒/毫秒/秒/分钟/小时)", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
n, e := strconv.Atoi(arg[1]) t := time.Now() // {{{
m.Assert(e) if m.Options("parse") {
t = time.Unix(int64(n), 0) f := "2006-01-02 15:04:05"
} n, e := time.Parse(f, m.Option("parse"))
m.Assert(e)
t = n
}
f := "" if len(arg) > 1 {
if len(arg) > 0 { n, e := strconv.Atoi(arg[1])
f = arg[0] m.Assert(e)
} t = time.Unix(int64(n), 0)
}
if f == "" { f := ""
m.Echo("%d", t.Unix()) if len(arg) > 0 {
} else { f = arg[0]
m.Echo(t.Format(f)) }
} // }}}
}}, 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) { "express": &ctx.Command{Name: "express exp", Help: "表达式运算", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
result := "false" // {{{ result := "false" // {{{
switch len(arg) { switch len(arg) {

View File

@ -948,13 +948,14 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
m.Echo(wd) // }}} m.Echo(wd) // }}}
}}, }},
"git": &ctx.Command{Name: "git", Help: "写入文件, string: 写入内容, pos: 写入位置", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) { "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 { if out, e := cmd.CombinedOutput(); e != nil {
m.Echo("error: ") m.Echo("error: ")
m.Echo("%s\n", e) m.Echo("%s\n", e)
} else { } else {
m.Echo(string(out)) m.Echo(string(out))
} }
// }}}
}}, }},
}, },
Index: map[string]*ctx.Context{ Index: map[string]*ctx.Context{