From 2a0278790f88db657b54973edd67f3a3b6827785 Mon Sep 17 00:00:00 2001 From: shaoying Date: Tue, 18 Jun 2019 08:43:47 +0800 Subject: [PATCH] add cli.missyou --- src/contexts/cli/cli.go | 51 ++++--- src/contexts/ctx/init.go | 11 +- src/contexts/nfs/nfs.go | 6 +- src/contexts/ssh/ssh.go | 297 +++++++++++++++++++++++---------------- src/toolkit/kit.go | 3 + 5 files changed, 226 insertions(+), 142 deletions(-) diff --git a/src/contexts/cli/cli.go b/src/contexts/cli/cli.go index 9d2080e8..37aff460 100644 --- a/src/contexts/cli/cli.go +++ b/src/contexts/cli/cli.go @@ -178,6 +178,9 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心", "librarys_tar_gz": "usr/librarys.tar.gz", }, }, Help: "日志地址"}, + "missyou": &ctx.Config{Name: "missyou", Value: map[string]interface{}{ + "path": "usr/work", + }, Help: "免密登录"}, "plugin": &ctx.Config{Name: "plugin", Value: map[string]interface{}{ "go": map[string]interface{}{ @@ -545,19 +548,14 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心", []string{"stash", "pop"}, }) - list := [][]string{} - m.Confm("project", "import", func(index int, value string) { - list = append(list, []string{value}) - }) - - m.Cmdp(time.Second, []string{"go init"}, []string{"cli.system", "go", "get", - "cmd_env", "GOPATH", m.Conf("runtime", "boot.ctx_path")}, list) - case "import": list := [][]string{} m.Confm("project", "import", func(index int, value string) { list = append(list, []string{value}) + m.Add("append", "time", m.Time()) + m.Add("append", "package", value) }) + m.Table() m.Cmdp(time.Second, []string{"go init"}, []string{"cli.system", "go", "get", "cmd_env", "GOPATH", m.Conf("runtime", "boot.ctx_path")}, list) @@ -625,19 +623,23 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心", } for _, key := range arg { + key = kit.Key(key) value := m.Conf("publish", []string{"list", key}) p := m.Cmdx("nfs.path", value) + q := path.Join(dir, key) if s, e := os.Stat(p); e == nil { if s.IsDir() { - m.Cmd("cli.system", "tar", "-zcf", path.Join(dir, key), "-C", path.Dir(p), path.Base(value)) + m.Cmd("cli.system", "tar", "-zcf", q, "-C", path.Dir(p), path.Base(value)) } else { - m.Cmd("nfs.copy", path.Join(dir, key), p) + m.Cmd("nfs.copy", q, p) } + m.Add("append", "time", m.Time()) + m.Add("append", "file", q) + m.Add("append", "hash", kit.Hashs(p)) } } - + m.Table() // m.Cmdy("nfs.dir", dir, "dir_sort", "time", "time_r") - return }}, "upgrade": &ctx.Command{Name: "upgrade project|bench|system|portal|script", Help: "服务升级", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { @@ -688,6 +690,17 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心", } return }}, + "missyou": &ctx.Command{Name: "missyou", Help: "服务升级", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { + if len(arg) == 0 { + m.Option("dir_root", "") + m.Cmdy("nfs.dir", m.Conf("missyou", "path")) + return + } + + m.Cmdy("cli.system", "node.sh", "create", path.Join(m.Conf("missyou", "path"), m.Time("20060102-")+arg[0]), + "daemon", "cmd_daemon", "true") + return + }}, "quit": &ctx.Command{Name: "quit code", Help: "停止服务", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { code := kit.Select("0", arg, 0) switch code { @@ -704,12 +717,17 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心", m.Echo("restart") } } - m.Append("directory", "") - m.Echo(", wait 1s") + m.Append("time", m.Time()) + m.Append("code", code) + m.Echo(", wait 1s\n") + m.Table() m.GoFunc(m, func(m *ctx.Message) { + defer func() { + os.Exit(kit.Int(code)) + }() time.Sleep(time.Second * 1) + m.Cmd("cli._exit") m.Cmd("nfs._exit") - os.Exit(kit.Int(code)) }) return }}, @@ -781,6 +799,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心", default: m.Cmdy("system", m.Conf("system", []string{"script", strings.TrimPrefix(path.Ext(p), ".")}), arg) } + m.Append("directory", "") return } @@ -895,7 +914,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心", timer["msg"] = msg.Code() if timer["repeat"].(bool) { - timer["action_time"] = int64(m.Sess("cli").Cmd("time", timer["action_time"], timer["order"], timer["time"]).Appendi("timestamp")) + timer["action_time"] = int64(m.Sess("cli").Cmd("time", msg.Time(), timer["order"], timer["time"]).Appendi("timestamp")) } else { timer["done"] = true } diff --git a/src/contexts/ctx/init.go b/src/contexts/ctx/init.go index 86bd6312..57e9a9f6 100644 --- a/src/contexts/ctx/init.go +++ b/src/contexts/ctx/init.go @@ -694,18 +694,23 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{}, all, arg = true, arg[1:] } - action := "show" + action := "" if len(arg) > 0 { switch arg[0] { case "show", "list", "add", "delete": action, arg = arg[0], arg[1:] } + } else { + action = "show" } switch action { case "show": c.BackTrace(m, func(m *Message) bool { for k, v := range m.target.Commands { + if strings.HasPrefix(k, "_") { + continue + } if len(arg) > 0 { if k == arg[0] { m.Add("append", "key", k) @@ -825,6 +830,10 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{}, delete(m.target.Commands, arg[0]) return !all }) + default: + if len(arg) > 0 { + m.Cmdy(arg) + } } return }}, diff --git a/src/contexts/nfs/nfs.go b/src/contexts/nfs/nfs.go index 917b9c54..4f99f4fa 100644 --- a/src/contexts/nfs/nfs.go +++ b/src/contexts/nfs/nfs.go @@ -891,6 +891,7 @@ func (nfs *NFS) Start(m *ctx.Message, arg ...string) bool { if nfs.out = m.Optionv("out").(*os.File); m.Cap("goos") != "windows" && !m.Options("daemon") { kit.STDIO = nfs nfs.Term(m, "init") + m.Conf("term", "use", true) defer nfs.Term(m, "exit") } if what := make(chan bool); m.Options("daemon") { @@ -1047,6 +1048,7 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心", }, Configs: map[string]*ctx.Config{ "term": &ctx.Config{Name: "term", Value: map[string]interface{}{ + "use": "false", "mouse": map[string]interface{}{ "resize": false, }, @@ -1147,7 +1149,9 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心", return }}, "_exit": &ctx.Command{Name: "_init", Help: "", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { - termbox.Close() + if m.Confs("term", "use") { + termbox.Close() + } 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 ad902316..79f2f0ba 100644 --- a/src/contexts/ssh/ssh.go +++ b/src/contexts/ssh/ssh.go @@ -45,121 +45,12 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心", "trust": &ctx.Config{Name: "trust", Value: map[string]interface{}{"fresh": false, "user": true, "up": true}, Help: "可信节点"}, "timer": &ctx.Config{Name: "timer", Value: map[string]interface{}{"interval": "10s", "timer": ""}, Help: "断线重连"}, "componet": &ctx.Config{Name: "componet", Value: map[string]interface{}{ - "index": []interface{}{ - map[string]interface{}{"componet_name": "salary", "componet_help": "计算工资", - "componet_tmpl": "componet", "componet_view": "Salary", "componet_init": "", - "componet_type": "public", "componet_ctx": "web.chat", "componet_cmd": "salary", - "componet_args": []interface{}{}, "inputs": []interface{}{ - map[string]interface{}{"label": "total", "type": "text", "name": "text"}, - map[string]interface{}{"label": "base", "type": "text", "name": "total"}, - }, - }, - map[string]interface{}{"componet_name": "qrcode", "componet_help": "生成二维码", - "componet_tmpl": "componet", "componet_view": "QRCode", "componet_init": "initQRCode.js", - "componet_type": "public", "componet_ctx": "web.chat", "componet_cmd": "login", - "componet_args": []interface{}{"qrcode"}, "inputs": []interface{}{ - map[string]interface{}{"label": "content", "type": "text", "name": "content"}, - }, - }, - map[string]interface{}{"componet_name": "clip", "componet_help": "粘贴板", - "componet_tmpl": "componet", "componet_view": "Context", "componet_init": "", - "componet_type": "public", "componet_ctx": "aaa", "componet_cmd": "clip", - "componet_args": []interface{}{}, "inputs": []interface{}{ - map[string]interface{}{"label": "content", "type": "text", "name": "content"}, - map[string]interface{}{"type": "button", "value": "运行"}, - }, - }, - }, - "project": []interface{}{ - map[string]interface{}{"componet_name": "context", "componet_help": "context", - "componet_tmpl": "componet", "componet_view": "Context", "componet_init": "", - "componet_type": "private", "componet_ctx": "ctx", "componet_cmd": "context", - "componet_args": []interface{}{}, "inputs": []interface{}{ - map[string]interface{}{"type": "button", "value": "模块"}, - }, - }, - map[string]interface{}{"componet_name": "ifconfig", "componet_help": "ifconfig", - "componet_tmpl": "componet", "componet_view": "Context", "componet_init": "", - "componet_type": "private", "componet_ctx": "tcp", "componet_cmd": "ifconfig", - "componet_args": []interface{}{}, "inputs": []interface{}{ - map[string]interface{}{"type": "button", "value": "网卡"}, - }, - }, - map[string]interface{}{"componet_name": "pod", "componet_help": "pod", - "componet_tmpl": "componet", "componet_view": "Context", "componet_init": "", - "componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "remote", - "componet_args": []interface{}{}, "inputs": []interface{}{ - map[string]interface{}{"type": "button", "value": "执行"}, - }, - "exports": []interface{}{"pod", "key"}, - }, - map[string]interface{}{"componet_name": "dir", "componet_help": "dir", - "componet_tmpl": "componet", "componet_view": "Context", "componet_init": "", - "componet_type": "private", "componet_ctx": "nfs", "componet_cmd": "dir", - "componet_args": []interface{}{}, "inputs": []interface{}{ - map[string]interface{}{"type": "text", "name": "dir", "value": "work"}, - map[string]interface{}{"type": "button", "value": "查看"}, - }, - "display": map[string]interface{}{"hide_result": true}, - "exports": []interface{}{"dir", "filename", "dir"}, - }, - map[string]interface{}{"componet_name": "status", "componet_help": "git", - "componet_tmpl": "componet", "componet_view": "Context", "componet_init": "", - "componet_type": "private", "componet_ctx": "cli", "componet_cmd": "git", - "componet_args": []interface{}{}, "inputs": []interface{}{ - map[string]interface{}{"type": "text", "name": "dir", "imports": "plugin_dir"}, - map[string]interface{}{"type": "select", "name": "cmd", "values": []interface{}{ - "branch", "status", "diff", "log", "update", "push", - }}, - map[string]interface{}{"type": "button", "value": "执行"}, - }, - }, - map[string]interface{}{"componet_name": "commit", "componet_help": "git", - "componet_tmpl": "componet", "componet_view": "Context", "componet_init": "", - "componet_type": "private", "componet_ctx": "cli", "componet_cmd": "git", - "componet_args": []interface{}{}, "inputs": []interface{}{ - map[string]interface{}{"type": "text", "name": "dir", "imports": "plugin_dir"}, - map[string]interface{}{"type": "select", "name": "cmd", "values": []interface{}{ - "commit", - }}, - map[string]interface{}{"type": "text", "name": "commit"}, - map[string]interface{}{"type": "button", "value": "执行"}, - }, - }, - map[string]interface{}{"componet_name": "spide", "componet_help": "spide", - "componet_tmpl": "componet", "componet_view": "Context", "componet_init": "", - "componet_type": "private", "componet_ctx": "web", "componet_cmd": "spide", - "componet_args": []interface{}{}, "inputs": []interface{}{ - map[string]interface{}{"type": "button", "value": "执行"}, - }, - "exports": []interface{}{"site", "key"}, - }, - map[string]interface{}{"componet_name": "get", "componet_help": "get", - "componet_tmpl": "componet", "componet_view": "Context", "componet_init": "", - "componet_type": "private", "componet_ctx": "web", "componet_cmd": "get", - "componet_args": []interface{}{}, "inputs": []interface{}{ - map[string]interface{}{"type": "text", "name": "spide", "imports": "plugin_site"}, - map[string]interface{}{"type": "text", "name": "url"}, - map[string]interface{}{"type": "button", "value": "执行"}, - }, - }, - map[string]interface{}{"componet_name": "post", "componet_help": "post", - "componet_tmpl": "componet", "componet_view": "Context", "componet_init": "", - "componet_type": "private", "componet_ctx": "web", "componet_cmd": "post", - "componet_args": []interface{}{"content_type", "application/json", "parse", "json"}, "inputs": []interface{}{ - map[string]interface{}{"type": "text", "name": "spide", "imports": "plugin_site"}, - map[string]interface{}{"type": "text", "name": "url"}, - map[string]interface{}{"type": "button", "value": "执行"}, - }, - }, - }, "company": []interface{}{ map[string]interface{}{"componet_name": "status", "componet_help": "status", "componet_tmpl": "componet", "componet_view": "Company", "componet_init": "", "componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route", - "componet_args": []interface{}{}, "inputs": []interface{}{ + "componet_args": []interface{}{"$$", "gg"}, "inputs": []interface{}{ map[string]interface{}{"type": "text", "name": "pod", "imports": "plugin_pod"}, - map[string]interface{}{"type": "text", "name": "cmd", "value": "gg", "view": "hide"}, map[string]interface{}{"type": "select", "name": "sub", "values": []interface{}{"status", ""}}, map[string]interface{}{"type": "button", "value": "执行"}, }, @@ -167,9 +58,8 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心", map[string]interface{}{"componet_name": "deploy", "componet_help": "deploy", "componet_tmpl": "componet", "componet_view": "Company", "componet_init": "", "componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route", - "componet_args": []interface{}{}, "inputs": []interface{}{ + "componet_args": []interface{}{"$$", "gg"}, "inputs": []interface{}{ map[string]interface{}{"type": "text", "name": "pod", "imports": "plugin_pod"}, - map[string]interface{}{"type": "text", "name": "cmd", "value": "gg", "view": "hide"}, map[string]interface{}{"type": "select", "name": "sub", "values": []interface{}{"deploygo", "deploy"}}, map[string]interface{}{"type": "text", "name": "sub", "imports": "plugin_dir"}, map[string]interface{}{"type": "text", "name": "sub", "imports": "plugin_branch"}, @@ -179,9 +69,8 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心", map[string]interface{}{"componet_name": "php", "componet_help": "php", "componet_tmpl": "componet", "componet_view": "Company", "componet_init": "", "componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route", - "componet_args": []interface{}{}, "inputs": []interface{}{ + "componet_args": []interface{}{"$$", "php"}, "inputs": []interface{}{ map[string]interface{}{"type": "text", "name": "pod", "imports": "plugin_pod"}, - map[string]interface{}{"type": "text", "name": "cmd", "value": "php"}, map[string]interface{}{"type": "text", "name": "cmd", "value": "usr/script/test.php"}, map[string]interface{}{"type": "button", "value": "执行"}, }, @@ -189,12 +78,9 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心", map[string]interface{}{"componet_name": "redis", "componet_help": "redis", "componet_tmpl": "componet", "componet_view": "Company", "componet_init": "", "componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route", - "componet_args": []interface{}{}, "inputs": []interface{}{ + "componet_args": []interface{}{"$$", "context", "mdb", "redis"}, "inputs": []interface{}{ map[string]interface{}{"type": "text", "name": "pod"}, - map[string]interface{}{"type": "text", "name": "cmd", "value": "context", "view": "hide"}, - map[string]interface{}{"type": "text", "name": "cmd", "value": "mdb", "view": "hide"}, - map[string]interface{}{"type": "text", "name": "cmd", "value": "redis", "view": "hide"}, - map[string]interface{}{"type": "text", "name": "cmd", "value": "get"}, + map[string]interface{}{"type": "text", "name": "cmd", "values": []interface{}{"get", "del"}}, map[string]interface{}{"type": "text", "name": "cmd", "value": "test"}, map[string]interface{}{"type": "button", "value": "执行"}, }, @@ -220,20 +106,167 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心", "componet_tmpl": "componet", "componet_view": "Compile", "componet_init": "", "componet_type": "private", "componet_ctx": "cli", "componet_cmd": "compile", "componet_args": []interface{}{}, "inputs": []interface{}{ - map[string]interface{}{"type": "text", "name": "action"}, + map[string]interface{}{"type": "select", "name": "action", "values": []interface{}{"linux", "darwin", "windows", "self", "all"}}, map[string]interface{}{"type": "button", "value": "编译"}, }, "display": map[string]interface{}{"hide_append": true, "show_result": true}, }, map[string]interface{}{"componet_name": "publish", "componet_help": "publish", "componet_tmpl": "componet", "componet_view": "Compile", "componet_init": "", - "componet_type": "private", "componet_ctx": "cli", "componet_cmd": "compile", + "componet_type": "private", "componet_ctx": "cli", "componet_cmd": "publish", "componet_args": []interface{}{}, "inputs": []interface{}{ map[string]interface{}{"type": "text", "name": "action"}, - map[string]interface{}{"type": "button", "value": "编译"}, + map[string]interface{}{"type": "button", "value": "发布"}, }, "display": map[string]interface{}{"hide_append": true, "show_result": true}, }, + map[string]interface{}{"componet_name": "upgrade", "componet_help": "upgrade", + "componet_tmpl": "componet", "componet_view": "Compile", "componet_init": "", + "componet_type": "private", "componet_ctx": "cli", "componet_cmd": "upgrade", + "componet_args": []interface{}{}, "inputs": []interface{}{ + map[string]interface{}{"type": "select", "name": "action", "values": []interface{}{"bench", "system", "portal", "script"}}, + map[string]interface{}{"type": "text", "name": "action"}, + map[string]interface{}{"type": "button", "value": "升级"}, + }, + "display": map[string]interface{}{"hide_append": true, "show_result": true}, + }, + map[string]interface{}{"componet_name": "missyou", "componet_help": "missyou", + "componet_tmpl": "componet", "componet_view": "Compile", "componet_init": "", + "componet_type": "private", "componet_ctx": "cli", "componet_cmd": "missyou", + "componet_args": []interface{}{}, "inputs": []interface{}{ + map[string]interface{}{"type": "text", "name": "action"}, + map[string]interface{}{"type": "button", "value": "行动"}, + }, + }, + }, + "favor": []interface{}{ + map[string]interface{}{"componet_name": "salary", "componet_help": "计算工资", + "componet_tmpl": "componet", "componet_view": "Salary", "componet_init": "", + "componet_type": "public", "componet_ctx": "web.chat", "componet_cmd": "salary", + "componet_args": []interface{}{}, "inputs": []interface{}{ + map[string]interface{}{"label": "total", "type": "text", "name": "text"}, + map[string]interface{}{"label": "base", "type": "text", "name": "total"}, + }, + }, + map[string]interface{}{"componet_name": "qrcode", "componet_help": "生成二维码", + "componet_tmpl": "componet", "componet_view": "QRCode", "componet_init": "initQRCode.js", + "componet_type": "public", "componet_ctx": "web.chat", "componet_cmd": "login", + "componet_args": []interface{}{"qrcode"}, "inputs": []interface{}{ + map[string]interface{}{"label": "content", "type": "text", "name": "content"}, + }, + }, + map[string]interface{}{"componet_name": "clip", "componet_help": "粘贴板", + "componet_tmpl": "componet", "componet_view": "Context", "componet_init": "", + "componet_type": "public", "componet_ctx": "aaa", "componet_cmd": "clip", + "componet_args": []interface{}{}, "inputs": []interface{}{ + map[string]interface{}{"label": "content", "type": "text", "name": "content"}, + map[string]interface{}{"type": "button", "value": "运行"}, + }, + }, + }, + "index": []interface{}{ + map[string]interface{}{"componet_name": "pod", "componet_help": "pod", + "componet_tmpl": "componet", "componet_view": "Context", "componet_init": "", + "componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "remote", + "componet_args": []interface{}{}, "inputs": []interface{}{ + map[string]interface{}{"type": "button", "value": "执行"}, + }, + "exports": []interface{}{"pod", "key"}, + }, + map[string]interface{}{"componet_name": "ctx", "componet_help": "ctx", + "componet_tmpl": "componet", "componet_view": "Context", "componet_init": "", + "componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route", + "componet_args": []interface{}{"$$", "context", "$$", "context"}, "inputs": []interface{}{ + map[string]interface{}{"type": "text", "name": "pod", "imports": "plugin_pod"}, + map[string]interface{}{"type": "text", "name": "ctx", "value": "nfs"}, + map[string]interface{}{"type": "button", "value": "模块"}, + }, + "exports": []interface{}{"ctx", "names"}, + }, + map[string]interface{}{"componet_name": "cmd", "componet_help": "cmd", + "componet_tmpl": "componet", "componet_view": "Company", "componet_init": "", + "componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route", + "componet_args": []interface{}{"$$", "context", "$$", "command"}, "inputs": []interface{}{ + map[string]interface{}{"type": "text", "name": "pod", "imports": "plugin_pod"}, + map[string]interface{}{"type": "text", "name": "ctx", "value": "nfs", "imports": "plugin_ctx"}, + map[string]interface{}{"type": "text", "name": "cmd", "value": "pwd"}, + map[string]interface{}{"type": "button", "value": "执行"}, + }, + }, + map[string]interface{}{"componet_name": "dir", "componet_help": "dir", + "componet_tmpl": "componet", "componet_view": "Context", "componet_init": "", + "componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route", + "componet_args": []interface{}{"$$", "context", "nfs", "dir"}, "inputs": []interface{}{ + map[string]interface{}{"type": "text", "name": "pod", "imports": "plugin_pod"}, + map[string]interface{}{"type": "text", "name": "dir", "value": ""}, + map[string]interface{}{"type": "button", "value": "查看"}, + }, + "display": map[string]interface{}{"hide_result": true}, + "exports": []interface{}{"dir", "filename", "dir"}, + }, + map[string]interface{}{"componet_name": "status", "componet_help": "git", + "componet_tmpl": "componet", "componet_view": "Context", "componet_init": "", + "componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route", + "componet_args": []interface{}{"$$", "context", "nfs", "git"}, "inputs": []interface{}{ + map[string]interface{}{"type": "text", "name": "pod", "imports": "plugin_pod"}, + map[string]interface{}{"type": "text", "name": "dir", "imports": "plugin_dir"}, + map[string]interface{}{"type": "select", "name": "cmd", "values": []interface{}{ + "branch", "status", "diff", "log", "update", "push", "init", + }}, + map[string]interface{}{"type": "button", "value": "执行"}, + }, + }, + map[string]interface{}{"componet_name": "commit", "componet_help": "git", + "componet_tmpl": "componet", "componet_view": "Context", "componet_init": "", + "componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route", + "componet_args": []interface{}{"$$", "git"}, "inputs": []interface{}{ + map[string]interface{}{"type": "text", "name": "pod", "imports": "plugin_pod"}, + map[string]interface{}{"type": "text", "name": "dir", "imports": "plugin_dir"}, + map[string]interface{}{"type": "select", "name": "cmd", "values": []interface{}{ + "commit", "add", + }}, + map[string]interface{}{"type": "text", "name": "commit"}, + map[string]interface{}{"type": "button", "value": "执行"}, + }, + }, + map[string]interface{}{"componet_name": "spide", "componet_help": "spide", + "componet_tmpl": "componet", "componet_view": "Context", "componet_init": "", + "componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route", + "componet_args": []interface{}{"$$", "context", "web", "spide"}, "inputs": []interface{}{ + map[string]interface{}{"type": "text", "name": "pod", "imports": "plugin_pod"}, + map[string]interface{}{"type": "button", "value": "执行"}, + }, + "exports": []interface{}{"site", "key"}, + }, + map[string]interface{}{"componet_name": "post", "componet_help": "post", + "componet_tmpl": "componet", "componet_view": "Context", "componet_init": "", + "componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route", + "componet_args": []interface{}{"$$", "context", "web", "post", "$$", "content_type", "application/json", "parse", "json"}, "inputs": []interface{}{ + map[string]interface{}{"type": "text", "name": "pod", "imports": "plugin_pod"}, + map[string]interface{}{"type": "text", "name": "spide", "imports": "plugin_site"}, + map[string]interface{}{"type": "text", "name": "url", "value": "/"}, + map[string]interface{}{"type": "button", "value": "执行"}, + }, + }, + map[string]interface{}{"componet_name": "get", "componet_help": "get", + "componet_tmpl": "componet", "componet_view": "Context", "componet_init": "", + "componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route", + "componet_args": []interface{}{"$$", "context", "web", "get"}, "inputs": []interface{}{ + map[string]interface{}{"type": "text", "name": "pod", "imports": "plugin_pod"}, + map[string]interface{}{"type": "text", "name": "spide", "imports": "plugin_site"}, + map[string]interface{}{"type": "text", "name": "url", "value": "/"}, + map[string]interface{}{"type": "button", "value": "执行"}, + }, + }, + }, + "other": []interface{}{ + map[string]interface{}{"componet_name": "ifconfig", "componet_help": "ifconfig", + "componet_tmpl": "componet", "componet_view": "Context", "componet_init": "", + "componet_type": "private", "componet_ctx": "tcp", "componet_cmd": "ifconfig", + "componet_args": []interface{}{}, "inputs": []interface{}{ + map[string]interface{}{"type": "button", "value": "网卡"}, + }, + }, }, }, Help: "组件列表"}, }, @@ -398,11 +431,21 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心", msg := m.Find(kit.Format(tool["componet_ctx"])) + arg = arg[4:] args := []string{} for _, v := range kit.Trans(tool["componet_args"]) { - args = append(args, msg.Parse(v)) + if v == "$$" { + if len(arg) > 0 { + args = append(args, arg[0]) + arg = arg[1:] + } else { + args = append(args, "") + } + } else { + args = append(args, msg.Parse(v)) + } } - msg.Cmd(tool["componet_cmd"], args, arg[4:]).CopyTo(m) + msg.Cmd(tool["componet_cmd"], args, arg).CopyTo(m) default: m.Confm("componet", arg[0:], func(value map[string]interface{}) { @@ -459,6 +502,9 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心", m.Cmd("ssh._node", "init") m.Call(func(nfs *ctx.Message) *ctx.Message { + if m.Caps("stream") { + return nil + } // 删除重连 if m.Confs("timer", "timer") { m.Conf("timer", "timer", m.Cmdx("cli.timer", "delete", m.Conf("timer", "timer"))) @@ -466,6 +512,9 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心", // 注册设备 m.Spawn(nfs.Target()).Call(func(node *ctx.Message) *ctx.Message { + if m.Caps("stream") { + return nil + } // 添加网关 name := m.Cmd("ssh._node", "create", node.Append("node.name"), "master", m.Cap("stream", nfs.Format("target"))) diff --git a/src/toolkit/kit.go b/src/toolkit/kit.go index cfd90f7a..d915505f 100644 --- a/src/toolkit/kit.go +++ b/src/toolkit/kit.go @@ -42,6 +42,9 @@ func Debugf(str string, args ...interface{}) { Log("debug", str, args...) } +func Key(name string) string { + return strings.Replace(name, ".", "_", -1) +} func Env(key string) { os.Getenv(key) }