diff --git a/Makefile b/Makefile
index 41f8e8c5..3db7978a 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,8 @@
PUBLISH=usr/publish
-BENCH=src/extend/bench.go
+BENCH=src/extend/shy.go
BUILD=go build -o $(PUBLISH)/
+TARGET=shy
install:prepare
GOPATH=$(PWD):$(GOPATH) go install $(BENCH) && date && echo
@@ -17,15 +18,15 @@ prepare:
@go get gopkg.in/gomail.v2
linux_arm:
- GOARCH=arm GOOS=linux $(BUILD)bench.linux.arm $(BENCH)
+ GOARCH=arm GOOS=linux $(BUILD)$(TARGET).linux.arm $(BENCH)
linux32:
- GOARCH=386 GOOS=linux $(BUILD)bench.linux.386 $(BENCH)
+ GOARCH=386 GOOS=linux $(BUILD)$(TARGET).linux.386 $(BENCH)
linux64:
- GOARCH=amd64 GOOS=linux $(BUILD)bench.linux.amd64 $(BENCH)
+ GOARCH=amd64 GOOS=linux $(BUILD)$(TARGET).linux.amd64 $(BENCH)
darwin:
- GOARCH=amd64 GOOS=darwin $(BUILD)bench.darwin.amd64 $(BENCH)
+ GOARCH=amd64 GOOS=darwin $(BUILD)$(TARGET).darwin.amd64 $(BENCH)
win64:
- GOARCH=amd64 GOOS=windows $(BUILD)bench.win64.exe $(BENCH)
+ GOARCH=amd64 GOOS=windows $(BUILD)$(TARGET).win64.exe $(BENCH)
win32:
- GOARCH=386 GOOS=windows $(BUILD)bench.win32.exe $(BENCH)
+ GOARCH=386 GOOS=windows $(BUILD)$(TARGET).win32.exe $(BENCH)
diff --git a/bin/boot.sh b/bin/boot.sh
index 3658bca0..eb5d3fb0 100755
--- a/bin/boot.sh
+++ b/bin/boot.sh
@@ -8,7 +8,7 @@ export ctx_log_disable=${ctx_log_disable:=false}
export ctx_gdb_enable=${ctx_gdb_enable:=false}
# 目录配置
-export ctx_app=${ctx_app:="bench"}
+export ctx_app=${ctx_app:="shy"}
export ctx_bin=${ctx_bin:=$(pwd)/bin/${ctx_app}}; [ -e $ctx_bin ] || export ctx_bin=`which ${ctx_app}`
export ctx_root=${ctx_root:=/usr/local/context}
export ctx_home=${ctx_home:=~/context}
diff --git a/src/contexts/cli/cli.go b/src/contexts/cli/cli.go
index f8b31ad3..3a4d465d 100644
--- a/src/contexts/cli/cli.go
+++ b/src/contexts/cli/cli.go
@@ -175,7 +175,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
},
}, Help: "项目管理"},
"compile": &ctx.Config{Name: "compile", Value: map[string]interface{}{
- "name": "bench", "bench": "src/extend/bench.go", "list": []interface{}{
+ "bench": "src/extend/shy.go", "list": []interface{}{
map[string]interface{}{"os": "linux", "cpu": "arm"},
map[string]interface{}{"os": "linux", "cpu": "386"},
map[string]interface{}{"os": "linux", "cpu": "amd64"},
@@ -824,85 +824,86 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
return
}},
- "project": &ctx.Command{Name: "project init|stat|trend|submit|review|plugin [args...]", Help: "项目管理", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
- switch arg[0] {
- case "init":
- if _, e := os.Stat(".git"); e == nil {
- // 更新代码
- m.Cmdp(0, []string{"git update"}, []string{"cli.system", "git"}, [][]string{
- []string{"stash"}, []string{"pull"}, []string{"stash", "pop"},
+ "project": &ctx.Command{Name: "project init|stat|stats|trend|trends|submit|review|plugin [args...]",
+ Help: "项目管理", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
+ switch arg[0] {
+ case "init":
+ if _, e := os.Stat(".git"); e == nil {
+ // 更新代码
+ m.Cmdp(0, []string{"git update"}, []string{"cli.system", "git"}, [][]string{
+ []string{"stash"}, []string{"pull"}, []string{"stash", "pop"},
+ })
+
+ // 代码状态
+ m.Cmdy("cli.system", "git", "status", "-sb", "cmd_parse", "cut")
+ return e
+ }
+
+ // 创建项目
+ m.Cmdp(0, []string{"git init"}, []string{"cli.system", "git"}, [][]string{
+ []string{"init"}, []string{"remote", "add", kit.Select("origin", arg, 1), kit.Select(m.Conf("project", "github"), arg, 2)},
+ []string{"stash"}, []string{"pull"}, []string{"checkout", "-f", "master"}, []string{"stash", "pop"},
})
- // 代码状态
- m.Cmdy("cli.system", "git", "status", "-sb", "cmd_parse", "cut")
- return e
- }
-
- // 创建项目
- m.Cmdp(0, []string{"git init"}, []string{"cli.system", "git"}, [][]string{
- []string{"init"}, []string{"remote", "add", kit.Select("origin", arg, 1), kit.Select(m.Conf("project", "github"), arg, 2)},
- []string{"stash"}, []string{"pull"}, []string{"checkout", "-f", "master"}, []string{"stash", "pop"},
- })
-
- // 下载依赖
- list := [][]string{}
- m.Confm("compile", "dep", func(index int, value string) {
- list = append(list, []string{value})
- })
- m.Cmdp(0, []string{"go build"}, []string{"cli.system", "go", "get"}, list)
-
- case "stat":
- // 代码统计
- m.Cmdy("nfs.dir", "src", "dir_deep", "dir_type", "file", "dir_sort", "line", "int_r")
-
- case "stats":
- // 代码统计
- m.Cmdy("nfs.dir", kit.Select("src", arg, 1), "dir_deep", "dir_type", "file", "dir_sort", "line", "int_r", "dir_select", "group", "")
-
- case "trend":
- // 提交记录
- if len(arg) == 1 {
- m.Cmdy("nfs.git", "sum", "-n", 20)
- } else {
- m.Cmdy("nfs.git", "sum", "-n", arg[1:])
- }
-
- case "trends":
- // 提交记录
- if len(arg) == 1 {
- m.Cmdy("nfs.git", "sum", "total")
- } else {
- m.Cmdy("nfs.git", "sum", "total", "--reverse", "--since", arg[1])
- }
-
- case "submit":
- // 提交代码
- if len(arg) > 1 {
- m.Cmdp(0, []string{"git submit"}, []string{"cli.system", "git"}, [][]string{
- []string{"commit", "-am", arg[1]}, []string{"push"},
+ // 下载依赖
+ list := [][]string{}
+ m.Confm("compile", "dep", func(index int, value string) {
+ list = append(list, []string{value})
})
- }
- // 提交记录
- m.Cmdy("nfs.git", "logs", "table.limit", "3")
+ m.Cmdp(0, []string{"go build"}, []string{"cli.system", "go", "get"}, list)
- case "review":
- // 代码修改
- m.Cmdy("cli.system", "git", "diff")
+ case "stat":
+ // 代码统计
+ m.Cmdy("nfs.dir", "src", "dir_deep", "dir_type", "file", "dir_sort", "line", "int_r")
- case "plugin":
- // 查看插件
- if arg = arg[1:]; len(arg) == 0 {
- m.Cmdy("nfs.dir", m.Conf("project", "plugin.path"), "time", "line", "name")
- break
+ case "stats":
+ // 代码统计
+ m.Cmdy("nfs.dir", kit.Select("src", arg, 1), "dir_deep", "dir_type", "file", "dir_sort", "line", "int_r", "dir_select", "group", "")
+
+ case "trend":
+ // 提交记录
+ if len(arg) == 1 {
+ m.Cmdy("nfs.git", "sum", "-n", 20)
+ } else {
+ m.Cmdy("nfs.git", "sum", "-n", arg[1:])
+ }
+
+ case "trends":
+ // 提交记录
+ if len(arg) == 1 {
+ m.Cmdy("nfs.git", "sum", "total")
+ } else {
+ m.Cmdy("nfs.git", "sum", "total", "--reverse", "--since", arg[1])
+ }
+
+ case "submit":
+ // 提交代码
+ if len(arg) > 1 {
+ m.Cmdp(0, []string{"git submit"}, []string{"cli.system", "git"}, [][]string{
+ []string{"commit", "-am", arg[1]}, []string{"push"},
+ })
+ }
+ // 提交记录
+ m.Cmdy("nfs.git", "logs", "table.limit", "3")
+
+ case "review":
+ // 代码修改
+ m.Cmdy("cli.system", "git", "diff")
+
+ case "plugin":
+ // 查看插件
+ if arg = arg[1:]; len(arg) == 0 {
+ m.Cmdy("nfs.dir", m.Conf("project", "plugin.path"), "time", "line", "name")
+ break
+ }
+ fallthrough
+ default:
+ m.Option("name", arg[0])
+ m.Option("help", kit.Select("plugin", arg, 1))
+ m.Cmdy("nfs.template", path.Join(m.Conf("project", "plugin.path"), arg[0])+"/", path.Join(m.Conf("project", "plugin.template"))+"/")
}
- fallthrough
- default:
- m.Option("name", arg[0])
- m.Option("help", kit.Select("plugin", arg, 1))
- m.Cmdy("nfs.template", path.Join(m.Conf("project", "plugin.path"), arg[0])+"/", path.Join(m.Conf("project", "plugin.template"))+"/")
- }
- return
- }},
+ return
+ }},
"compile": &ctx.Command{Name: "compile all|self|linux|windows|darwin|restart|plugin", Help: "项目编译", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
switch arg[0] {
case "all":
@@ -962,7 +963,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
// 编译目标
if q == "" {
- q = path.Join(m.Conf("publish", "path"), strings.Join([]string{m.Conf("compile", "name"), goos, arch}, "."))
+ q = path.Join(m.Conf("publish", "path"), strings.Join([]string{m.Conf("runtime", "boot.ctx_app"), goos, arch}, "."))
p = m.Cmdx("nfs.path", m.Conf("compile", "bench"))
}
@@ -1142,9 +1143,9 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
// 执行文件
if strings.HasPrefix(file, "bin/") {
if m.Cmd("cli.system", "chmod", "a+x", file); link == "bench" {
- m.Cmd("cli.system", "mv", "bin/bench", fmt.Sprintf("bin/bench_%s", m.Time("20060102_150405")))
- m.Cmd("cli.system", "mv", "bin/bench.new", "bin/bench")
- file = "bin/bench"
+ file = "bin/" + m.Conf("runtime", "boot.ctx_app")
+ m.Cmd("cli.system", "mv", file, file+m.Time("_20060102_150405"))
+ m.Cmd("cli.system", "mv", m.Conf("upgrade", "list.bench"), file)
}
restart = true
}
diff --git a/src/contexts/cli/version.go b/src/contexts/cli/version.go
index 854e787d..e58fba82 100644
--- a/src/contexts/cli/version.go
+++ b/src/contexts/cli/version.go
@@ -7,5 +7,5 @@ var version = struct {
self int
}{
[]string{"2017-11-01 01:02:03", "2019-07-13 18:02:21"},
- `2019-10-30 15:29:40`, `centos`, 654,
+ `2019-11-01 14:34:16`, `mac`, 657,
}
diff --git a/src/contexts/web/web.go b/src/contexts/web/web.go
index 4bf99049..90b272fa 100644
--- a/src/contexts/web/web.go
+++ b/src/contexts/web/web.go
@@ -1110,8 +1110,8 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
"/publish/": &ctx.Command{Name: "/publish/filename [upgrade script|plugin]", Help: "下载项目", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
// 下载程序
key = strings.TrimPrefix(key, "/publish/")
- if strings.HasSuffix(key, "bench") {
- key = key + "." + kit.Select(m.Conf("runtime", "host.GOOS"), m.Option("GOOS")) +
+ if key == "bench" {
+ key = m.Conf("runtime", "boot.ctx_app") + "." + kit.Select(m.Conf("runtime", "host.GOOS"), m.Option("GOOS")) +
"." + kit.Select(m.Conf("runtime", "host.GOARCH"), m.Option("GOARCH"))
}
diff --git a/src/examples/code/code.go b/src/examples/code/code.go
index 44da9dad..ab973cdf 100644
--- a/src/examples/code/code.go
+++ b/src/examples/code/code.go
@@ -3,483 +3,35 @@ package code
import (
"contexts/ctx"
"contexts/web"
- "fmt"
- "path"
- "plugin"
- "runtime"
- "strconv"
- "strings"
- "time"
- "toolkit"
)
var Index = &ctx.Context{Name: "code", Help: "代码中心",
- Caches: map[string]*ctx.Cache{},
- Configs: map[string]*ctx.Config{
- "skip_login": &ctx.Config{Name: "skip_login", Value: map[string]interface{}{"/consul": "true"}, Help: "免密登录"},
- "componet": &ctx.Config{Name: "componet", Value: map[string]interface{}{
- "login": []interface{}{
- map[string]interface{}{"componet_name": "code", "componet_tmpl": "head", "metas": []interface{}{
- map[string]interface{}{"name": "viewport", "content": "width=device-width, initial-scale=0.7, user-scalable=no"},
- }, "favicon": "favicon.ico", "styles": []interface{}{"example.css", "code.css"}},
-
- map[string]interface{}{"componet_name": "login", "componet_help": "login",
- "componet_tmpl": "componet", "componet_init": "initLogin",
- "componet_ctx": "aaa", "componet_cmd": "auth", "componet_args": []interface{}{"@sessid", "ship", "username", "@username", "password", "@password"}, "inputs": []interface{}{
- map[string]interface{}{"type": "text", "name": "username", "value": "", "label": "username"},
- map[string]interface{}{"type": "password", "name": "password", "value": "", "label": "password"},
- map[string]interface{}{"type": "button", "value": "login"},
- },
- "display_append": "", "display_result": "",
- },
-
- map[string]interface{}{"componet_name": "tail", "componet_tmpl": "tail",
- "scripts": []interface{}{"toolkit.js", "context.js", "example.js", "code.js"},
- },
- },
- "flash": []interface{}{
- map[string]interface{}{"componet_name": "flash", "componet_tmpl": "head", "metas": []interface{}{
- map[string]interface{}{"name": "viewport", "content": "width=device-width, initial-scale=0.7, user-scalable=no"},
- }, "favicon": "favicon.ico", "styles": []interface{}{"example.css", "code.css"}},
-
- map[string]interface{}{"componet_name": "ask", "componet_help": "ask", "componet_tmpl": "componet",
- "componet_view": "FlashText", "componet_init": "initFlashText",
- "componet_ctx": "web.code", "componet_cmd": "flash", "componet_args": []interface{}{"text", "@text"}, "inputs": []interface{}{
- map[string]interface{}{"type": "textarea", "name": "text", "value": "", "cols": 50, "rows": 5},
- map[string]interface{}{"type": "button", "value": "添加请求"},
- },
- "display_result": "", "display_append": "",
- },
- map[string]interface{}{"componet_name": "tip", "componet_help": "tip", "componet_tmpl": "componet",
- "componet_view": "FlashList", "componet_init": "initFlashList",
- "componet_ctx": "web.code", "componet_cmd": "flash",
- "display_result": "", "display_append": "",
- },
-
- map[string]interface{}{"componet_name": "tail", "componet_tmpl": "tail",
- "scripts": []interface{}{"toolkit.js", "context.js", "example.js", "code.js"},
- },
- },
- "schedule": []interface{}{
- map[string]interface{}{"componet_name": "flash", "componet_tmpl": "head", "metas": []interface{}{
- map[string]interface{}{"name": "viewport", "content": "width=device-width, initial-scale=0.7, user-scalable=no"},
- }, "favicon": "favicon.ico", "styles": []interface{}{"example.css", "code.css"}},
-
- map[string]interface{}{"componet_name": "com", "componet_help": "com", "componet_tmpl": "componet",
- "componet_view": "ComList", "componet_init": "initComList",
- "componet_ctx": "web.code", "componet_cmd": "componet", "componet_args": []interface{}{"share", "@role", "@componet_group", "@tips"}, "inputs": []interface{}{
- map[string]interface{}{"type": "text", "name": "role", "value": "tech", "label": "role"},
- map[string]interface{}{"type": "text", "name": "tips", "value": "schedule", "label": "tips"},
- map[string]interface{}{"type": "button", "value": "共享页面"},
- },
- },
-
- map[string]interface{}{"componet_name": "text", "componet_help": "text", "componet_tmpl": "componet",
- "componet_view": "ScheduleText", "componet_init": "initScheduleText",
- "componet_ctx": "web.code", "componet_cmd": "schedule",
- "componet_args": []interface{}{"@time", "@name", "@place"}, "inputs": []interface{}{
- map[string]interface{}{"type": "text", "name": "time", "value": "", "label": "time"},
- map[string]interface{}{"type": "text", "name": "name", "value": "", "label": "name"},
- map[string]interface{}{"type": "text", "name": "place", "value": "", "label": "place"},
- map[string]interface{}{"type": "button", "value": "添加行程"},
- },
- "display_result": "", "display_append": "",
- },
- map[string]interface{}{"componet_name": "list", "componet_help": "list", "componet_tmpl": "componet",
- "componet_view": "ScheduleList", "componet_init": "initScheduleList",
- "componet_ctx": "web.code", "componet_cmd": "schedule",
- "inputs": []interface{}{
- map[string]interface{}{"type": "choice", "name": "view", "value": "default", "label": "显示字段", "choice": []interface{}{
- map[string]interface{}{"name": "默认", "value": "default"},
- map[string]interface{}{"name": "行程", "value": "order"},
- map[string]interface{}{"name": "总结", "value": "summary"},
- }},
- map[string]interface{}{"type": "button", "value": "刷新行程"},
- },
- "display_result": "",
- },
-
- map[string]interface{}{"componet_name": "tail", "componet_tmpl": "tail",
- "scripts": []interface{}{"toolkit.js", "context.js", "example.js", "code.js"},
- },
- },
- "index": []interface{}{
- map[string]interface{}{"componet_name": "code", "componet_tmpl": "head", "metas": []interface{}{
- map[string]interface{}{"name": "viewport", "content": "width=device-width, initial-scale=0.7, user-scalable=no"},
- }, "favicon": "favicon.ico", "styles": []interface{}{"example.css", "code.css"}},
- map[string]interface{}{"componet_name": "banner", "componet_help": "banner", "componet_tmpl": "banner",
- "componet_view": "Banner", "componet_init": "initBanner",
- },
-
- map[string]interface{}{"componet_name": "toolkit", "componet_help": "Ctrl+B", "componet_tmpl": "toolkit",
- "componet_view": "KitList", "componet_init": "initKitList",
- },
- // map[string]interface{}{"componet_name": "login", "componet_help": "login", "componet_tmpl": "componet",
- // "componet_ctx": "aaa", "componet_cmd": "login", "componet_args": []interface{}{"@username", "@password"},
- // "inputs": []interface{}{
- // map[string]interface{}{"type": "text", "name": "username", "label": "username"},
- // map[string]interface{}{"type": "password", "name": "password", "label": "password"},
- // map[string]interface{}{"type": "button", "value": "login"},
- // },
- // "display_append": "", "display_result": "",
- // },
- // map[string]interface{}{"componet_name": "userinfo", "componet_help": "userinfo", "componet_tmpl": "componet",
- // "componet_ctx": "aaa", "componet_cmd": "login", "componet_args": []interface{}{"@sessid"},
- // "pre_run": true,
- // },
- map[string]interface{}{"componet_name": "buffer", "componet_help": "buffer", "componet_tmpl": "componet",
- "componet_view": "BufList", "componet_init": "initBufList",
- "componet_ctx": "cli", "componet_cmd": "tmux", "componet_args": []interface{}{"buffer"}, "inputs": []interface{}{
- map[string]interface{}{"type": "text", "name": "limit", "value": "3", "label": "limit"},
- map[string]interface{}{"type": "text", "name": "index", "value": "0", "label": "index"},
- map[string]interface{}{"type": "button", "value": "refresh"},
- },
- "pre_run": true,
- },
- map[string]interface{}{"componet_name": "dir", "componet_help": "dir", "componet_tmpl": "componet",
- "componet_view": "DirList", "componet_init": "initDirList",
- "componet_ctx": "nfs", "componet_cmd": "dir", "componet_args": []interface{}{"@dir", "dir_sort", "@sort_field", "@sort_order"}, "inputs": []interface{}{
- map[string]interface{}{"type": "choice", "name": "dir_type", "value": "both", "label": "dir_type", "choice": []interface{}{
- map[string]interface{}{"name": "all", "value": "all"},
- map[string]interface{}{"name": "both", "value": "both"},
- map[string]interface{}{"name": "file", "value": "file"},
- map[string]interface{}{"name": "dir", "value": "dir"},
- }},
- map[string]interface{}{"type": "text", "name": "dir", "value": "@current.dir", "label": "dir"},
- map[string]interface{}{"type": "button", "value": "refresh"},
- },
- "pre_run": false, "display_result": "",
- },
- map[string]interface{}{"componet_name": "upload", "componet_help": "upload", "componet_tmpl": "componet",
- "componet_view": "PutFile", "componet_init": "initPutFile",
- "componet_ctx": "web", "componet_cmd": "upload", "form_type": "upload", "inputs": []interface{}{
- map[string]interface{}{"type": "file", "name": "upload"},
- map[string]interface{}{"type": "submit", "value": "submit"},
- },
- "display_result": "",
- },
- map[string]interface{}{"componet_name": "pod", "componet_help": "pod", "componet_tmpl": "componet",
- "componet_view": "PodList", "componet_init": "initPodList",
- "componet_ctx": "ssh", "componet_cmd": "node", "inputs": []interface{}{
- map[string]interface{}{"type": "text", "name": "pod", "value": "@current.pod"},
- map[string]interface{}{"type": "button", "value": "refresh"},
- },
- "pre_run": true, "display_result": "",
- },
- map[string]interface{}{"componet_name": "ctx", "componet_help": "ctx", "componet_tmpl": "componet",
- "componet_view": "CtxList", "componet_init": "initCtxList",
- "componet_pod": "true", "componet_ctx": "ssh", "componet_cmd": "context", "componet_args": []interface{}{"@ctx", "list"}, "inputs": []interface{}{
- map[string]interface{}{"type": "text", "name": "ctx", "value": "@current.ctx"},
- map[string]interface{}{"type": "button", "value": "refresh"},
- },
- "display_result": "",
- },
- map[string]interface{}{"componet_name": "cmd", "componet_help": "cmd", "componet_tmpl": "componet",
- "componet_view": "CmdList", "componet_init": "initCmdList",
- "componet_ctx": "cli.shy", "componet_cmd": "source", "componet_args": []interface{}{"@cmd"}, "inputs": []interface{}{
- map[string]interface{}{"type": "text", "name": "cmd", "value": "", "class": "cmd", "clipstack": "void"},
- },
- },
- // map[string]interface{}{"componet_name": "mp", "componet_tmpl": "mp"},
- map[string]interface{}{"componet_name": "tail", "componet_tmpl": "tail",
- "scripts": []interface{}{"toolkit.js", "context.js", "example.js", "code.js"},
- },
- },
- }, Help: "组件列表"},
- "componet_group": &ctx.Config{Name: "component_group", Value: "index", Help: "默认组件"},
-
- "make": &ctx.Config{Name: "make", Value: map[string]interface{}{
- "go": map[string]interface{}{
- "build": []interface{}{"go", "build"},
- "plugin": []interface{}{"go", "build", "-buildmode=plugin"},
- "load": []interface{}{"load"},
- },
- "so": map[string]interface{}{
- "load": []interface{}{"load"},
- },
- }, Help: "免密登录"},
-
- "flash": &ctx.Config{Name: "flash", Value: map[string]interface{}{
- "data": []interface{}{},
- "view": map[string]interface{}{"default": []interface{}{"index", "time", "text", "code", "output"}},
- }, Help: "闪存"},
- "schedule": &ctx.Config{Name: "schedule", Value: map[string]interface{}{
- "data": []interface{}{},
- "view": map[string]interface{}{
- "default": []interface{}{"面试时间", "面试公司", "面试地点", "面试轮次", "题目类型", "面试题目", "面试总结"},
- "summary": []interface{}{"面试公司", "面试轮次", "题目类型", "面试题目", "面试总结"},
- "order": []interface{}{"面试时间", "面试公司", "面试地点"},
- },
- "maps": map[string]interface{}{"baidu": "%s"},
- }, Help: "闪存"},
-
- "counter": &ctx.Config{Name: "counter", Value: map[string]interface{}{
- "nopen": "0", "nsave": "0",
- }, Help: "counter"},
- "counter_service": &ctx.Config{Name: "counter_service", Value: "http://localhost:9094/code/counter", Help: "counter"},
- },
+ Caches: map[string]*ctx.Cache{},
+ Configs: map[string]*ctx.Config{},
Commands: map[string]*ctx.Command{
- "make": &ctx.Command{Name: "make [action] file [args...]", Help: "更新代码", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
- target, action, suffix := path.Join(m.Conf("runtime", "boot.ctx_home"), "src/examples/app/bench.go"), "build", "go"
- if len(arg) == 0 {
- arg = append(arg, target)
- }
-
- if cs := strings.Split(arg[0], "."); len(cs) > 1 {
- suffix = cs[len(cs)-1]
- } else if cs := strings.Split(arg[1], "."); len(cs) > 1 {
- action, suffix, arg = arg[0], cs[len(cs)-1], arg[1:]
- }
-
- target = m.Cmdx("nfs.path", arg[0])
- if target == "" {
- target = m.Cmdx("nfs.path", path.Join("src/plugin/", arg[0]))
- }
-
- cook := m.Confv("make", []string{suffix, action})
- switch kit.Chains(cook, "0") {
- case "load":
- if suffix == "go" {
- so := strings.Replace(target, ".go", ".so", -1)
- m.Cmd("cli.system", m.Confv("make", "go.plugin"), "-o", so, target)
- arg[0] = so
- }
-
- if p, e := plugin.Open(arg[0]); m.Assert(e) {
- s, e := p.Lookup("Index")
- m.Assert(e)
- w := *(s.(**ctx.Context))
- c.Register(w, nil, true)
- }
- default:
- m.Cmdy("cli.system", cook, arg)
- }
+ "zsh": &ctx.Command{Name: "zsh", Help: "终端", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
+ m.Echo("zsh")
return
}},
- "flash": &ctx.Command{Name: "flash", Help: "闪存", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
- total := len(m.Confv("flash", "data").([]interface{}))
- // 查看列表
- if len(arg) == 0 {
- if index := m.Option("flash_index"); index != "" {
- arg = append(arg, index)
- } else {
- m.Confm("flash", "data", func(index int, item map[string]interface{}) {
- for _, k := range kit.View([]string{}, m.Confm("flash", "view")) {
- m.Add("append", k, kit.Format(item[k]))
- }
- })
- m.Table()
- return
- }
-
- }
-
- index, item := -1, map[string]interface{}{"time": m.Time()}
- if i, e := strconv.Atoi(arg[0]); e == nil && 0 <= i && i < total {
- // 查看索引
- index, arg = total-1-i, arg[1:]
- if item = m.Confm("flash", []interface{}{"data", index}); len(arg) == 0 {
- // 查看数据
- for _, k := range kit.View([]string{}, m.Confm("flash", "view")) {
- m.Add("append", k, kit.Format(item[k]))
- }
- m.Table()
- return e
- }
- }
-
- switch arg[0] {
- case "vim": // 编辑数据
- name := m.Cmdx("nfs.temp", kit.Format(item[kit.Select("code", arg, 1)]))
- m.Cmd("cli.system", "vi", name)
- item[kit.Select("code", arg, 1)] = m.Cmdx("nfs.load", name)
- m.Cmd("nfs.trash", name)
-
- case "run": // 运行代码
- code := kit.Format(item[kit.Select("code", arg, 1)])
- if code == "" {
- break
- }
- name := m.Cmdx("nfs.temp", code)
- m.Cmdy("cli.system", "python", name)
- item["output"] = m.Result(0)
- m.Cmd("nfs.trash", name)
-
- default:
- // 修改数据
- for i := 0; i < len(arg)-1; i += 2 {
- item[arg[i]] = arg[i+1]
- }
- m.Conf("flash", []interface{}{"data", index}, item)
- item["index"] = total - 1 - index
- m.Echo("%d", total-1-index)
- }
-
+ "tmux": &ctx.Command{Name: "tmux", Help: "窗口", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
+ m.Echo("git")
return
}},
- "schedule": &ctx.Command{Name: "schedule [time name place]", Help: "行程安排", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
- if len(arg) == 0 { // 会话列表
- m.Confm("schedule", "data", func(index int, value map[string]interface{}) {
- for _, v := range kit.View([]string{m.Option("view")}, m.Confm("schedule", "view")) {
- if v == "面试地点" {
- m.Add("append", "面试地点", fmt.Sprintf(m.Conf("schedule", "maps.baidu"), value["面试地点"], value["面试地点"]))
- continue
- }
- m.Add("append", v, kit.Format(value[v]))
- }
- })
- m.Table()
- return
- }
-
- view := "default"
- if m.Confs("schedule", arg[0]) {
- view, arg = arg[0], arg[1:]
- }
-
- data := map[string]interface{}{}
- for _, k := range kit.View([]string{view}, m.Confm("schedule", "view")) {
- if len(arg) == 0 {
- data[k] = ""
- continue
- }
- data[k], arg = arg[0], arg[1:]
- }
-
- extra := map[string]interface{}{}
- for i := 0; i < len(arg)-1; i += 2 {
- data[arg[i]] = arg[i+1]
- }
- data["extra"] = extra
-
- m.Conf("schedule", []string{"data", "-1"}, data)
+ "docker": &ctx.Command{Name: "docker", Help: "容器", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
+ m.Echo("docker")
return
}},
- "12306": &ctx.Command{Name: "12306", Help: "12306", Form: map[string]int{"fields": 1, "limit": 1, "offset": 1}, Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
- date := time.Now().Add(time.Hour * 24).Format("2006-01-02")
- if len(arg) > 0 {
- date, arg = arg[0], arg[1:]
- }
- to := "QFK"
- if len(arg) > 0 {
- to, arg = arg[0], arg[1:]
- }
- from := "BJP"
- if len(arg) > 0 {
- from, arg = arg[0], arg[1:]
- }
- m.Echo("%s->%s %s\n", from, to, date)
-
- m.Cmd("web.get", fmt.Sprintf("https://kyfw.12306.cn/otn/leftTicket/queryX?leftTicketDTO.train_date=%s&leftTicketDTO.from_station=%s&leftTicketDTO.to_station=%s&purpose_codes=ADULT", date, from, to), "temp", "data.result")
- for _, v := range m.Meta["value"] {
- fields := strings.Split(v, "|")
- m.Add("append", "车次--", fields[3])
- m.Add("append", "出发----", fields[8])
- m.Add("append", "到站----", fields[9])
- m.Add("append", "时长----", fields[10])
- m.Add("append", "二等座", fields[30])
- m.Add("append", "一等座", fields[31])
- }
- m.Table()
+ "git": &ctx.Command{Name: "git", Help: "版本", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
+ m.Echo("git")
return
}},
- "brow": &ctx.Command{Name: "brow url", Help: "浏览网页", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
- if len(arg) == 0 {
- m.Cmd("tcp.ifconfig").Table(func(index int, value map[string]string) {
- m.Append("index", index)
- m.Append("site", fmt.Sprintf("%s://%s%s", m.Conf("serve", "protocol"), value["ip"], m.Conf("runtime", "boot.web_port")))
- })
- m.Table()
- return
- }
-
- switch runtime.GOOS {
- case "windows":
- m.Cmd("cli.system", "explorer", arg[0])
- case "darwin":
- m.Cmd("cli.system", "open", arg[0])
- default:
- m.Cmd("web.get", arg[0])
- }
- return
- }},
-
- "/counter": &ctx.Command{Name: "/counter", Help: "/counter", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
- if len(arg) > 0 {
- m.Option("name", arg[0])
- }
- if len(arg) > 1 {
- m.Option("count", arg[1])
- }
-
- count := m.Optioni("count")
- switch v := m.Confv("counter", m.Option("name")).(type) {
- case string:
- i, e := strconv.Atoi(v)
- m.Assert(e)
- count += i
- }
- m.Log("info", "%v: %v", m.Option("name"), m.Confv("counter", m.Option("name"), fmt.Sprintf("%d", count)))
- m.Echo("%d", count)
- return
- }},
- "counter": &ctx.Command{Name: "counter name count", Help: "counter", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
- if len(arg) > 1 {
- m.Copy(m.Spawn().Cmd("get", m.Conf("counter_service"), "name", arg[0], "count", arg[1]), "result")
- }
- return
- }},
- "tmux": &ctx.Command{Name: "tmux buffer", Help: "终端管理, buffer: 查看复制", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
- switch arg[0] {
- case "buffer":
- bufs := strings.Split(m.Spawn().Cmd("system", "tmux", "list-buffers").Result(0), "\n")
-
- n := 3
- if m.Option("limit") != "" {
- n = m.Optioni("limit")
- }
-
- for i, b := range bufs {
- if i >= n {
- break
- }
- bs := strings.SplitN(b, ": ", 3)
- if len(bs) > 1 {
- m.Add("append", "buffer", bs[0][:len(bs[0])])
- m.Add("append", "length", bs[1][:len(bs[1])-6])
- m.Add("append", "strings", bs[2][1:len(bs[2])-1])
- }
- }
-
- if m.Option("index") == "" {
- m.Echo(m.Spawn().Cmd("system", "tmux", "show-buffer").Result(0))
- } else {
- m.Echo(m.Spawn().Cmd("system", "tmux", "show-buffer", "-b", m.Option("index")).Result(0))
- }
- }
- return
- }},
- "windows": &ctx.Command{Name: "windows", Help: "windows", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
- m.Append("nclient", strings.Count(m.Spawn().Cmd("system", "tmux", "list-clients").Result(0), "\n"))
- m.Append("nsession", strings.Count(m.Spawn().Cmd("system", "tmux", "list-sessions").Result(0), "\n"))
- m.Append("nwindow", strings.Count(m.Spawn().Cmd("system", "tmux", "list-windows", "-a").Result(0), "\n"))
- m.Append("npane", strings.Count(m.Spawn().Cmd("system", "tmux", "list-panes", "-a").Result(0), "\n"))
-
- m.Append("nbuf", strings.Count(m.Spawn().Cmd("system", "tmux", "list-buffers").Result(0), "\n"))
- m.Append("ncmd", strings.Count(m.Spawn().Cmd("system", "tmux", "list-commands").Result(0), "\n"))
- m.Append("nkey", strings.Count(m.Spawn().Cmd("system", "tmux", "list-keys").Result(0), "\n"))
- m.Table()
- return
- }},
- "notice": &ctx.Command{Name: "notice", Help: "睡眠, time(ns/us/ms/s/m/h): 时间值(纳秒/微秒/毫秒/秒/分钟/小时)", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
- m.Cmd("cli.system", "osascript", "-e", fmt.Sprintf("display notification \"%s\"", kit.Select("", arg, 0)))
+ "vim": &ctx.Command{Name: "vim", Help: "编辑器", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
+ m.Echo("vim")
return
}},
},
}
func init() {
- code := &web.WEB{}
- code.Context = Index
- web.Index.Register(Index, code)
+ web.Index.Register(Index, &web.WEB{Context: Index})
}
diff --git a/src/examples/team/team.go b/src/examples/team/team.go
index 8a9e8449..ed1eb2a4 100644
--- a/src/examples/team/team.go
+++ b/src/examples/team/team.go
@@ -3,20 +3,483 @@ package team
import (
"contexts/ctx"
"contexts/web"
+ "fmt"
+ "path"
+ "plugin"
+ "runtime"
+ "strconv"
+ "strings"
+ "time"
+ "toolkit"
)
-var Index = &ctx.Context{Name: "team", Help: "任务中心",
- Caches: map[string]*ctx.Cache{},
- Configs: map[string]*ctx.Config{},
+var Index = &ctx.Context{Name: "team", Help: "团队中心",
+ Caches: map[string]*ctx.Cache{},
+ Configs: map[string]*ctx.Config{
+ "skip_login": &ctx.Config{Name: "skip_login", Value: map[string]interface{}{"/consul": "true"}, Help: "免密登录"},
+ "componet": &ctx.Config{Name: "componet", Value: map[string]interface{}{
+ "login": []interface{}{
+ map[string]interface{}{"componet_name": "code", "componet_tmpl": "head", "metas": []interface{}{
+ map[string]interface{}{"name": "viewport", "content": "width=device-width, initial-scale=0.7, user-scalable=no"},
+ }, "favicon": "favicon.ico", "styles": []interface{}{"example.css", "code.css"}},
+
+ map[string]interface{}{"componet_name": "login", "componet_help": "login",
+ "componet_tmpl": "componet", "componet_init": "initLogin",
+ "componet_ctx": "aaa", "componet_cmd": "auth", "componet_args": []interface{}{"@sessid", "ship", "username", "@username", "password", "@password"}, "inputs": []interface{}{
+ map[string]interface{}{"type": "text", "name": "username", "value": "", "label": "username"},
+ map[string]interface{}{"type": "password", "name": "password", "value": "", "label": "password"},
+ map[string]interface{}{"type": "button", "value": "login"},
+ },
+ "display_append": "", "display_result": "",
+ },
+
+ map[string]interface{}{"componet_name": "tail", "componet_tmpl": "tail",
+ "scripts": []interface{}{"toolkit.js", "context.js", "example.js", "code.js"},
+ },
+ },
+ "flash": []interface{}{
+ map[string]interface{}{"componet_name": "flash", "componet_tmpl": "head", "metas": []interface{}{
+ map[string]interface{}{"name": "viewport", "content": "width=device-width, initial-scale=0.7, user-scalable=no"},
+ }, "favicon": "favicon.ico", "styles": []interface{}{"example.css", "code.css"}},
+
+ map[string]interface{}{"componet_name": "ask", "componet_help": "ask", "componet_tmpl": "componet",
+ "componet_view": "FlashText", "componet_init": "initFlashText",
+ "componet_ctx": "web.code", "componet_cmd": "flash", "componet_args": []interface{}{"text", "@text"}, "inputs": []interface{}{
+ map[string]interface{}{"type": "textarea", "name": "text", "value": "", "cols": 50, "rows": 5},
+ map[string]interface{}{"type": "button", "value": "添加请求"},
+ },
+ "display_result": "", "display_append": "",
+ },
+ map[string]interface{}{"componet_name": "tip", "componet_help": "tip", "componet_tmpl": "componet",
+ "componet_view": "FlashList", "componet_init": "initFlashList",
+ "componet_ctx": "web.code", "componet_cmd": "flash",
+ "display_result": "", "display_append": "",
+ },
+
+ map[string]interface{}{"componet_name": "tail", "componet_tmpl": "tail",
+ "scripts": []interface{}{"toolkit.js", "context.js", "example.js", "code.js"},
+ },
+ },
+ "schedule": []interface{}{
+ map[string]interface{}{"componet_name": "flash", "componet_tmpl": "head", "metas": []interface{}{
+ map[string]interface{}{"name": "viewport", "content": "width=device-width, initial-scale=0.7, user-scalable=no"},
+ }, "favicon": "favicon.ico", "styles": []interface{}{"example.css", "code.css"}},
+
+ map[string]interface{}{"componet_name": "com", "componet_help": "com", "componet_tmpl": "componet",
+ "componet_view": "ComList", "componet_init": "initComList",
+ "componet_ctx": "web.code", "componet_cmd": "componet", "componet_args": []interface{}{"share", "@role", "@componet_group", "@tips"}, "inputs": []interface{}{
+ map[string]interface{}{"type": "text", "name": "role", "value": "tech", "label": "role"},
+ map[string]interface{}{"type": "text", "name": "tips", "value": "schedule", "label": "tips"},
+ map[string]interface{}{"type": "button", "value": "共享页面"},
+ },
+ },
+
+ map[string]interface{}{"componet_name": "text", "componet_help": "text", "componet_tmpl": "componet",
+ "componet_view": "ScheduleText", "componet_init": "initScheduleText",
+ "componet_ctx": "web.code", "componet_cmd": "schedule",
+ "componet_args": []interface{}{"@time", "@name", "@place"}, "inputs": []interface{}{
+ map[string]interface{}{"type": "text", "name": "time", "value": "", "label": "time"},
+ map[string]interface{}{"type": "text", "name": "name", "value": "", "label": "name"},
+ map[string]interface{}{"type": "text", "name": "place", "value": "", "label": "place"},
+ map[string]interface{}{"type": "button", "value": "添加行程"},
+ },
+ "display_result": "", "display_append": "",
+ },
+ map[string]interface{}{"componet_name": "list", "componet_help": "list", "componet_tmpl": "componet",
+ "componet_view": "ScheduleList", "componet_init": "initScheduleList",
+ "componet_ctx": "web.code", "componet_cmd": "schedule",
+ "inputs": []interface{}{
+ map[string]interface{}{"type": "choice", "name": "view", "value": "default", "label": "显示字段", "choice": []interface{}{
+ map[string]interface{}{"name": "默认", "value": "default"},
+ map[string]interface{}{"name": "行程", "value": "order"},
+ map[string]interface{}{"name": "总结", "value": "summary"},
+ }},
+ map[string]interface{}{"type": "button", "value": "刷新行程"},
+ },
+ "display_result": "",
+ },
+
+ map[string]interface{}{"componet_name": "tail", "componet_tmpl": "tail",
+ "scripts": []interface{}{"toolkit.js", "context.js", "example.js", "code.js"},
+ },
+ },
+ "index": []interface{}{
+ map[string]interface{}{"componet_name": "code", "componet_tmpl": "head", "metas": []interface{}{
+ map[string]interface{}{"name": "viewport", "content": "width=device-width, initial-scale=0.7, user-scalable=no"},
+ }, "favicon": "favicon.ico", "styles": []interface{}{"example.css", "code.css"}},
+ map[string]interface{}{"componet_name": "banner", "componet_help": "banner", "componet_tmpl": "banner",
+ "componet_view": "Banner", "componet_init": "initBanner",
+ },
+
+ map[string]interface{}{"componet_name": "toolkit", "componet_help": "Ctrl+B", "componet_tmpl": "toolkit",
+ "componet_view": "KitList", "componet_init": "initKitList",
+ },
+ // map[string]interface{}{"componet_name": "login", "componet_help": "login", "componet_tmpl": "componet",
+ // "componet_ctx": "aaa", "componet_cmd": "login", "componet_args": []interface{}{"@username", "@password"},
+ // "inputs": []interface{}{
+ // map[string]interface{}{"type": "text", "name": "username", "label": "username"},
+ // map[string]interface{}{"type": "password", "name": "password", "label": "password"},
+ // map[string]interface{}{"type": "button", "value": "login"},
+ // },
+ // "display_append": "", "display_result": "",
+ // },
+ // map[string]interface{}{"componet_name": "userinfo", "componet_help": "userinfo", "componet_tmpl": "componet",
+ // "componet_ctx": "aaa", "componet_cmd": "login", "componet_args": []interface{}{"@sessid"},
+ // "pre_run": true,
+ // },
+ map[string]interface{}{"componet_name": "buffer", "componet_help": "buffer", "componet_tmpl": "componet",
+ "componet_view": "BufList", "componet_init": "initBufList",
+ "componet_ctx": "cli", "componet_cmd": "tmux", "componet_args": []interface{}{"buffer"}, "inputs": []interface{}{
+ map[string]interface{}{"type": "text", "name": "limit", "value": "3", "label": "limit"},
+ map[string]interface{}{"type": "text", "name": "index", "value": "0", "label": "index"},
+ map[string]interface{}{"type": "button", "value": "refresh"},
+ },
+ "pre_run": true,
+ },
+ map[string]interface{}{"componet_name": "dir", "componet_help": "dir", "componet_tmpl": "componet",
+ "componet_view": "DirList", "componet_init": "initDirList",
+ "componet_ctx": "nfs", "componet_cmd": "dir", "componet_args": []interface{}{"@dir", "dir_sort", "@sort_field", "@sort_order"}, "inputs": []interface{}{
+ map[string]interface{}{"type": "choice", "name": "dir_type", "value": "both", "label": "dir_type", "choice": []interface{}{
+ map[string]interface{}{"name": "all", "value": "all"},
+ map[string]interface{}{"name": "both", "value": "both"},
+ map[string]interface{}{"name": "file", "value": "file"},
+ map[string]interface{}{"name": "dir", "value": "dir"},
+ }},
+ map[string]interface{}{"type": "text", "name": "dir", "value": "@current.dir", "label": "dir"},
+ map[string]interface{}{"type": "button", "value": "refresh"},
+ },
+ "pre_run": false, "display_result": "",
+ },
+ map[string]interface{}{"componet_name": "upload", "componet_help": "upload", "componet_tmpl": "componet",
+ "componet_view": "PutFile", "componet_init": "initPutFile",
+ "componet_ctx": "web", "componet_cmd": "upload", "form_type": "upload", "inputs": []interface{}{
+ map[string]interface{}{"type": "file", "name": "upload"},
+ map[string]interface{}{"type": "submit", "value": "submit"},
+ },
+ "display_result": "",
+ },
+ map[string]interface{}{"componet_name": "pod", "componet_help": "pod", "componet_tmpl": "componet",
+ "componet_view": "PodList", "componet_init": "initPodList",
+ "componet_ctx": "ssh", "componet_cmd": "node", "inputs": []interface{}{
+ map[string]interface{}{"type": "text", "name": "pod", "value": "@current.pod"},
+ map[string]interface{}{"type": "button", "value": "refresh"},
+ },
+ "pre_run": true, "display_result": "",
+ },
+ map[string]interface{}{"componet_name": "ctx", "componet_help": "ctx", "componet_tmpl": "componet",
+ "componet_view": "CtxList", "componet_init": "initCtxList",
+ "componet_pod": "true", "componet_ctx": "ssh", "componet_cmd": "context", "componet_args": []interface{}{"@ctx", "list"}, "inputs": []interface{}{
+ map[string]interface{}{"type": "text", "name": "ctx", "value": "@current.ctx"},
+ map[string]interface{}{"type": "button", "value": "refresh"},
+ },
+ "display_result": "",
+ },
+ map[string]interface{}{"componet_name": "cmd", "componet_help": "cmd", "componet_tmpl": "componet",
+ "componet_view": "CmdList", "componet_init": "initCmdList",
+ "componet_ctx": "cli.shy", "componet_cmd": "source", "componet_args": []interface{}{"@cmd"}, "inputs": []interface{}{
+ map[string]interface{}{"type": "text", "name": "cmd", "value": "", "class": "cmd", "clipstack": "void"},
+ },
+ },
+ // map[string]interface{}{"componet_name": "mp", "componet_tmpl": "mp"},
+ map[string]interface{}{"componet_name": "tail", "componet_tmpl": "tail",
+ "scripts": []interface{}{"toolkit.js", "context.js", "example.js", "code.js"},
+ },
+ },
+ }, Help: "组件列表"},
+ "componet_group": &ctx.Config{Name: "component_group", Value: "index", Help: "默认组件"},
+
+ "make": &ctx.Config{Name: "make", Value: map[string]interface{}{
+ "go": map[string]interface{}{
+ "build": []interface{}{"go", "build"},
+ "plugin": []interface{}{"go", "build", "-buildmode=plugin"},
+ "load": []interface{}{"load"},
+ },
+ "so": map[string]interface{}{
+ "load": []interface{}{"load"},
+ },
+ }, Help: "免密登录"},
+
+ "flash": &ctx.Config{Name: "flash", Value: map[string]interface{}{
+ "data": []interface{}{},
+ "view": map[string]interface{}{"default": []interface{}{"index", "time", "text", "code", "output"}},
+ }, Help: "闪存"},
+ "schedule": &ctx.Config{Name: "schedule", Value: map[string]interface{}{
+ "data": []interface{}{},
+ "view": map[string]interface{}{
+ "default": []interface{}{"面试时间", "面试公司", "面试地点", "面试轮次", "题目类型", "面试题目", "面试总结"},
+ "summary": []interface{}{"面试公司", "面试轮次", "题目类型", "面试题目", "面试总结"},
+ "order": []interface{}{"面试时间", "面试公司", "面试地点"},
+ },
+ "maps": map[string]interface{}{"baidu": "%s"},
+ }, Help: "闪存"},
+
+ "counter": &ctx.Config{Name: "counter", Value: map[string]interface{}{
+ "nopen": "0", "nsave": "0",
+ }, Help: "counter"},
+ "counter_service": &ctx.Config{Name: "counter_service", Value: "http://localhost:9094/code/counter", Help: "counter"},
+ },
Commands: map[string]*ctx.Command{
- "/demo": &ctx.Command{Name: "/demo", Help: "demo", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
- m.Echo("demo")
+ "make": &ctx.Command{Name: "make [action] file [args...]", Help: "更新代码", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
+ target, action, suffix := path.Join(m.Conf("runtime", "boot.ctx_home"), "src/examples/app/bench.go"), "build", "go"
+ if len(arg) == 0 {
+ arg = append(arg, target)
+ }
+
+ if cs := strings.Split(arg[0], "."); len(cs) > 1 {
+ suffix = cs[len(cs)-1]
+ } else if cs := strings.Split(arg[1], "."); len(cs) > 1 {
+ action, suffix, arg = arg[0], cs[len(cs)-1], arg[1:]
+ }
+
+ target = m.Cmdx("nfs.path", arg[0])
+ if target == "" {
+ target = m.Cmdx("nfs.path", path.Join("src/plugin/", arg[0]))
+ }
+
+ cook := m.Confv("make", []string{suffix, action})
+ switch kit.Chains(cook, "0") {
+ case "load":
+ if suffix == "go" {
+ so := strings.Replace(target, ".go", ".so", -1)
+ m.Cmd("cli.system", m.Confv("make", "go.plugin"), "-o", so, target)
+ arg[0] = so
+ }
+
+ if p, e := plugin.Open(arg[0]); m.Assert(e) {
+ s, e := p.Lookup("Index")
+ m.Assert(e)
+ w := *(s.(**ctx.Context))
+ c.Register(w, nil, true)
+ }
+ default:
+ m.Cmdy("cli.system", cook, arg)
+ }
+ return
+ }},
+ "flash": &ctx.Command{Name: "flash", Help: "闪存", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
+ total := len(m.Confv("flash", "data").([]interface{}))
+ // 查看列表
+ if len(arg) == 0 {
+ if index := m.Option("flash_index"); index != "" {
+ arg = append(arg, index)
+ } else {
+ m.Confm("flash", "data", func(index int, item map[string]interface{}) {
+ for _, k := range kit.View([]string{}, m.Confm("flash", "view")) {
+ m.Add("append", k, kit.Format(item[k]))
+ }
+ })
+ m.Table()
+ return
+ }
+
+ }
+
+ index, item := -1, map[string]interface{}{"time": m.Time()}
+ if i, e := strconv.Atoi(arg[0]); e == nil && 0 <= i && i < total {
+ // 查看索引
+ index, arg = total-1-i, arg[1:]
+ if item = m.Confm("flash", []interface{}{"data", index}); len(arg) == 0 {
+ // 查看数据
+ for _, k := range kit.View([]string{}, m.Confm("flash", "view")) {
+ m.Add("append", k, kit.Format(item[k]))
+ }
+ m.Table()
+ return e
+ }
+ }
+
+ switch arg[0] {
+ case "vim": // 编辑数据
+ name := m.Cmdx("nfs.temp", kit.Format(item[kit.Select("code", arg, 1)]))
+ m.Cmd("cli.system", "vi", name)
+ item[kit.Select("code", arg, 1)] = m.Cmdx("nfs.load", name)
+ m.Cmd("nfs.trash", name)
+
+ case "run": // 运行代码
+ code := kit.Format(item[kit.Select("code", arg, 1)])
+ if code == "" {
+ break
+ }
+ name := m.Cmdx("nfs.temp", code)
+ m.Cmdy("cli.system", "python", name)
+ item["output"] = m.Result(0)
+ m.Cmd("nfs.trash", name)
+
+ default:
+ // 修改数据
+ for i := 0; i < len(arg)-1; i += 2 {
+ item[arg[i]] = arg[i+1]
+ }
+ m.Conf("flash", []interface{}{"data", index}, item)
+ item["index"] = total - 1 - index
+ m.Echo("%d", total-1-index)
+ }
+
+ return
+ }},
+ "schedule": &ctx.Command{Name: "schedule [time name place]", Help: "行程安排", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
+ if len(arg) == 0 { // 会话列表
+ m.Confm("schedule", "data", func(index int, value map[string]interface{}) {
+ for _, v := range kit.View([]string{m.Option("view")}, m.Confm("schedule", "view")) {
+ if v == "面试地点" {
+ m.Add("append", "面试地点", fmt.Sprintf(m.Conf("schedule", "maps.baidu"), value["面试地点"], value["面试地点"]))
+ continue
+ }
+ m.Add("append", v, kit.Format(value[v]))
+ }
+ })
+ m.Table()
+ return
+ }
+
+ view := "default"
+ if m.Confs("schedule", arg[0]) {
+ view, arg = arg[0], arg[1:]
+ }
+
+ data := map[string]interface{}{}
+ for _, k := range kit.View([]string{view}, m.Confm("schedule", "view")) {
+ if len(arg) == 0 {
+ data[k] = ""
+ continue
+ }
+ data[k], arg = arg[0], arg[1:]
+ }
+
+ extra := map[string]interface{}{}
+ for i := 0; i < len(arg)-1; i += 2 {
+ data[arg[i]] = arg[i+1]
+ }
+ data["extra"] = extra
+
+ m.Conf("schedule", []string{"data", "-1"}, data)
+ return
+ }},
+ "12306": &ctx.Command{Name: "12306", Help: "12306", Form: map[string]int{"fields": 1, "limit": 1, "offset": 1}, Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
+ date := time.Now().Add(time.Hour * 24).Format("2006-01-02")
+ if len(arg) > 0 {
+ date, arg = arg[0], arg[1:]
+ }
+ to := "QFK"
+ if len(arg) > 0 {
+ to, arg = arg[0], arg[1:]
+ }
+ from := "BJP"
+ if len(arg) > 0 {
+ from, arg = arg[0], arg[1:]
+ }
+ m.Echo("%s->%s %s\n", from, to, date)
+
+ m.Cmd("web.get", fmt.Sprintf("https://kyfw.12306.cn/otn/leftTicket/queryX?leftTicketDTO.train_date=%s&leftTicketDTO.from_station=%s&leftTicketDTO.to_station=%s&purpose_codes=ADULT", date, from, to), "temp", "data.result")
+ for _, v := range m.Meta["value"] {
+ fields := strings.Split(v, "|")
+ m.Add("append", "车次--", fields[3])
+ m.Add("append", "出发----", fields[8])
+ m.Add("append", "到站----", fields[9])
+ m.Add("append", "时长----", fields[10])
+ m.Add("append", "二等座", fields[30])
+ m.Add("append", "一等座", fields[31])
+ }
+ m.Table()
+ return
+ }},
+ "brow": &ctx.Command{Name: "brow url", Help: "浏览网页", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
+ if len(arg) == 0 {
+ m.Cmd("tcp.ifconfig").Table(func(index int, value map[string]string) {
+ m.Append("index", index)
+ m.Append("site", fmt.Sprintf("%s://%s%s", m.Conf("serve", "protocol"), value["ip"], m.Conf("runtime", "boot.web_port")))
+ })
+ m.Table()
+ return
+ }
+
+ switch runtime.GOOS {
+ case "windows":
+ m.Cmd("cli.system", "explorer", arg[0])
+ case "darwin":
+ m.Cmd("cli.system", "open", arg[0])
+ default:
+ m.Cmd("web.get", arg[0])
+ }
+ return
+ }},
+
+ "/counter": &ctx.Command{Name: "/counter", Help: "/counter", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
+ if len(arg) > 0 {
+ m.Option("name", arg[0])
+ }
+ if len(arg) > 1 {
+ m.Option("count", arg[1])
+ }
+
+ count := m.Optioni("count")
+ switch v := m.Confv("counter", m.Option("name")).(type) {
+ case string:
+ i, e := strconv.Atoi(v)
+ m.Assert(e)
+ count += i
+ }
+ m.Log("info", "%v: %v", m.Option("name"), m.Confv("counter", m.Option("name"), fmt.Sprintf("%d", count)))
+ m.Echo("%d", count)
+ return
+ }},
+ "counter": &ctx.Command{Name: "counter name count", Help: "counter", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
+ if len(arg) > 1 {
+ m.Copy(m.Spawn().Cmd("get", m.Conf("counter_service"), "name", arg[0], "count", arg[1]), "result")
+ }
+ return
+ }},
+ "tmux": &ctx.Command{Name: "tmux buffer", Help: "终端管理, buffer: 查看复制", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
+ switch arg[0] {
+ case "buffer":
+ bufs := strings.Split(m.Spawn().Cmd("system", "tmux", "list-buffers").Result(0), "\n")
+
+ n := 3
+ if m.Option("limit") != "" {
+ n = m.Optioni("limit")
+ }
+
+ for i, b := range bufs {
+ if i >= n {
+ break
+ }
+ bs := strings.SplitN(b, ": ", 3)
+ if len(bs) > 1 {
+ m.Add("append", "buffer", bs[0][:len(bs[0])])
+ m.Add("append", "length", bs[1][:len(bs[1])-6])
+ m.Add("append", "strings", bs[2][1:len(bs[2])-1])
+ }
+ }
+
+ if m.Option("index") == "" {
+ m.Echo(m.Spawn().Cmd("system", "tmux", "show-buffer").Result(0))
+ } else {
+ m.Echo(m.Spawn().Cmd("system", "tmux", "show-buffer", "-b", m.Option("index")).Result(0))
+ }
+ }
+ return
+ }},
+ "windows": &ctx.Command{Name: "windows", Help: "windows", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
+ m.Append("nclient", strings.Count(m.Spawn().Cmd("system", "tmux", "list-clients").Result(0), "\n"))
+ m.Append("nsession", strings.Count(m.Spawn().Cmd("system", "tmux", "list-sessions").Result(0), "\n"))
+ m.Append("nwindow", strings.Count(m.Spawn().Cmd("system", "tmux", "list-windows", "-a").Result(0), "\n"))
+ m.Append("npane", strings.Count(m.Spawn().Cmd("system", "tmux", "list-panes", "-a").Result(0), "\n"))
+
+ m.Append("nbuf", strings.Count(m.Spawn().Cmd("system", "tmux", "list-buffers").Result(0), "\n"))
+ m.Append("ncmd", strings.Count(m.Spawn().Cmd("system", "tmux", "list-commands").Result(0), "\n"))
+ m.Append("nkey", strings.Count(m.Spawn().Cmd("system", "tmux", "list-keys").Result(0), "\n"))
+ m.Table()
+ return
+ }},
+ "notice": &ctx.Command{Name: "notice", Help: "睡眠, time(ns/us/ms/s/m/h): 时间值(纳秒/微秒/毫秒/秒/分钟/小时)", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
+ m.Cmd("cli.system", "osascript", "-e", fmt.Sprintf("display notification \"%s\"", kit.Select("", arg, 0)))
+ return
}},
},
}
func init() {
- team := &web.WEB{}
- team.Context = Index
- web.Index.Register(Index, team)
+ code := &web.WEB{}
+ code.Context = Index
+ web.Index.Register(Index, code)
}
diff --git a/src/extend/bench.go b/src/extend/shy.go
similarity index 100%
rename from src/extend/bench.go
rename to src/extend/shy.go