forked from x/ContextOS
mac mod 删除对etc&var目录的依赖
This commit is contained in:
parent
c386ce1f80
commit
bcf246c9a9
33
etc/init.shy
33
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"
|
||||
|
@ -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,8 +226,10 @@ 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 {
|
||||
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") { // {{{
|
||||
|
@ -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,13 +1466,14 @@ 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 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 ""
|
||||
// }
|
||||
}
|
||||
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")) {
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user