From f0faba149da28b8d27a645c1ce991d99a6ca2e68 Mon Sep 17 00:00:00 2001 From: shaoying Date: Tue, 26 Feb 2019 11:10:41 +0800 Subject: [PATCH] opt cli.runtime Change-Id: I5c8c1de4b9db7e367add756eade23d9530c0a98a --- etc/dotsfile/.tmux.conf | 8 ++++---- etc/dotsfile/shy.vim | 4 ++++ src/contexts/cli/cli.go | 22 ++++++++++++---------- src/contexts/ctx/ctx_init.go | 2 +- src/contexts/nfs/nfs.go | 6 +++--- src/contexts/ssh/ssh.go | 14 +++++++------- src/contexts/web/web.go | 6 +++--- src/examples/code/code.go | 2 +- 8 files changed, 35 insertions(+), 29 deletions(-) diff --git a/etc/dotsfile/.tmux.conf b/etc/dotsfile/.tmux.conf index c890bddc..0222230b 100644 --- a/etc/dotsfile/.tmux.conf +++ b/etc/dotsfile/.tmux.conf @@ -42,12 +42,12 @@ bind i display-panes bind x confirm-before -p "kill-pane #P? (y/n)" kill-pane bind b break-pane -bind u split-window -bind v split-window -h +# bind u split-window +# bind v split-window -h +bind u split-window -c "#{pane_current_path}" +bind v split-window -h -c "#{pane_current_path}" bind C-u split-window -f bind C-v split-window -f -h -# bind u split-window -c "#{pane_current_path}" -# bind v split-window -h -c "#{pane_current_path}" # bind C-u split-window -f -c "#{pane_current_path}" # bind C-v split-window -f -h -c "#{pane_current_path}" diff --git a/etc/dotsfile/shy.vim b/etc/dotsfile/shy.vim index ae769fbe..017e4c0a 100644 --- a/etc/dotsfile/shy.vim +++ b/etc/dotsfile/shy.vim @@ -4,6 +4,8 @@ syntax match shyCommand "\(^\|\t\| \|$(\)[a-zA-Z0-9_\.]\+\>" syntax match shyConfig "\(^\|\t\| \|$(\)config\>" syntax match shyCache "\(^\|\t\| \|$(\)cache\>" +syntax match shyStmt "return" + syntax match shyString "'[^']*'" syntax match shyString "\"[^\"]*\"" syntax match shyNumber "-\=\<\d\+\>#\=" @@ -27,6 +29,8 @@ highlight shyCommand ctermfg=green highlight shyConfig ctermfg=yellow highlight shyCache ctermfg=yellow +highlight shyStmt ctermfg=yellow + highlight shyString ctermfg=magenta highlight shyNumber ctermfg=magenta highlight shyVariable ctermfg=magenta diff --git a/src/contexts/cli/cli.go b/src/contexts/cli/cli.go index 11c0fc72..fb876d61 100644 --- a/src/contexts/cli/cli.go +++ b/src/contexts/cli/cli.go @@ -100,9 +100,11 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心", Configs: map[string]*ctx.Config{ "runtime": &ctx.Config{Name: "runtime", Value: map[string]interface{}{ "init_env": []interface{}{"ctx_dev", "ctx_box", "ctx_root", "ctx_home", "USER"}, - "script": map[string]interface{}{"sh": "bash", "shy": "source", "py": "python"}, - "init_shy": "etc/init.shy", "exit_shy": "etc/exit.shy", - "web_port": ":9094", "ssh_port": ":9090", "ssh_ports": []interface{}{}, + "boot": map[string]interface{}{"web_port": ":9094", "ssh_port": ":9090"}, + "script": map[string]interface{}{ + "sh": "bash", "shy": "source", "py": "python", + "init": "etc/init.shy", "exit": "etc/exit.shy", + }, }, Help: "运行环境"}, "alias": &ctx.Config{Name: "alias", Value: map[string]interface{}{ @@ -136,19 +138,19 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心", }, Commands: map[string]*ctx.Command{ "init": &ctx.Command{Name: "init", Help: "停止服务", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { - m.Conf("runtime", "GOARCH", runtime.GOARCH) - m.Conf("runtime", "GOOS", runtime.GOOS) - m.Conf("runtime", "pid", os.Getpid()) + m.Conf("runtime", "host.GOARCH", runtime.GOARCH) + m.Conf("runtime", "host.GOOS", runtime.GOOS) + m.Conf("runtime", "host.pid", os.Getpid()) if name, e := os.Hostname(); e == nil { - m.Conf("runtime", "hostname", name) + m.Conf("runtime", "boot.hostname", name) } if name, e := os.Getwd(); e == nil { _, file := path.Split(name) - m.Conf("runtime", "pathname", file) + m.Conf("runtime", "boot.pathname", file) } m.Confm("runtime", "init_env", func(index int, key string) { - m.Conf("runtime", key, os.Getenv(key)) + m.Conf("runtime", "boot."+key, os.Getenv(key)) }) return }}, @@ -313,7 +315,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心", return }}, "exit": &ctx.Command{Name: "exit code", Help: "停止服务", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { - m.Cmd("cli.source", m.Conf("exit_shy")) + m.Cmd("cli.source", m.Conf("runtime", "script.exit")) go func() { time.Sleep(time.Second * 3) os.Exit(kit.Int(arg[0])) diff --git a/src/contexts/ctx/ctx_init.go b/src/contexts/ctx/ctx_init.go index 368abcee..527cfa56 100644 --- a/src/contexts/ctx/ctx_init.go +++ b/src/contexts/ctx/ctx_init.go @@ -41,7 +41,7 @@ func (ctx *CTX) Start(m *Message, arg ...string) bool { m.Cmd("ctx.init") if m.Optionv("ps_target", Index); len(arg) == 0 { m.Cap("stream", "shy") - m.Cmd("cli.source", m.Conf("runtime", "init_shy")).Cmd("cli.source", "stdio").Cmd("cli.source", m.Conf("runtime", "exit_shy")) + m.Cmd("cli.source", m.Conf("runtime", "script.init")).Cmd("cli.source", "stdio").Cmd("cli.source", m.Conf("runtime", "script.exit")) } else { m.Cmd("cli.source", arg) } diff --git a/src/contexts/nfs/nfs.go b/src/contexts/nfs/nfs.go index c17e0ae1..4cd1bfe4 100644 --- a/src/contexts/nfs/nfs.go +++ b/src/contexts/nfs/nfs.go @@ -917,7 +917,7 @@ func (nfs *NFS) Start(m *ctx.Message, arg ...string) bool { msg := m.Backs(m.Spawn(m.Source()).Set( "detail", line).Set( "option", "file_pos", i).Set( - "option", "username", m.Conf("runtime", "USER"))) + "option", "username", m.Conf("runtime", "boot.USER"))) nfs.printf(m.Conf("prompt"), line) nfs.printf(msg.Meta["result"]) @@ -1132,8 +1132,8 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心", }, Commands: map[string]*ctx.Command{ "init": &ctx.Command{Name: "init", Help: "", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { - m.Conf("paths", -2, m.Conf("runtime", "ctx_home")) - m.Conf("paths", -2, m.Conf("runtime", "ctx_root")) + m.Conf("paths", -2, m.Conf("runtime", "boot.ctx_home")) + m.Conf("paths", -2, m.Conf("runtime", "boot.ctx_root")) return }}, "pwd": &ctx.Command{Name: "pwd [all] | [[index] path] ", Help: "工作目录,all: 查看所有, index path: 设置路径, path: 设置当前路径", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { diff --git a/src/contexts/ssh/ssh.go b/src/contexts/ssh/ssh.go index d14a94e3..a8c4690e 100644 --- a/src/contexts/ssh/ssh.go +++ b/src/contexts/ssh/ssh.go @@ -44,15 +44,15 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心", }, Commands: map[string]*ctx.Command{ "init": &ctx.Command{Name: "init", Help: "启动", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { - if m.Confs("runtime", "ctx_box") { + if m.Confs("runtime", "boot.ctx_box") { m.Conf("runtime", "node.type", "worker") - m.Conf("runtime", "node.name", m.Conf("runtime", "pathname")) + m.Conf("runtime", "node.name", m.Conf("runtime", "boot.pathname")) } else { m.Conf("runtime", "node.type", "server") - m.Conf("runtime", "node.name", strings.Replace(strings.TrimSuffix(m.Conf("runtime", "hostname"), ".local"), ".", "_", -1)) + m.Conf("runtime", "node.name", strings.Replace(strings.TrimSuffix(m.Conf("runtime", "boot.hostname"), ".local"), ".", "_", -1)) } m.Conf("runtime", "node.route", m.Conf("runtime", "node.name")) - m.Conf("runtime", "user.name", m.Conf("runtime", "USER")) + m.Conf("runtime", "user.name", m.Conf("runtime", "boot.USER")) return }}, "remote": &ctx.Command{Name: "remote auto|dial|listen args...", Help: "远程连接", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { @@ -70,9 +70,9 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心", switch arg[0] { case "auto": // 自动连接 - if m.Cmd("ssh.remote", "dial", "consul", "/shadow"); !m.Confs("runtime", "ctx_box") { - m.Cmd("ssh.remote", "listen", m.Conf("runtime", "ssh_port")) - m.Cmd("web.serve", "usr", m.Conf("runtime", "web_port")) + if m.Cmd("ssh.remote", "dial", "consul", "/shadow"); !m.Confs("runtime", "boot.ctx_box") { + m.Cmd("ssh.remote", "listen", m.Conf("runtime", "boot.ssh_port")) + m.Cmd("web.serve", "usr", m.Conf("runtime", "boot.web_port")) } case "listen": // 监听连接 diff --git a/src/contexts/web/web.go b/src/contexts/web/web.go index 4c954916..eab47307 100644 --- a/src/contexts/web/web.go +++ b/src/contexts/web/web.go @@ -144,8 +144,8 @@ func (web *WEB) HandleCmd(m *ctx.Message, key string, cmd *ctx.Command) { msg.Option("path", r.URL.Path) msg.Optionv("debug", false) - msg.Option("GOOS", m.Conf("runtime", "GOOS")) - msg.Option("GOOS", m.Conf("runtime", "GOARCH")) + msg.Option("GOOS", m.Conf("runtime", "host.GOOS")) + msg.Option("GOOS", m.Conf("runtime", "host.GOARCH")) agent := r.Header.Get("User-Agent") switch { case strings.Contains(agent, "Macintosh"): @@ -398,7 +398,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", }, Commands: map[string]*ctx.Command{ "init": &ctx.Command{Name: "init", Help: "post请求", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { - m.Cmd("web.spide", "dev", "client", "new", kit.Select(m.Conf("runtime", "ctx_dev"), m.Conf("runtime", "ctx_box"))) + m.Cmd("web.spide", "dev", "client", "new", kit.Select(m.Conf("runtime", "boot.ctx_dev"), m.Conf("runtime", "boot.ctx_box"))) return }}, "spide": &ctx.Command{Name: "spide [which [client|cookie [name [value]]]]", Help: "爬虫配置", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { diff --git a/src/examples/code/code.go b/src/examples/code/code.go index 135de3ef..3aad29ee 100644 --- a/src/examples/code/code.go +++ b/src/examples/code/code.go @@ -278,7 +278,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心", m.Assert(e) } if m.Cmd("web.get", "dev", fmt.Sprintf("code/upgrade/%s", link), - "GOOS", m.Conf("runtime", "GOOS"), "GOARCH", m.Conf("runtime", "GOARCH"), + "GOOS", m.Conf("runtime", "host.GOOS"), "GOARCH", m.Conf("runtime", "host.GOARCH"), "save", file); strings.HasPrefix(file, "bin/") { if m.Cmd("cli.system", "chmod", "u+x", file); link == "bench" { m.Cmd("cli.system", "mv", "bin/bench", fmt.Sprintf("bin/bench_%s", m.Time("20060102_150405")))