forked from x/icebergs
opt code
This commit is contained in:
parent
2edcda85e8
commit
12758d813d
@ -106,19 +106,7 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
var runChecker = []func(*ice.Message, string, string, ...string) bool{}
|
||||
|
||||
func AddRunChecker(cb func(*ice.Message, string, string, ...string) bool) {
|
||||
runChecker = append(runChecker, cb)
|
||||
}
|
||||
func Run(m *ice.Message, arg ...string) {
|
||||
if len(arg) > 3 && arg[1] == ACTION && arg[2] == CONFIG {
|
||||
for _, check := range runChecker {
|
||||
if check(m, arg[0], arg[3], arg...) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
if !PodCmd(m, arg) && aaa.Right(m, arg) {
|
||||
m.Cmdy(arg)
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ const CONFIG = "config"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
CONFIG: {Name: "config key auto", Help: "配置", Actions: ice.Actions{
|
||||
CONFIG: {Name: "config key auto remove", Help: "配置", Actions: ice.Actions{
|
||||
SAVE: {Hand: func(m *ice.Message, arg ...string) { _config_save(m, arg[0], arg[1:]...) }},
|
||||
LOAD: {Hand: func(m *ice.Message, arg ...string) { _config_load(m, arg[0], arg[1:]...) }},
|
||||
mdb.LIST: {Hand: func(m *ice.Message, arg ...string) {
|
||||
@ -107,7 +107,8 @@ func init() {
|
||||
m.Confv(arg[0], arg[1], list)
|
||||
}},
|
||||
mdb.REMOVE: {Name: "remove key sub", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Conf(m.Option("key"), m.Option("sub"), "")
|
||||
m.Cmd(mdb.EXPORT, m.Option(mdb.KEY), m.Option(mdb.SUB), mdb.HASH, path.Join(ice.VAR_TRASH, kit.Keys(m.Option(mdb.KEY), m.Option(mdb.SUB))))
|
||||
nfs.Trash(m, path.Join(ice.VAR_DATA, m.Option(mdb.KEY)))
|
||||
m.Go(func() { m.Cmd(ice.EXIT, 1) })
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, arg ...string) {
|
||||
@ -116,23 +117,11 @@ func init() {
|
||||
} else {
|
||||
_config_make(m, arg[0], arg[1:]...)
|
||||
DisplayStoryJSON(m)
|
||||
m.Action(mdb.REMOVE)
|
||||
}
|
||||
}},
|
||||
})
|
||||
}
|
||||
func init() {
|
||||
AddRunChecker(func(m *ice.Message, cmd, sub string, arg ...string) bool {
|
||||
switch sub {
|
||||
case mdb.SELECT:
|
||||
ProcessFloat(m, CONFIG, cmd)
|
||||
case mdb.REMOVE:
|
||||
m.Cmd(CONFIG, mdb.REMOVE, cmd)
|
||||
default:
|
||||
return false
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
func init() {
|
||||
ice.Info.Save = Save
|
||||
ice.Info.Load = Load
|
||||
|
@ -144,6 +144,7 @@ const (
|
||||
|
||||
JSON = "json"
|
||||
CSV = "csv"
|
||||
SUB = "sub"
|
||||
)
|
||||
|
||||
const MDB = "mdb"
|
||||
|
@ -197,7 +197,8 @@ func ZoneSelect(m *ice.Message, arg ...string) *ice.Message {
|
||||
if m.Cmdy(SELECT, m.PrefixKey(), "", ZONE, arg, logs.FileLineMeta(-1)); len(arg) == 0 {
|
||||
m.PushAction(m.Config(ACTION), REMOVE).StatusTimeCount().Sort(ZoneShort(m))
|
||||
} else if len(arg) == 1 {
|
||||
m.StatusTimeCountTotal(_mdb_getmeta(m, "", kit.Keys(HASH, HashSelectField(m, arg[0], HASH)), COUNT))
|
||||
// m.StatusTimeCountTotal(_mdb_getmeta(m, m.PrefixKey(), kit.Keys(HASH, HashSelectField(m, arg[0], HASH)), COUNT))
|
||||
m.StatusTimeCount()
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
@ -214,6 +214,18 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
func Relative(m *ice.Message, p string) string {
|
||||
var bind = []string{
|
||||
"usr/icebergs/core/chat/", "usr/volcanos/panel/",
|
||||
"usr/icebergs/core/", "usr/volcanos/plugin/local/",
|
||||
}
|
||||
for i := 0; i < len(bind); i += 2 {
|
||||
if strings.HasPrefix(p, bind[i]) {
|
||||
return strings.Replace(p, bind[i], bind[i+1], 1)
|
||||
}
|
||||
}
|
||||
return p
|
||||
}
|
||||
func SplitPath(m *ice.Message, p string) []string {
|
||||
if ls := kit.Split(p, ice.PS); len(ls) == 1 {
|
||||
return []string{PWD, ls[0]}
|
||||
|
@ -90,6 +90,7 @@ const LINK = "link"
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
DEFS: {Name: "defs file text run", Help: "默认", Hand: func(m *ice.Message, arg ...string) {
|
||||
OptionFiles(m, DiskFile)
|
||||
_defs_file(m, arg[0], arg[1:]...)
|
||||
}},
|
||||
SAVE: {Name: "save file text run", Help: "保存", Hand: func(m *ice.Message, arg ...string) {
|
||||
|
@ -85,19 +85,11 @@ func Render(m *ice.Message, cmd string, args ...ice.Any) bool {
|
||||
m.W.Write([]byte(arg[0]))
|
||||
|
||||
default:
|
||||
for _, k := range kit.Simple(m.Optionv("option"), m.Optionv("_option")) {
|
||||
if m.Option(k) == "" {
|
||||
m.Set(k)
|
||||
}
|
||||
}
|
||||
for _, k := range []string{"sessid", "cmds", "fields", "_option", "_handle", "_output"} {
|
||||
m.Set(k)
|
||||
}
|
||||
if cmd != "" && cmd != ice.RENDER_RAW {
|
||||
m.Echo(kit.Format(cmd, args...))
|
||||
}
|
||||
RenderType(m.W, nfs.JSON, "")
|
||||
fmt.Fprint(m.W, m.FormatMeta())
|
||||
m.DumpMeta(m.W)
|
||||
}
|
||||
return true
|
||||
}
|
||||
@ -159,10 +151,19 @@ func CookieName(url string) string {
|
||||
}
|
||||
|
||||
func RenderIndex(m *ice.Message, repos string, file ...string) *ice.Message {
|
||||
if m.IsCliUA() {
|
||||
return m.RenderDownload(path.Join(ice.USR_INTSHELL, kit.Select(ice.INDEX_SH, path.Join(file...))))
|
||||
}
|
||||
return m.RenderDownload(path.Join(ice.USR_VOLCANOS, kit.Select("page/"+ice.INDEX_HTML, path.Join(file...))))
|
||||
|
||||
if repos == "" {
|
||||
repos = kit.Select(ice.VOLCANOS, ice.INTSHELL, m.IsCliUA())
|
||||
}
|
||||
return m.RenderDownload(path.Join(m.Conf(SERVE, kit.Keym(repos, nfs.PATH)), kit.Select(m.Conf(SERVE, kit.Keym(repos, INDEX)), path.Join(file...))))
|
||||
p := func() string {
|
||||
defer mdb.RLock(m, "web.serve")()
|
||||
return path.Join(m.Conf(SERVE, kit.Keym(repos, nfs.PATH)), kit.Select(m.Conf(SERVE, kit.Keym(repos, INDEX)), path.Join(file...)))
|
||||
}
|
||||
return m.RenderDownload(p())
|
||||
}
|
||||
func RenderMain(m *ice.Message, pod, index string, arg ...ice.Any) *ice.Message {
|
||||
if script := m.Cmdx(Space(m, pod), nfs.CAT, kit.Select(ice.SRC_MAIN_JS, index)); script != "" {
|
||||
|
@ -65,10 +65,11 @@ func _serve_main(m *ice.Message, w http.ResponseWriter, r *http.Request) bool {
|
||||
}
|
||||
if r.Method == http.MethodGet && r.URL.Path != PP(SPACE) && !strings.HasPrefix(r.URL.Path, "/code/bash") {
|
||||
repos := kit.Select(ice.INTSHELL, ice.VOLCANOS, strings.Contains(r.Header.Get(UserAgent), MOZILLA))
|
||||
dir := kit.Select(ice.USR_INTSHELL, ice.USR_VOLCANOS, strings.Contains(r.Header.Get(UserAgent), MOZILLA))
|
||||
if p := path.Join(ice.USR, repos, r.URL.Path); r.URL.Path != ice.PS && nfs.ExistsFile(m, p) {
|
||||
Render(m.Spawn(w, r), ice.RENDER_DOWNLOAD, p)
|
||||
return false
|
||||
} else if msg := gdb.Event(m.Spawn(w, r), SERVE_REWRITE, r.Method, r.URL.Path, path.Join(m.Conf(SERVE, kit.Keym(repos, nfs.PATH)), r.URL.Path), repos); msg.Option(ice.MSG_OUTPUT) != "" {
|
||||
} else if msg := gdb.Event(m.Spawn(w, r), SERVE_REWRITE, r.Method, r.URL.Path, path.Join(dir, r.URL.Path), repos); msg.Option(ice.MSG_OUTPUT) != "" {
|
||||
Render(msg, msg.Option(ice.MSG_OUTPUT), kit.List(msg.Optionv(ice.MSG_ARGS))...)
|
||||
return false
|
||||
}
|
||||
@ -194,7 +195,11 @@ func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
"/exit": {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(ice.EXIT) }},
|
||||
SERVE: {Name: "serve name auto start", Help: "服务器", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { cli.NodeInfo(m, ice.Info.Pathname, WORKER) }},
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
cli.NodeInfo(m, ice.Info.Pathname, WORKER)
|
||||
ice.Info.Intshell = path.Join(m.Conf(SERVE, kit.Keym(ice.INTSHELL, nfs.PATH)), kit.Select(m.Conf(SERVE, kit.Keym(ice.INTSHELL, INDEX))))
|
||||
ice.Info.Volcanos = path.Join(m.Conf(SERVE, kit.Keym(ice.VOLCANOS, nfs.PATH)), kit.Select(m.Conf(SERVE, kit.Keym(ice.VOLCANOS, INDEX))))
|
||||
}},
|
||||
cli.START: {Name: "start dev proto host port=9020 nodename username usernick", Hand: func(m *ice.Message, arg ...string) {
|
||||
_serve_start(m)
|
||||
}},
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/web"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
@ -21,6 +22,20 @@ func init() {
|
||||
}
|
||||
}
|
||||
}},
|
||||
ice.HELP: {Hand: func(m *ice.Message, arg ...string) {
|
||||
ctx.ProcessField(m, web.WIKI_WORD, func() string { return kit.ExtChange(ctx.GetCmdFile(m, arg[0]), nfs.SHY) }, arg...)
|
||||
}},
|
||||
nfs.SCRIPT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
ctx.ProcessField(m, web.CODE_VIMER, func() []string {
|
||||
return nfs.SplitPath(m, kit.ExtChange(nfs.Relative(m, ctx.GetCmdFile(m, arg[0])), nfs.JS))
|
||||
}, arg...)
|
||||
}},
|
||||
nfs.SOURCE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
ctx.ProcessField(m, web.CODE_VIMER, func() []string { return nfs.SplitPath(m, ctx.GetCmdFile(m, arg[0])) }, arg...)
|
||||
}},
|
||||
ctx.CONFIG: {Hand: func(m *ice.Message, arg ...string) {
|
||||
ctx.ProcessField(m, ctx.CONFIG, arg, arg...)
|
||||
}},
|
||||
}, ctx.CmdAction(), aaa.WhiteAction(ctx.COMMAND, ice.RUN)), Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Result(kit.Select(m.Config(TITLE), ice.Info.Make.Email))
|
||||
}},
|
||||
|
@ -16,7 +16,7 @@ import (
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _defs_list(m *ice.Message) string {
|
||||
func _autogen_list(m *ice.Message) string {
|
||||
return m.OptionDefault(mdb.LIST, ice.Maps{
|
||||
"Zone": "zone id auto insert",
|
||||
"Hash": "hash auto create",
|
||||
@ -26,7 +26,6 @@ func _defs_list(m *ice.Message) string {
|
||||
}[m.Option(mdb.TYPE)])
|
||||
}
|
||||
func _autogen_source(m *ice.Message, main, file string) {
|
||||
main = kit.ExtChange(main, SHY)
|
||||
m.Cmd(nfs.DEFS, main, nfs.Template(m, ice.SRC_MAIN_SHY))
|
||||
m.Cmd(nfs.PUSH, main, ssh.SOURCE+ice.SP+strings.TrimPrefix(file, ice.SRC+ice.PS)+ice.NL)
|
||||
}
|
||||
@ -53,9 +52,6 @@ func _autogen_import(m *ice.Message, main string, ctx string, mod string) {
|
||||
}
|
||||
func _autogen_version(m *ice.Message) string {
|
||||
if mod := _autogen_mod(m, ice.GO_MOD); !nfs.ExistsFile(m, ".git") {
|
||||
m.Cmdy(cli.SYSTEM, GIT, ice.INIT)
|
||||
m.Cmd(cli.SYSTEM, GIT, nfs.REMOTE, "add", nfs.ORIGIN, "https://"+mod)
|
||||
m.Cmd(cli.SYSTEM, GIT, "add", ice.GO_MOD, ice.SRC, ice.ETC_MISS_SH)
|
||||
m.Cmd(REPOS, mdb.CREATE, nfs.ORIGIN, "https://"+mod, mdb.NAME, path.Base(mod), nfs.PATH, nfs.PWD)
|
||||
}
|
||||
m.Cmd(nfs.DEFS, ".gitignore", nfs.Template(m, "gitignore"))
|
||||
@ -69,13 +65,14 @@ func _autogen_version(m *ice.Message) string {
|
||||
}
|
||||
func _autogen_gits(m *ice.Message, arg ...string) string {
|
||||
res := []string{}
|
||||
kit.Fetch(_autogen_git(m, arg...), func(k string, v string) {
|
||||
kit.For(_autogen_git(m, arg...), func(k, v string) {
|
||||
res = append(res, kit.Format(` %s: "%s",`, kit.Capital(k), strings.TrimSpace(v)))
|
||||
})
|
||||
return kit.Join(res, ice.NL)
|
||||
}
|
||||
func _autogen_git(m *ice.Message, arg ...string) ice.Map {
|
||||
return kit.Dict(nfs.PATH, kit.Path(""), mdb.TIME, m.Time(), arg,
|
||||
return kit.Dict(
|
||||
mdb.TIME, m.Time(), nfs.PATH, kit.Path(""), arg,
|
||||
mdb.HASH, m.Cmdx(cli.SYSTEM, GIT, "log", "-n1", `--pretty=%H`),
|
||||
nfs.REMOTE, m.Cmdx(cli.SYSTEM, GIT, "config", "remote.origin.url"),
|
||||
nfs.BRANCH, m.Cmdx(cli.SYSTEM, GIT, "rev-parse", "--abbrev-ref", "HEAD"),
|
||||
@ -92,24 +89,22 @@ func _autogen_mod(m *ice.Message, file string) (mod string) {
|
||||
} else {
|
||||
host = path.Join(host, "x", path.Base(kit.Path("")))
|
||||
}
|
||||
m.Cmd(nfs.DEFS, file, kit.Format(nfs.Template(m, ice.GO_MOD), host))
|
||||
m.Cmd(nfs.DEFS, file, nfs.Template(m, ice.GO_MOD, host))
|
||||
m.Cmd(nfs.CAT, file, func(line string) {
|
||||
kit.If(strings.HasPrefix(line, nfs.MODULE), func() { mod = kit.Split(line, ice.SP)[1] })
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
const (
|
||||
GIT = "git"
|
||||
|
||||
USR_RELEASE_CONF_GO = "usr/release/conf.go"
|
||||
USR_RELEASE_BINPACK_GO = "usr/release/binpack.go"
|
||||
)
|
||||
const AUTOGEN = "autogen"
|
||||
|
||||
func init() {
|
||||
const (
|
||||
USR_RELEASE_CONF_GO = "usr/release/conf.go"
|
||||
USR_RELEASE_BINPACK_GO = "usr/release/binpack.go"
|
||||
)
|
||||
Index.MergeCommands(ice.Commands{
|
||||
AUTOGEN: {Name: "autogen path auto version module script", Help: "生成", Actions: ice.Actions{
|
||||
AUTOGEN: {Name: "autogen path auto script module version", Help: "生成", Actions: ice.Actions{
|
||||
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) {
|
||||
switch arg[0] {
|
||||
case cli.MAIN:
|
||||
@ -120,28 +115,24 @@ func init() {
|
||||
m.Push(arg[0], Prefix(m.Option(mdb.ZONE), m.Option(mdb.NAME)))
|
||||
}
|
||||
}},
|
||||
nfs.SCRIPT: {Help: "脚本", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(nfs.DEFS, ice.ETC_MISS_SH, nfs.Template(m, ice.ETC_MISS_SH))
|
||||
m.Cmdy(nfs.DIR, ice.ETC_MISS_SH).Cmdy(nfs.CAT, ice.ETC_MISS_SH)
|
||||
}},
|
||||
nfs.MODULE: {Name: "module name*=hi help type*=Zone,Hash,Data,Code,Lang main*=main.go@key zone key", Help: "模块", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.OptionDefault(mdb.ZONE, m.Option(mdb.NAME), mdb.HELP, m.Option(mdb.NAME))
|
||||
m.OptionDefault(mdb.KEY, Prefix(m.Option(mdb.ZONE), m.Option(mdb.NAME)))
|
||||
m.Option(nfs.FILE, path.Join(m.Option(mdb.ZONE), kit.Keys(m.Option(mdb.NAME), GO)))
|
||||
m.Option(mdb.TEXT, kit.Format("`name:\"list %s\" help:\"%s\"`", _defs_list(m), m.Option(mdb.HELP)))
|
||||
nfs.OptionFiles(m, nfs.DiskFile)
|
||||
m.Option(mdb.TEXT, kit.Format("`name:\"list %s\" help:\"%s\"`", _autogen_list(m), m.Option(mdb.HELP)))
|
||||
defer _autogen_version(m.Spawn())
|
||||
if p := path.Join(ice.SRC, kit.ExtChange(m.Option(nfs.FILE), SHY)); !nfs.ExistsFile(m, p) {
|
||||
_autogen_source(m, path.Join(ice.SRC, m.Option(cli.MAIN)), p)
|
||||
_autogen_source(m, kit.ExtChange(path.Join(ice.SRC, m.Option(cli.MAIN)), SHY), p)
|
||||
_autogen_script(m, p)
|
||||
}
|
||||
if p := path.Join(ice.SRC, m.Option(nfs.FILE)); !nfs.ExistsFile(m, p) {
|
||||
_autogen_import(m, path.Join(ice.SRC, m.Option(cli.MAIN)), m.Option(mdb.ZONE), _autogen_mod(m, ice.GO_MOD))
|
||||
_autogen_module(m, p)
|
||||
}
|
||||
_autogen_version(m.Spawn())
|
||||
}},
|
||||
nfs.SCRIPT: {Help: "脚本", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(nfs.DEFS, ice.ETC_MISS_SH, nfs.Template(m, ice.ETC_MISS_SH))
|
||||
defer m.Cmdy(nfs.CAT, ice.ETC_MISS_SH)
|
||||
m.Cmdy(nfs.DIR, ice.ETC_MISS_SH)
|
||||
m.Cmdy(nfs.DIR, ice.GO_MOD)
|
||||
m.Cmdy(nfs.DIR, ice.GO_SUM)
|
||||
}},
|
||||
DEVPACK: {Help: "开发", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(WEBPACK, mdb.REMOVE) }},
|
||||
WEBPACK: {Help: "打包", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(WEBPACK, mdb.CREATE) }},
|
||||
@ -158,8 +149,6 @@ func init() {
|
||||
m.Cmdy(nfs.CAT, _autogen_version(m))
|
||||
}},
|
||||
VERSION: {Help: "版本", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(nfs.CAT, _autogen_version(m)) }},
|
||||
}, Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(nfs.CAT, kit.Select(path.Base(ice.SRC_VERSION_GO), arg, 0), kit.Dict(nfs.DIR_ROOT, ice.SRC))
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
@ -38,8 +38,7 @@ func _bench_http(m *ice.Message, target string, arg ...string) {
|
||||
n, _ := io.Copy(ioutil.Discard, res.Body)
|
||||
atomic.AddInt64(&ndata, n)
|
||||
}); m.Assert(e) {
|
||||
m.Echo("nconn: %d total: %d ndata: %s\n", nconn, nreqs*nconn, kit.FmtSize(ndata)).Echo(s.Show())
|
||||
m.ProcessInner()
|
||||
m.Echo("nconn: %d total: %d ndata: %s\n", nconn, nreqs*nconn, kit.FmtSize(ndata)).Echo(s.Show()).ProcessInner()
|
||||
}
|
||||
}
|
||||
func _bench_redis(m *ice.Message, target string, arg ...string) {
|
||||
@ -58,8 +57,8 @@ const BENCH = "bench"
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
BENCH: {Name: "bench zone id auto insert", Help: "性能压测", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.INSERT: {Name: "insert zone*=some type*=http,redis name=demo text*='http://localhost:9020' nconn=3 nreqs=10"},
|
||||
ice.RUN: {Name: "run", Help: "执行", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.INSERT: {Name: "insert zone*=demo type*=http,redis name=demo text*='http://localhost:9020/chat/cmd/run/web.chat.favor' nconn=10 nreqs=100"},
|
||||
ice.RUN: {Hand: func(m *ice.Message, arg ...string) {
|
||||
switch m.Option(mdb.TYPE) {
|
||||
case HTTP:
|
||||
_bench_http(m, m.Option(mdb.TEXT))
|
||||
@ -68,7 +67,7 @@ func init() {
|
||||
}
|
||||
}},
|
||||
}, mdb.ZoneAction(mdb.FIELD, "time,id,type,name,text,nconn,nreqs")), Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.ZoneSelect(m, arg...).PushAction(kit.Select(mdb.REMOVE, ice.RUN, len(arg) > 0))
|
||||
mdb.ZoneSelect(m, arg...).PushAction(kit.Select(ice.RUN, mdb.REMOVE, len(arg) == 0))
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
@ -25,7 +25,9 @@ func _binpack_file(m *ice.Message, w io.Writer, arg ...string) {
|
||||
}
|
||||
switch path.Base(arg[0]) {
|
||||
case ice.GO_MOD, ice.GO_SUM:
|
||||
return
|
||||
if !strings.HasPrefix(arg[0], ice.SRC_TEMPLATE) {
|
||||
return
|
||||
}
|
||||
}
|
||||
switch arg[0] {
|
||||
case ice.SRC_VERSION_GO, ice.SRC_BINPACK_GO, ice.ETC_LOCAL_SHY:
|
||||
@ -54,23 +56,23 @@ func _binpack_all(m *ice.Message) {
|
||||
for _, p := range []string{ice.ETC_MISS_SH, ice.ETC_INIT_SHY, ice.ETC_EXIT_SHY, ice.README_MD, ice.MAKEFILE, ice.LICENSE} {
|
||||
_binpack_file(m, w, p)
|
||||
}
|
||||
list, cache := map[string]bool{}, kit.Select(ice.USR_REQUIRE, m.Cmdx(cli.SYSTEM, GO, "env", "GOMODCACHE"))
|
||||
list, cache := map[string]string{}, kit.Select(ice.USR_REQUIRE, m.Cmdx(cli.SYSTEM, GO, "env", "GOMODCACHE"))
|
||||
const _mod_ = "/pkg/mod/"
|
||||
for k := range ice.Info.File {
|
||||
switch ls := strings.Split(k, ice.PS); ls[2] {
|
||||
case ice.SRC:
|
||||
case ice.USR:
|
||||
list[path.Join(kit.Slice(ls, 2, -1)...)] = true
|
||||
list[path.Join(kit.Slice(ls, 2, -1)...)] = ""
|
||||
default:
|
||||
list[path.Join(cache, path.Join(kit.Slice(ls, 2, -1)...))] = true
|
||||
p := path.Join(cache, path.Join(kit.Slice(ls, 2, -1)...))
|
||||
_ls := strings.Split(strings.Split(p, _mod_)[1], ice.PS)
|
||||
list[path.Join(nfs.USR, strings.Split(_ls[2], ice.AT)[0], path.Join(kit.Slice(_ls, 3)...))] = p
|
||||
}
|
||||
}
|
||||
for _, p := range kit.SortedKey(list) {
|
||||
m.Cmd(nfs.DIR, p, nfs.PATH, kit.Dict(nfs.DIR_ROOT, nfs.PWD, nfs.DIR_REG, kit.ExtReg(SH, SHY, PY, JS, CSS, HTML))).Tables(func(value ice.Maps) {
|
||||
if strings.Contains(value[nfs.PATH], "/go/pkg/mod/") {
|
||||
_binpack_file(m, w, value[nfs.PATH], ice.USR_REQUIRE+strings.Split(value[nfs.PATH], "/go/pkg/mod/")[1])
|
||||
} else {
|
||||
_binpack_file(m, w, value[nfs.PATH])
|
||||
}
|
||||
for _, k := range kit.SortedKey(list) {
|
||||
v := kit.Select(k, list[k])
|
||||
m.Cmd(nfs.DIR, nfs.PWD, nfs.PATH, kit.Dict(nfs.DIR_ROOT, v, nfs.DIR_REG, kit.ExtReg(SH, SHY, PY, JS, CSS, HTML))).Tables(func(value ice.Maps) {
|
||||
_binpack_file(m, w, kit.Path(v, value[nfs.PATH]), path.Join(k, value[nfs.PATH]))
|
||||
})
|
||||
}
|
||||
mdb.HashSelects(m).Sort(nfs.PATH).Tables(func(value ice.Maps) {
|
||||
|
@ -1,9 +1,6 @@
|
||||
package code
|
||||
|
||||
import (
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
@ -16,19 +13,14 @@ const CASE = "case"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
CASE: {Name: "case dev zone id auto", Help: "用例", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.CREATE: {Name: "create name address", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(web.SPIDE, mdb.CREATE, arg)
|
||||
}},
|
||||
mdb.INSERT: {Name: "insert zone name=hi cmd=POST,GET api arg:textarea res:textarea", Help: "添加"},
|
||||
|
||||
CASE: {Name: "case dev zone id auto insert", Help: "用例", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.INSERT: {Name: "insert zone*=demo name=hi cmd=GET,POST api*=/chat/cmd/web.chat.favor arg:textarea res:textarea"},
|
||||
cli.CHECK: {Name: "check", Help: "检查", Hand: func(m *ice.Message, arg ...string) {
|
||||
if m.ProcessInner(); len(arg) > 0 {
|
||||
if m.ProcessInner(); len(arg) > 1 {
|
||||
success := 0
|
||||
m.Cmd(m.PrefixKey(), arg[0], func(value ice.Maps) {
|
||||
m.Push(mdb.TIME, m.Time())
|
||||
m.Push(mdb.ID, value[mdb.ID])
|
||||
if err := m.Cmdx(m.PrefixKey(), cli.CHECK, value); err == ice.OK {
|
||||
m.Cmd("", arg[0], arg[1], func(value ice.Maps) {
|
||||
m.Push(mdb.TIME, m.Time()).Push(mdb.ID, value[mdb.ID])
|
||||
if err := m.Cmdx("", cli.CHECK, value); err == ice.OK {
|
||||
m.Push(ice.ERR, cli.Color(m, cli.GREEN, err))
|
||||
success++
|
||||
} else {
|
||||
@ -41,9 +33,7 @@ func init() {
|
||||
m.StatusTimeCount(ice.SUCCESS, success)
|
||||
return
|
||||
}
|
||||
|
||||
res := kit.UnMarshal(m.Cmdx(m.PrefixKey(), ice.RUN))
|
||||
if m.Option(ice.RES) != "" {
|
||||
if res := kit.UnMarshal(m.Cmdx("", ice.RUN)); m.Option(ice.RES) != "" {
|
||||
for k, v := range kit.KeyValue(nil, "", kit.UnMarshal(m.Option(ice.RES))) {
|
||||
if v != kit.Value(res, k) {
|
||||
m.Echo(kit.Formats(res))
|
||||
@ -53,74 +43,17 @@ func init() {
|
||||
}
|
||||
m.Echo(ice.OK)
|
||||
}},
|
||||
ice.RUN: {Name: "run", Help: "运行", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Option(web.SPIDE_HEADER, web.ContentType, web.ContentJSON)
|
||||
m.Echo(kit.Formats(kit.UnMarshal(m.Cmdx(web.SPIDE, m.Option(ice.DEV), web.SPIDE_RAW,
|
||||
m.Option(ice.CMD), m.Option(cli.API), web.SPIDE_DATA, m.Option(ice.ARG)))))
|
||||
m.Info(`curl "` + m.Option(cli.API) + `" -H "Content-Type: application/json"` + ` -d '` + m.Option(ice.ARG) + `'`)
|
||||
m.ProcessDisplay("/plugin/story/json.js")
|
||||
ice.RUN: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Option(web.SPIDE_HEADER, web.ContentType, web.ContentJSON, web.UserAgent, "Mozilla/5.0")
|
||||
m.Cmdy(web.SPIDE, m.Option(ice.DEV), web.SPIDE_RAW, m.Option(ice.CMD), m.Option(cli.API), web.SPIDE_DATA, m.Option(ice.ARG)).ProcessInner()
|
||||
m.StatusTime(nfs.SCRIPT, `curl "`+kit.MergeURL2(m.Cmd(web.SPIDE, m.Option(ice.DEV)).Append(web.CLIENT_ORIGIN), m.Option(cli.API))+`" -H "Content-Type: application/json"`+` -d '`+m.Option(ice.ARG)+`'`)
|
||||
}},
|
||||
}, mdb.ZoneAction(mdb.SHORT, mdb.ZONE, mdb.FIELD, "time,id,name,cmd,api,arg,res")), Hand: func(m *ice.Message, arg ...string) {
|
||||
}, mdb.ZoneAction(mdb.FIELD, "time,id,name,cmd,api,arg,res")), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
m.Cmdy(web.SPIDE).RenameAppend("client.name", "dev", "client.url", "address").Action(mdb.CREATE)
|
||||
return
|
||||
m.Cmdy(web.SPIDE).RenameAppend(web.CLIENT_NAME, ice.DEV, web.CLIENT_URL, "address")
|
||||
} else if mdb.ZoneSelect(m, arg[1:]...); len(arg) > 1 {
|
||||
m.PushAction(ice.RUN, cli.CHECK).Action(cli.CHECK)
|
||||
}
|
||||
|
||||
defer m.StatusTimeCount()
|
||||
if mdb.ZoneSelect(m, arg[1:]...); len(arg) == 1 {
|
||||
m.Action(mdb.INSERT, mdb.EXPORT, mdb.IMPORT)
|
||||
m.PushAction(mdb.INSERT, cli.CHECK, mdb.REMOVE)
|
||||
} else {
|
||||
m.Action(mdb.INSERT, cli.CHECK)
|
||||
m.PushAction(ice.RUN, cli.CHECK)
|
||||
}
|
||||
}},
|
||||
"test": {Name: "test path func auto run case", Help: "测试用例", Actions: ice.Actions{
|
||||
"run": {Name: "run", Help: "运行", Hand: func(m *ice.Message, arg ...string) {
|
||||
// cli.Follow(m, "run", func() {
|
||||
m.Option(cli.CMD_DIR, kit.Select(path.Dir(arg[0]), arg[0], strings.HasSuffix(arg[0], "/")))
|
||||
m.Cmdy(cli.SYSTEM, "go", "test", nfs.PWD, "-v", "-run="+arg[1])
|
||||
// })
|
||||
}},
|
||||
"case": {Name: "case", Help: "用例", Hand: func(m *ice.Message, arg ...string) {
|
||||
msg := m.Spawn()
|
||||
if strings.HasSuffix(arg[0], "/") {
|
||||
msg.Option(cli.CMD_DIR, arg[0])
|
||||
msg.Split(msg.Cmdx(cli.SYSTEM, "grep", "-r", "func Test.*(", nfs.PWD), "file:line", ":", "\n")
|
||||
msg.Tables(func(value ice.Maps) {
|
||||
if strings.HasPrefix(strings.TrimSpace(value["line"]), "//") {
|
||||
return
|
||||
}
|
||||
ls := kit.Split(value["line"], " (", " (", " (")
|
||||
m.Push("file", value["file"])
|
||||
m.Push("func", strings.TrimPrefix(ls[1], "Test"))
|
||||
})
|
||||
} else {
|
||||
for _, line := range kit.Split(m.Cmdx(cli.SYSTEM, "grep", "^func Test.*(", arg[0]), "\n", "\n", "\n") {
|
||||
ls := kit.Split(line, " (", " (", " (")
|
||||
m.Push("func", strings.TrimPrefix(ls[1], "Test"))
|
||||
}
|
||||
}
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 || arg[0] == "" {
|
||||
m.Cmdy(nfs.DIR, nfs.PWD)
|
||||
return
|
||||
}
|
||||
if len(arg) == 1 {
|
||||
if strings.HasSuffix(arg[0], "/") {
|
||||
m.Cmdy(nfs.DIR, arg[0])
|
||||
} else {
|
||||
for _, line := range kit.Split(m.Cmdx(cli.SYSTEM, "grep", "^func Test.*(", arg[0]), "\n", "\n", "\n") {
|
||||
ls := kit.Split(line, " (", " (", " (")
|
||||
m.Push("func", strings.TrimPrefix(ls[1], "Test"))
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
m.Option(cli.CMD_DIR, kit.Select(path.Dir(arg[0]), arg[0], strings.HasSuffix(arg[0], "/")))
|
||||
m.Cmdy(cli.SYSTEM, "go", "test", nfs.PWD, "-v", "-run="+arg[1])
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ import (
|
||||
"shylinux.com/x/icebergs/base/lex"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/web"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
@ -132,27 +131,6 @@ func init() {
|
||||
}
|
||||
}},
|
||||
})
|
||||
ctx.AddRunChecker(func(m *ice.Message, cmd, check string, arg ...string) bool {
|
||||
process := func(m *ice.Message, file string) bool {
|
||||
ctx.ProcessFloat(m, kit.Simple(web.CODE_INNER, nfs.SplitPath(m, file))...)
|
||||
return true
|
||||
}
|
||||
switch check {
|
||||
case nfs.SCRIPT:
|
||||
if file := kit.ExtChange(ctx.GetCmdFile(m, cmd), nfs.JS); nfs.ExistsFile(m, file) {
|
||||
return process(m, file)
|
||||
} else if strings.HasPrefix(file, bind[0]) {
|
||||
if file := strings.Replace(file, bind[0], bind[1], 1); nfs.ExistsFile(m, file) {
|
||||
return process(m, file)
|
||||
}
|
||||
}
|
||||
case nfs.SOURCE:
|
||||
if file := ctx.GetCmdFile(m, cmd); nfs.ExistsFile(m, file) {
|
||||
return process(m, file)
|
||||
}
|
||||
}
|
||||
return false
|
||||
})
|
||||
}
|
||||
func InnerPath(arg ...string) (dir, file string) {
|
||||
p := strings.TrimPrefix(path.Join(arg...), kit.Path("")+ice.PS)
|
||||
|
@ -5,6 +5,9 @@ import (
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
)
|
||||
|
||||
const (
|
||||
GIT = "git"
|
||||
)
|
||||
const REPOS = nfs.REPOS
|
||||
|
||||
func init() {
|
||||
|
@ -153,5 +153,6 @@ func init() {
|
||||
}
|
||||
|
||||
func ProcessXterm(m *ice.Message, cmds, text string, arg ...string) {
|
||||
m.Option(nfs.PATH, "")
|
||||
m.Cmdy(ctx.COMMAND, XTERM).Push(ctx.ARGS, kit.Format([]string{m.Cmdx(XTERM, mdb.CREATE, mdb.TYPE, cmds, mdb.NAME, kit.Select("", arg, 0), mdb.TEXT, text)})).ProcessField(XTERM)
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ import (
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/ssh"
|
||||
"shylinux.com/x/icebergs/base/web"
|
||||
"shylinux.com/x/icebergs/misc/git"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
@ -58,16 +57,6 @@ func init() {
|
||||
}
|
||||
}},
|
||||
})
|
||||
ctx.AddRunChecker(func(m *ice.Message, cmd, check string, arg ...string) bool {
|
||||
switch check {
|
||||
case ice.HELP:
|
||||
if file := kit.ExtChange(ctx.GetCmdFile(m, cmd), nfs.SHY); nfs.ExistsFile(m, file) {
|
||||
ctx.ProcessFloat(m, web.WIKI_WORD, file)
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
}
|
||||
func WordAction(template string, arg ...ice.Any) ice.Actions {
|
||||
return ice.Actions{ice.CTX_INIT: mdb.AutoConfig(append([]ice.Any{nfs.TEMPLATE, template}, arg...)...)}
|
||||
|
2
info.go
2
info.go
@ -21,6 +21,8 @@ var Info = struct {
|
||||
Pathname string
|
||||
Username string
|
||||
Password string
|
||||
Intshell string
|
||||
Volcanos string
|
||||
|
||||
Domain string
|
||||
NodeType string
|
||||
|
29
logs.go
29
logs.go
@ -1,6 +1,9 @@
|
||||
package ice
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"runtime"
|
||||
"strings"
|
||||
@ -180,6 +183,32 @@ func (m *Message) FormatCost() string {
|
||||
func (m *Message) FormatSize() string {
|
||||
return kit.Format("%dx%d %v", m.Length(), len(m.meta[MSG_APPEND]), kit.Simple(m.meta[MSG_APPEND]))
|
||||
}
|
||||
func (m *Message) DumpMeta(w io.Writer) {
|
||||
m.meta[MSG_OPTION] = kit.Filters(m.meta[MSG_OPTION], "sessid", "cmds", "fields", "_option", "_handle", "_output", "", "_name", "_index", "log.caller", "aaa.checker")
|
||||
kit.For(m.meta[MSG_OPTION], func(i int, k string) {
|
||||
kit.If(len(m.meta[k]) == 0 || len(m.meta[k]) == 1 && m.meta[k][0] == "", func() { m.meta[MSG_OPTION][i] = "" })
|
||||
})
|
||||
bio := bufio.NewWriter(w)
|
||||
defer bio.Flush()
|
||||
echo := func(k string) {
|
||||
if len(m.meta[k]) == 0 {
|
||||
return
|
||||
}
|
||||
kit.If(k != MSG_DETAIL, func() { fmt.Fprintln(bio, FS) })
|
||||
fmt.Fprint(bio, kit.Format(" %q: ", k))
|
||||
b, _ := json.Marshal(m.meta[k])
|
||||
bio.Write(b)
|
||||
}
|
||||
fmt.Fprintln(bio, "{")
|
||||
defer fmt.Fprintln(bio, "}")
|
||||
echo(MSG_DETAIL)
|
||||
echo(MSG_OPTION)
|
||||
kit.For(m.meta[MSG_OPTION], func(k string) { echo(k) })
|
||||
kit.For(m.meta[MSG_APPEND], func(k string) { echo(k) })
|
||||
echo(MSG_APPEND)
|
||||
echo(MSG_RESULT)
|
||||
fmt.Fprintln(bio)
|
||||
}
|
||||
func (m *Message) FormatMeta() string {
|
||||
return kit.Format(m.meta)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user