mirror of
https://shylinux.com/x/icebergs
synced 2025-04-26 01:24:05 +08:00
opt code
This commit is contained in:
parent
c2d67e7081
commit
7a65f0b4ef
@ -137,12 +137,7 @@ const ZONE = "zone"
|
||||
func ZoneAction(args ...interface{}) map[string]*ice.Action {
|
||||
_zone := func(m *ice.Message) string { return kit.Select(ZONE, m.Config(SHORT)) }
|
||||
|
||||
return ice.SelectAction(map[string]*ice.Action{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if cs := m.Target().Configs; cs[m.CommandKey()] == nil {
|
||||
cs[m.CommandKey()] = &ice.Config{Value: kit.Data(args...)}
|
||||
}
|
||||
}},
|
||||
return ice.SelectAction(map[string]*ice.Action{ice.CTX_INIT: AutoConfig(args...),
|
||||
INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
|
||||
arg[0] = strings.TrimPrefix(arg[0], "extra.")
|
||||
arg[0] = kit.Select(arg[0], m.Config(kit.Keys(ALIAS, arg[0])))
|
||||
|
@ -95,6 +95,10 @@ func _cat_list(m *ice.Message, name string) {
|
||||
for bio := bufio.NewScanner(f); bio.Scan(); {
|
||||
cb(bio.Text())
|
||||
}
|
||||
case func([]string, string):
|
||||
for bio := bufio.NewScanner(f); bio.Scan(); {
|
||||
cb(kit.Split(bio.Text()), bio.Text())
|
||||
}
|
||||
|
||||
default:
|
||||
buf := make([]byte, ice.MOD_BUFS)
|
||||
|
@ -23,6 +23,10 @@ func _share_link(m *ice.Message, p string, arg ...interface{}) string {
|
||||
return tcp.ReplaceLocalhost(m, m.MergeURL2(p, arg...))
|
||||
}
|
||||
func _share_repos(m *ice.Message, repos string, arg ...string) {
|
||||
if repos == ice.Info.Make.Module && kit.FileExists(path.Join(arg...)) {
|
||||
m.RenderDownload(path.Join(arg...))
|
||||
return
|
||||
}
|
||||
prefix := kit.Path(m.Conf(SERVE, kit.Keym(ice.REQUIRE)))
|
||||
if _, e := os.Stat(path.Join(prefix, repos)); e != nil { // 克隆代码
|
||||
m.Cmd("web.code.git.repos", mdb.CREATE, nfs.REPOS, "https://"+repos, nfs.PATH, path.Join(prefix, repos))
|
||||
|
@ -24,7 +24,9 @@ func _header_check(m *ice.Message, arg ...string) {
|
||||
m.Option(web.LOGIN, m.Config(web.LOGIN))
|
||||
m.Option(web.SSO, m.Conf(web.SERVE, kit.Keym(web.SSO)))
|
||||
}
|
||||
m.Option("login.dev", m.Cmd(web.SPACE, ice.DEV).Append(mdb.TEXT))
|
||||
if m.Option("login.dev", m.Cmd(web.SPACE, ice.DEV).Append(mdb.TEXT)) == "" {
|
||||
m.Option("login.dev", m.Cmd(web.SPACE, ice.SHY).Append(mdb.TEXT))
|
||||
}
|
||||
}
|
||||
func _header_grant(m *ice.Message, arg ...string) {
|
||||
m.Cmd(GRANT, mdb.INSERT, kit.SimpleKV("space,grant,userrole,username",
|
||||
|
@ -85,7 +85,7 @@ field "{{.Option "help"}}" {{.Option "key"}}
|
||||
`)
|
||||
}
|
||||
func _autogen_source(m *ice.Message, main, file string) {
|
||||
m.Cmd(nfs.PUSH, strings.ReplaceAll(main, ice.PT+GO, ice.PT+SHY), ice.NL, strings.TrimPrefix(file, ice.SRC+ice.PS), ice.NL)
|
||||
m.Cmd(nfs.PUSH, strings.ReplaceAll(main, ice.PT+GO, ice.PT+SHY), ice.NL, "source "+strings.TrimPrefix(file, ice.SRC+ice.PS))
|
||||
}
|
||||
func _autogen_mod(m *ice.Message, file string) (mod string) {
|
||||
m.Cmd(nfs.DEFS, ice.GO_MOD, kit.Format(`module %s
|
||||
@ -138,7 +138,7 @@ func init() {
|
||||
%s
|
||||
}
|
||||
}
|
||||
`, _autogen_gits(m, "HostName", ice.Info.HostName, "UserName", ice.Info.UserName)))
|
||||
`, _autogen_gits(m, "Module", _autogen_mod(m, ice.GO_MOD), "HostName", ice.Info.HostName, "UserName", ice.Info.UserName)))
|
||||
|
||||
m.Cmdy(nfs.DIR, ice.SRC_MAIN_GO)
|
||||
m.Cmdy(nfs.DIR, ice.SRC_VERSION_GO)
|
||||
|
@ -26,27 +26,26 @@ func _bench_http(m *ice.Message, target string, arg ...string) {
|
||||
if f, e := os.Open(ls[2]); m.Assert(e) {
|
||||
defer f.Close()
|
||||
|
||||
req, err := http.NewRequest(http.MethodPost, ls[1], f)
|
||||
m.Assert(err)
|
||||
list = append(list, req)
|
||||
if req, err := http.NewRequest(http.MethodPost, ls[1], f); m.Assert(err) {
|
||||
list = append(list, req)
|
||||
}
|
||||
}
|
||||
default:
|
||||
req, err := http.NewRequest(http.MethodGet, v, nil)
|
||||
m.Assert(err)
|
||||
list = append(list, req)
|
||||
if req, err := http.NewRequest(http.MethodGet, v, nil); m.Assert(err) {
|
||||
list = append(list, req)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var body int64
|
||||
s, e := bench.HTTP(nconn, nreqs, list, func(req *http.Request, res *http.Response) {
|
||||
if s, e := bench.HTTP(nconn, nreqs, list, func(req *http.Request, res *http.Response) {
|
||||
n, _ := io.Copy(ioutil.Discard, res.Body)
|
||||
atomic.AddInt64(&body, n)
|
||||
})
|
||||
m.Assert(e)
|
||||
|
||||
m.Echo(s.Show())
|
||||
m.Echo("body: %d\n", body)
|
||||
m.ProcessInner()
|
||||
}); m.Assert(e) {
|
||||
m.Echo("body: %s\n", kit.FmtSize(body))
|
||||
m.Echo(s.Show())
|
||||
m.ProcessInner()
|
||||
}
|
||||
}
|
||||
func _bench_redis(m *ice.Message, target string, arg ...string) {
|
||||
}
|
||||
@ -62,11 +61,7 @@ const (
|
||||
const BENCH = "bench"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
||||
BENCH: {Name: BENCH, Help: "性能压测", Value: kit.Data(
|
||||
mdb.SHORT, mdb.ZONE, mdb.FIELD, "time,id,type,name,text,nconn,nreqs",
|
||||
)},
|
||||
}, Commands: map[string]*ice.Command{
|
||||
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
|
||||
BENCH: {Name: "bench zone id auto insert", Help: "性能压测", Action: ice.MergeAction(map[string]*ice.Action{
|
||||
mdb.INSERT: {Name: "insert zone=some type=http,redis name=demo text='http://localhost:9020' nconn=3 nreqs=10", Help: "添加"},
|
||||
ice.RUN: {Name: "run", Help: "执行", Hand: func(m *ice.Message, arg ...string) {
|
||||
@ -77,9 +72,8 @@ func init() {
|
||||
_bench_redis(m, m.Option(mdb.TEXT))
|
||||
}
|
||||
}},
|
||||
}, mdb.ZoneAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
mdb.ZoneSelect(m, arg...)
|
||||
m.PushAction(kit.Select(mdb.REMOVE, ice.RUN, len(arg) > 0))
|
||||
}, mdb.ZoneAction(mdb.SHORT, mdb.ZONE, mdb.FIELD, "time,id,type,name,text,nconn,nreqs")), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
mdb.ZoneSelect(m, arg...).PushAction(kit.Select(mdb.REMOVE, ice.RUN, len(arg) > 0))
|
||||
}},
|
||||
}})
|
||||
}
|
||||
|
@ -59,17 +59,6 @@ func init() {
|
||||
}
|
||||
LoadPlug(m, C)
|
||||
}},
|
||||
mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if arg[0] == mdb.FOREACH {
|
||||
return
|
||||
}
|
||||
m.Option(cli.CMD_DIR, kit.Select(ice.SRC, arg, 2))
|
||||
m.Cmdy(mdb.SEARCH, MAN2, arg[1:])
|
||||
m.Cmdy(mdb.SEARCH, MAN3, arg[1:])
|
||||
_c_tags(m, kit.Select(cli.MAIN, arg, 1))
|
||||
_go_find(m, kit.Select(cli.MAIN, arg, 1), arg[2])
|
||||
_go_grep(m, kit.Select(cli.MAIN, arg, 1), arg[2])
|
||||
}},
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Option(cli.CMD_DIR, arg[2])
|
||||
name := strings.TrimSuffix(arg[1], path.Ext(arg[1])) + ".bin"
|
||||
@ -79,6 +68,17 @@ func init() {
|
||||
}
|
||||
m.Echo(m.Cmd(cli.SYSTEM, nfs.PWD+name).Append(cli.CMD_OUT))
|
||||
}},
|
||||
mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if arg[0] == mdb.FOREACH {
|
||||
return
|
||||
}
|
||||
m.Option(cli.CMD_DIR, kit.Select(ice.SRC, arg, 2))
|
||||
m.Cmdy(mdb.SEARCH, MAN2, arg[1:])
|
||||
m.Cmdy(mdb.SEARCH, MAN3, arg[1:])
|
||||
_c_tags(m, kit.Select(cli.MAIN, arg, 1))
|
||||
// _go_find(m, kit.Select(cli.MAIN, arg, 1), arg[2])
|
||||
// _go_grep(m, kit.Select(cli.MAIN, arg, 1), arg[2])
|
||||
}},
|
||||
}, PlugAction())},
|
||||
MAN: {Name: MAN, Help: "手册", Action: ice.MergeAction(map[string]*ice.Action{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
@ -89,6 +89,9 @@ func init() {
|
||||
}
|
||||
LoadPlug(m, MAN)
|
||||
}},
|
||||
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Echo(_c_help(m, strings.TrimPrefix(arg[0], MAN), strings.TrimSuffix(arg[1], ice.PT+arg[0])))
|
||||
}},
|
||||
mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if arg[0] == mdb.FOREACH {
|
||||
return
|
||||
@ -99,19 +102,18 @@ func init() {
|
||||
}
|
||||
}
|
||||
}},
|
||||
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Echo(_c_help(m, strings.TrimPrefix(arg[0], MAN), strings.TrimSuffix(arg[1], ice.PT+arg[0])))
|
||||
}},
|
||||
}, PlugAction())},
|
||||
}, Configs: map[string]*ice.Config{
|
||||
C: {Name: C, Help: "系统", Value: kit.Data(PLUG, kit.Dict(
|
||||
SPLIT, kit.Dict("space", " ", "operator", "{[(.,:;!|<>)]}"),
|
||||
PREFIX, kit.Dict("//", COMMENT, "/*", COMMENT, "*", COMMENT), PREPARE, kit.Dict(
|
||||
PREFIX, kit.Dict("//", COMMENT, "/* ", COMMENT, "* ", COMMENT), PREPARE, kit.Dict(
|
||||
KEYWORD, kit.Simple(
|
||||
"#include",
|
||||
"#define",
|
||||
"#ifndef",
|
||||
"#ifdef",
|
||||
"#if",
|
||||
"#elif",
|
||||
"#else",
|
||||
"#endif",
|
||||
|
||||
|
@ -15,11 +15,7 @@ import (
|
||||
const CASE = "case"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
||||
CASE: {Name: CASE, Help: "用例", Value: kit.Data(
|
||||
mdb.SHORT, mdb.ZONE, mdb.FIELD, "time,id,name,cmd,api,arg,res",
|
||||
)},
|
||||
}, Commands: map[string]*ice.Command{
|
||||
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
|
||||
CASE: {Name: "case dev zone id auto", Help: "用例", Action: ice.MergeAction(map[string]*ice.Action{
|
||||
mdb.CREATE: {Name: "create name address", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(web.SPIDE, mdb.CREATE, arg)
|
||||
@ -29,7 +25,7 @@ func init() {
|
||||
cli.CHECK: {Name: "check", Help: "检查", Hand: func(m *ice.Message, arg ...string) {
|
||||
if m.ProcessInner(); len(arg) > 0 {
|
||||
success := 0
|
||||
m.Cmd(m.PrefixKey(), arg[0]).Table(func(index int, value map[string]string, head []string) {
|
||||
m.Cmd(m.PrefixKey(), arg[0]).Tables(func(value map[string]string) {
|
||||
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 {
|
||||
@ -64,15 +60,13 @@ func init() {
|
||||
m.Info(`curl "` + m.Option(cli.API) + `" -H "Content-Type: application/json"` + ` -d '` + m.Option(ice.ARG) + `'`)
|
||||
m.ProcessDisplay("/plugin/story/json.js")
|
||||
}},
|
||||
}, mdb.ZoneAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
}, mdb.ZoneAction(mdb.SHORT, mdb.ZONE, mdb.FIELD, "time,id,name,cmd,api,arg,res")), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
m.Cmdy(web.SPIDE)
|
||||
m.Action(mdb.CREATE)
|
||||
m.RenameAppend("client.name", "dev")
|
||||
m.RenameAppend("client.url", "address")
|
||||
m.Cmdy(web.SPIDE).RenameAppend("client.name", "dev", "client.url", "address").Action(mdb.CREATE)
|
||||
return
|
||||
}
|
||||
|
||||
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)
|
||||
@ -80,7 +74,6 @@ func init() {
|
||||
m.Action(mdb.INSERT, cli.CHECK)
|
||||
m.PushAction(ice.RUN, cli.CHECK)
|
||||
}
|
||||
m.StatusTimeCount()
|
||||
}},
|
||||
"test": {Name: "test path func auto run case", Help: "测试用例", Action: map[string]*ice.Action{
|
||||
"run": {Name: "run", Help: "运行", Hand: func(m *ice.Message, arg ...string) {
|
||||
@ -94,7 +87,7 @@ func init() {
|
||||
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.Table(func(index int, value map[string]string, head []string) {
|
||||
msg.Tables(func(value map[string]string) {
|
||||
if strings.HasPrefix(strings.TrimSpace(value["line"]), "//") {
|
||||
return
|
||||
}
|
||||
|
@ -8,21 +8,20 @@ publish.go
|
||||
upgrade.go
|
||||
install.go
|
||||
|
||||
favor.go
|
||||
inner.go
|
||||
vimer.go
|
||||
favor.go
|
||||
bench.go
|
||||
pprof.go
|
||||
case.go
|
||||
|
||||
c.go
|
||||
js.go
|
||||
go.go
|
||||
sh.go
|
||||
go.go
|
||||
js.go
|
||||
shy.go
|
||||
|
||||
python.go
|
||||
python.shy
|
||||
case.go
|
||||
code.go
|
||||
code.shy
|
||||
|
||||
sess.go
|
||||
template.go
|
||||
|
@ -9,17 +9,14 @@ import (
|
||||
const FAVOR = "favor"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
||||
FAVOR: {Name: FAVOR, Help: "收藏夹", Value: kit.Data(mdb.SHORT, mdb.ZONE, mdb.FIELD, "time,id,type,name,text,path,file,line")},
|
||||
}, Commands: map[string]*ice.Command{
|
||||
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
|
||||
FAVOR: {Name: "favor zone id auto insert", Help: "收藏夹", Action: ice.MergeAction(map[string]*ice.Action{
|
||||
mdb.INSERT: {Name: "insert zone=数据结构 type=go name=hi text=hello path file line", Help: "添加"},
|
||||
INNER: {Name: "inner", Help: "源码", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.ProcessCommand(INNER, m.OptionSplit("path,file,line"), arg...)
|
||||
}},
|
||||
}, mdb.ZoneAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
mdb.ZoneSelect(m, arg...)
|
||||
m.PushAction(kit.Select(mdb.REMOVE, INNER, len(arg) > 0))
|
||||
}, mdb.ZoneAction(mdb.SHORT, mdb.ZONE, mdb.FIELD, "time,id,type,name,text,path,file,line")), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
mdb.ZoneSelect(m, arg...).PushAction(kit.Select(mdb.REMOVE, INNER, len(arg) > 0))
|
||||
}},
|
||||
}})
|
||||
}
|
||||
|
@ -52,17 +52,13 @@ func _go_help(m *ice.Message, key string) {
|
||||
}
|
||||
}
|
||||
func _go_find(m *ice.Message, key string, dir string) {
|
||||
m.Cmd(nfs.FIND, dir, key).Table(func(index int, value map[string]string, head []string) {
|
||||
m.PushSearch(nfs.LINE, 1, value)
|
||||
})
|
||||
m.Cmd(nfs.FIND, dir, key).Tables(func(value map[string]string) { m.PushSearch(nfs.LINE, 1, value) })
|
||||
}
|
||||
func _go_grep(m *ice.Message, key string, dir string) {
|
||||
m.Cmd(nfs.GREP, dir, key).Table(func(index int, value map[string]string, head []string) {
|
||||
m.PushSearch(value)
|
||||
})
|
||||
m.Cmd(nfs.GREP, dir, key).Tables(func(value map[string]string) { m.PushSearch(value) })
|
||||
}
|
||||
func _go_exec(m *ice.Message, arg ...string) {
|
||||
if key, ok := ice.Info.File[path.Join(arg[2], arg[1])]; ok && key != "" {
|
||||
if key := ice.GetFileKey(path.Join(arg[2], arg[1])); key != "" {
|
||||
m.Cmdy(cli.SYSTEM, GO, ice.RUN, ice.SRC_MAIN_GO, key)
|
||||
} else if m.Option(cli.CMD_DIR, arg[2]); strings.HasSuffix(arg[1], "_test.go") {
|
||||
m.Cmdy(cli.SYSTEM, GO, "test", "-v", nfs.PWD+arg[1])
|
||||
@ -77,47 +73,43 @@ func _go_show(m *ice.Message, arg ...string) {
|
||||
PACKAGE = "package"
|
||||
IMPORT = "import"
|
||||
)
|
||||
block := ""
|
||||
index := 0
|
||||
push := func(repos string) {
|
||||
index++
|
||||
m.Push("index", index)
|
||||
m.Push("repos", repos)
|
||||
}
|
||||
m.Cmd(nfs.CAT, path.Join(arg[2], arg[1]), func(line string) {
|
||||
ls := kit.Split(line)
|
||||
block := ""
|
||||
m.Cmd(nfs.CAT, path.Join(arg[2], arg[1]), func(ls []string, line string) {
|
||||
switch {
|
||||
case strings.HasPrefix(line, IMPORT+" ("):
|
||||
block = IMPORT
|
||||
return
|
||||
case strings.HasPrefix(line, ")"):
|
||||
block = ""
|
||||
return
|
||||
case strings.HasPrefix(line, IMPORT):
|
||||
if len(ls) == 2 {
|
||||
push(ls[1])
|
||||
} else if len(ls) == 3 {
|
||||
push(ls[2])
|
||||
}
|
||||
return
|
||||
}
|
||||
switch block {
|
||||
case IMPORT:
|
||||
if len(ls) == 0 {
|
||||
push("")
|
||||
} else if len(ls) == 1 {
|
||||
push(ls[0])
|
||||
} else if len(ls) == 2 {
|
||||
push(ls[1])
|
||||
default:
|
||||
if block == IMPORT {
|
||||
if len(ls) == 0 {
|
||||
push("")
|
||||
} else if len(ls) == 1 {
|
||||
push(ls[0])
|
||||
} else if len(ls) == 2 {
|
||||
push(ls[1])
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
if key, ok := ice.Info.File[path.Join(arg[2], arg[1])]; ok && key != "" {
|
||||
m.ProcessCommand(key, kit.Simple())
|
||||
} else {
|
||||
m.ProcessCommand("web.wiki.word", kit.Simple(strings.ReplaceAll(path.Join(arg[2], arg[1]), ".go", ".shy")))
|
||||
if key := ice.GetFileKey(path.Join(arg[2], arg[1])); key != "" {
|
||||
m.ProcessCommand(key, kit.Simple())
|
||||
} else {
|
||||
m.ProcessCommand("web.wiki.word", kit.Simple(strings.ReplaceAll(path.Join(arg[2], arg[1]), ".go", ".shy")))
|
||||
}
|
||||
}
|
||||
}
|
||||
func _mod_show(m *ice.Message, file string) {
|
||||
@ -131,35 +123,30 @@ func _mod_show(m *ice.Message, file string) {
|
||||
block := ""
|
||||
require := map[string]string{}
|
||||
replace := map[string]string{}
|
||||
m.Cmd(nfs.CAT, file, func(line string) {
|
||||
ls := kit.Split(line)
|
||||
m.Cmd(nfs.CAT, file, func(ls []string, line string) {
|
||||
switch {
|
||||
case strings.HasPrefix(line, MODULE):
|
||||
require[ls[1]] = ""
|
||||
replace[ls[1]] = nfs.PWD
|
||||
return
|
||||
case strings.HasPrefix(line, REQUIRE+" ("):
|
||||
block = REQUIRE
|
||||
return
|
||||
case strings.HasPrefix(line, REPLACE+" ("):
|
||||
block = REPLACE
|
||||
return
|
||||
case strings.HasPrefix(line, ")"):
|
||||
block = ""
|
||||
return
|
||||
case strings.HasPrefix(line, REQUIRE):
|
||||
require[ls[1]] = ls[2]
|
||||
case strings.HasPrefix(line, REPLACE):
|
||||
replace[ls[1]] = ls[3]
|
||||
}
|
||||
if block == "" || len(ls) < 2 {
|
||||
return
|
||||
}
|
||||
switch block {
|
||||
case REQUIRE:
|
||||
require[ls[0]] = ls[1]
|
||||
case REPLACE:
|
||||
replace[ls[0]] = ls[2]
|
||||
default:
|
||||
if len(ls) > 1 {
|
||||
switch block {
|
||||
case REQUIRE:
|
||||
require[ls[0]] = ls[1]
|
||||
case REPLACE:
|
||||
replace[ls[0]] = ls[2]
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
for k, v := range require {
|
||||
@ -235,6 +222,9 @@ func init() {
|
||||
"switch", "case", "default", "fallthrough",
|
||||
"go", "select", "defer", "return", "panic", "recover",
|
||||
),
|
||||
CONSTANT, kit.Simple(
|
||||
"false", "true", "nil", "-1", "0", "1", "2",
|
||||
),
|
||||
DATATYPE, kit.Simple(
|
||||
"int", "int32", "int64", "float64",
|
||||
"string", "byte", "bool", "error", "chan", "map",
|
||||
@ -243,9 +233,6 @@ func init() {
|
||||
"init", "main", "print",
|
||||
"new", "make", "len", "cap", "copy", "append", "delete", "msg", "m",
|
||||
),
|
||||
CONSTANT, kit.Simple(
|
||||
"false", "true", "nil", "-1", "0", "1", "2",
|
||||
),
|
||||
), KEYWORD, kit.Dict(),
|
||||
))},
|
||||
}}, nil)
|
||||
|
@ -23,23 +23,22 @@ func _inner_list(m *ice.Message, ext, file, dir string, arg ...string) {
|
||||
_inner_show(m, ext, file, dir, arg...)
|
||||
}
|
||||
}
|
||||
func _inner_exec(m *ice.Message, ext, file, dir string, arg ...string) {
|
||||
if !m.Right(dir, file) {
|
||||
return // 没有权限
|
||||
}
|
||||
if m.Cmdy(mdb.ENGINE, ext, file, dir, arg); m.Result() != "" {
|
||||
return // 执行成功
|
||||
}
|
||||
if ls := kit.Simple(m.Configv(kit.Keys(EXEC, ext))); len(ls) > 0 {
|
||||
m.Cmdy(cli.SYSTEM, ls, file, ice.Option{cli.CMD_DIR, dir})
|
||||
}
|
||||
}
|
||||
func _inner_show(m *ice.Message, ext, file, dir string, arg ...string) {
|
||||
if !m.Right(dir, file) {
|
||||
return // 没有权限
|
||||
}
|
||||
if m.Cmdy(mdb.RENDER, ext, file, dir, arg); m.Result() != "" {
|
||||
return // 解析成功
|
||||
m.Cmdy(mdb.RENDER, ext, file, dir, arg)
|
||||
}
|
||||
func _inner_exec(m *ice.Message, ext, file, dir string, arg ...string) {
|
||||
if !m.Right(dir, file) {
|
||||
return // 没有权限
|
||||
}
|
||||
defer m.StatusTime()
|
||||
if m.Cmdy(mdb.ENGINE, ext, file, dir, arg); m.Result() != "" {
|
||||
return // 执行成功
|
||||
}
|
||||
if ls := kit.Simple(m.Configv(kit.Keys(EXEC, ext))); len(ls) > 0 {
|
||||
m.Cmdy(cli.SYSTEM, ls, file, kit.Dict(cli.CMD_DIR, dir)).SetAppend()
|
||||
}
|
||||
}
|
||||
func _inner_make(m *ice.Message, msg *ice.Message) {
|
||||
@ -69,21 +68,20 @@ func LoadPlug(m *ice.Message, language ...string) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func PlugAction(fields ...string) map[string]*ice.Action {
|
||||
return ice.SelectAction(map[string]*ice.Action{
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(nfs.CAT, path.Join(arg[2], arg[1])) }},
|
||||
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(nfs.CAT, path.Join(arg[2], arg[1])) }},
|
||||
mdb.PLUGIN: {Hand: func(m *ice.Message, arg ...string) { m.Echo(m.Config(PLUG)) }},
|
||||
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(nfs.CAT, path.Join(arg[2], arg[1])) }},
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(nfs.CAT, path.Join(arg[2], arg[1])) }},
|
||||
}, fields...)
|
||||
}
|
||||
|
||||
const (
|
||||
COMMENT = "comment"
|
||||
KEYWORD = "keyword"
|
||||
CONSTANT = "constant"
|
||||
DATATYPE = "datatype"
|
||||
FUNCTION = "function"
|
||||
CONSTANT = "constant"
|
||||
)
|
||||
const (
|
||||
SPLIT = "split"
|
||||
@ -92,19 +90,31 @@ const (
|
||||
)
|
||||
const (
|
||||
PLUG = "plug"
|
||||
EXEC = "exec"
|
||||
SHOW = "show"
|
||||
EXEC = "exec"
|
||||
)
|
||||
const INNER = "inner"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
|
||||
INNER: {Name: "inner path=src/@key file=main.go line=1 auto", Help: "源代码", Meta: kit.Dict(ice.DisplayLocal("")), Action: ice.MergeAction(map[string]*ice.Action{
|
||||
mdb.PLUGIN: {Name: "plugin", Help: "插件", Hand: func(m *ice.Message, arg ...string) {
|
||||
if m.Cmdy(mdb.PLUGIN, arg); m.Result() == "" {
|
||||
m.Echo(kit.Select("{}", m.Config(kit.Keys(PLUG, arg[0]))))
|
||||
}
|
||||
m.Set(ice.MSG_STATUS)
|
||||
}},
|
||||
mdb.RENDER: {Name: "render", Help: "渲染", Hand: func(m *ice.Message, arg ...string) {
|
||||
_inner_show(m, arg[0], arg[1], arg[2])
|
||||
}},
|
||||
mdb.ENGINE: {Name: "engine", Help: "引擎", Hand: func(m *ice.Message, arg ...string) {
|
||||
_inner_exec(m, arg[0], arg[1], arg[2])
|
||||
}},
|
||||
mdb.SEARCH: {Name: "search", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Option(nfs.DIR_ROOT, arg[2])
|
||||
m.Option(cli.CMD_DIR, kit.Path(arg[2]))
|
||||
m.Cmdy(mdb.SEARCH, arg[0], arg[1], arg[2])
|
||||
m.Cmd(FAVOR, arg[1], ice.OptionFields("")).Table(func(index int, value map[string]string, head []string) {
|
||||
m.Cmd(FAVOR, arg[1], ice.OptionFields("")).Tables(func(value map[string]string) {
|
||||
if p := path.Join(value[nfs.PATH], value[nfs.FILE]); strings.HasPrefix(p, m.Option(nfs.PATH)) {
|
||||
m.Push(nfs.FILE, strings.TrimPrefix(p, m.Option(nfs.PATH)))
|
||||
m.Push(nfs.LINE, value[nfs.LINE])
|
||||
@ -115,27 +125,6 @@ func init() {
|
||||
m.Cmdy(INNER, nfs.GREP, arg[1])
|
||||
}
|
||||
}},
|
||||
mdb.PLUGIN: {Name: "plugin", Help: "插件", Hand: func(m *ice.Message, arg ...string) {
|
||||
if m.Cmdy(mdb.PLUGIN, arg); m.Result() == "" {
|
||||
m.Echo(kit.Select("{}", m.Config(kit.Keys(PLUG, arg[0]))))
|
||||
}
|
||||
m.Set(ice.MSG_STATUS)
|
||||
}},
|
||||
mdb.ENGINE: {Name: "engine", Help: "引擎", Hand: func(m *ice.Message, arg ...string) {
|
||||
_inner_exec(m, arg[0], arg[1], arg[2])
|
||||
}},
|
||||
mdb.RENDER: {Name: "render", Help: "渲染", Hand: func(m *ice.Message, arg ...string) {
|
||||
_inner_show(m, arg[0], arg[1], arg[2])
|
||||
}},
|
||||
nfs.TAGS: {Name: "tags", Help: "索引", Hand: func(m *ice.Message, arg ...string) {
|
||||
}},
|
||||
nfs.GREP: {Name: "grep", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(nfs.GREP, m.Option(nfs.PATH), arg[0])
|
||||
m.StatusTimeCount(mdb.INDEX, 0)
|
||||
}},
|
||||
cli.MAKE: {Name: "make", Help: "构建", Hand: func(m *ice.Message, arg ...string) {
|
||||
_inner_make(m, m.Cmd(cli.SYSTEM, cli.MAKE, arg))
|
||||
}},
|
||||
mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
|
||||
if m.Option(ctx.ACTION) == "website" {
|
||||
switch arg[0] {
|
||||
@ -147,16 +136,13 @@ func init() {
|
||||
|
||||
switch arg[0] {
|
||||
case cli.MAIN:
|
||||
m.Option(nfs.DIR_REG, "*.go")
|
||||
m.Cmdy(nfs.DIR, "src/", nfs.DIR_CLI_FIELDS).ProcessAgain()
|
||||
m.Cmdy(nfs.DIR, ice.SRC, nfs.DIR_CLI_FIELDS, kit.Dict(nfs.DIR_REG, `.*\.go`)).ProcessAgain()
|
||||
case nfs.PATH:
|
||||
m.Cmdy(nfs.DIR, arg[1:], nfs.DIR_CLI_FIELDS).ProcessAgain()
|
||||
case nfs.FILE:
|
||||
p := kit.Select(nfs.PWD, arg, 1)
|
||||
if !strings.HasSuffix(p, ice.FS) {
|
||||
p = path.Dir(p)
|
||||
}
|
||||
m.Cmdy(nfs.DIR, p+ice.PS, nfs.DIR_CLI_FIELDS, kit.Dict(nfs.DIR_ROOT, m.Option(nfs.PATH))).ProcessAgain()
|
||||
m.Option(nfs.DIR_ROOT, m.Option(nfs.PATH))
|
||||
m.Cmdy(nfs.DIR, kit.Select(path.Dir(p), p, strings.HasSuffix(p, ice.FS))+ice.PS, nfs.DIR_CLI_FIELDS).ProcessAgain()
|
||||
case "url":
|
||||
m.Option(nfs.DIR_ROOT, "usr/volcanos/plugin/local/code/")
|
||||
m.Cmdy(nfs.DIR, nfs.PWD, nfs.DIR_CLI_FIELDS, kit.Dict(nfs.DIR_DEEP, ice.TRUE)).ProcessAgain()
|
||||
@ -164,10 +150,18 @@ func init() {
|
||||
m.Cmdy(FAVOR, mdb.INPUTS, arg)
|
||||
}
|
||||
}},
|
||||
|
||||
nfs.TAGS: {Name: "tags", Help: "索引", Hand: func(m *ice.Message, arg ...string) {}},
|
||||
nfs.GREP: {Name: "grep", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(nfs.GREP, m.Option(nfs.PATH), arg[0])
|
||||
m.StatusTimeCount(mdb.INDEX, 0)
|
||||
}},
|
||||
cli.MAKE: {Name: "make", Help: "构建", Hand: func(m *ice.Message, arg ...string) {
|
||||
_inner_make(m, m.Cmd(cli.SYSTEM, cli.MAKE, arg))
|
||||
}},
|
||||
FAVOR: {Name: "favor", Help: "收藏"},
|
||||
}, ctx.CmdAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
arg[0] = strings.Split(arg[0], ice.FS)[0]
|
||||
if !strings.HasSuffix(arg[0], ice.PS) {
|
||||
if arg[0] = strings.Split(arg[0], ice.FS)[0]; !strings.HasSuffix(arg[0], ice.PS) {
|
||||
arg[1] = kit.Slice(strings.Split(arg[0], ice.PS), -1)[0]
|
||||
arg[0] = strings.TrimSuffix(arg[0], arg[1])
|
||||
m.ProcessRewrite(nfs.PATH, arg[0], nfs.FILE, arg[1])
|
||||
@ -177,11 +171,20 @@ func init() {
|
||||
nfs.Dir(m, nfs.PATH)
|
||||
return
|
||||
}
|
||||
arg[1] = strings.Split(arg[1], ice.FS)[0]
|
||||
if m.Option(ice.POD) == "" {
|
||||
m.Option("plug", "web.chat.website,web.dream")
|
||||
|
||||
list := kit.Simple()
|
||||
for k, v := range ice.Info.File {
|
||||
if strings.HasPrefix(k, path.Dir(path.Join(m.Option(nfs.PATH), m.Option(nfs.FILE)))) {
|
||||
list = append(list, v)
|
||||
}
|
||||
}
|
||||
m.Option("keys", list)
|
||||
m.Option("module", ice.Info.Make.Module)
|
||||
|
||||
m.Option("plug", "web.chat.website,web.dream")
|
||||
m.Option("exts", "inner/search.js?a=1,inner/favor.js,inner/template.js")
|
||||
|
||||
arg[1] = strings.Split(arg[1], ice.FS)[0]
|
||||
if _inner_list(m, kit.Ext(arg[1]), arg[1], arg[0]); m.IsErrNotFound() {
|
||||
m.SetResult("")
|
||||
}
|
||||
@ -189,56 +192,18 @@ func init() {
|
||||
}},
|
||||
}, Configs: map[string]*ice.Config{
|
||||
INNER: {Name: "inner", Help: "源代码", Value: kit.Data(
|
||||
EXEC, kit.Dict(
|
||||
"py", []string{"python"},
|
||||
"js", []string{"node"},
|
||||
),
|
||||
EXEC, kit.Dict("js", []string{"node"}, "py", []string{"python"}),
|
||||
PLUG, kit.Dict(
|
||||
"s", kit.Dict(
|
||||
PREFIX, kit.Dict("//", COMMENT),
|
||||
KEYWORD, kit.Dict(
|
||||
"TEXT", KEYWORD,
|
||||
"RET", KEYWORD,
|
||||
),
|
||||
),
|
||||
"S", kit.Dict(
|
||||
PREFIX, kit.Dict("//", COMMENT),
|
||||
KEYWORD, kit.Dict(),
|
||||
),
|
||||
"py", kit.Dict(
|
||||
PREFIX, kit.Dict("#", COMMENT),
|
||||
KEYWORD, kit.Dict("print", KEYWORD),
|
||||
),
|
||||
nfs.HTML, kit.Dict(
|
||||
SPLIT, kit.Dict(
|
||||
"space", " ",
|
||||
"operator", "<>",
|
||||
),
|
||||
KEYWORD, kit.Dict(
|
||||
"head", KEYWORD,
|
||||
"body", KEYWORD,
|
||||
),
|
||||
),
|
||||
nfs.CSS, kit.Dict(
|
||||
SUFFIX, kit.Dict("{", COMMENT),
|
||||
),
|
||||
"yaml", kit.Dict(
|
||||
PREFIX, kit.Dict("#", COMMENT),
|
||||
),
|
||||
"yml", kit.Dict(
|
||||
PREFIX, kit.Dict("#", COMMENT),
|
||||
),
|
||||
"S", kit.Dict(PREFIX, kit.Dict("//", COMMENT)),
|
||||
"s", kit.Dict(PREFIX, kit.Dict("//", COMMENT), KEYWORD, kit.Dict("TEXT", KEYWORD, "RET", KEYWORD)),
|
||||
"py", kit.Dict(PREFIX, kit.Dict("#", COMMENT), KEYWORD, kit.Dict("print", KEYWORD)),
|
||||
nfs.HTML, kit.Dict(SPLIT, kit.Dict("space", " ", "operator", "<>"), KEYWORD, kit.Dict("head", KEYWORD, "body", KEYWORD)),
|
||||
nfs.CSS, kit.Dict(SUFFIX, kit.Dict("{", COMMENT)),
|
||||
"yaml", kit.Dict(PREFIX, kit.Dict("#", COMMENT)),
|
||||
"yml", kit.Dict(PREFIX, kit.Dict("#", COMMENT)),
|
||||
|
||||
"md", kit.Dict(),
|
||||
"makefile", kit.Dict(
|
||||
PREFIX, kit.Dict("#", COMMENT),
|
||||
SUFFIX, kit.Dict(":", COMMENT),
|
||||
KEYWORD, kit.Dict(
|
||||
"ifeq", KEYWORD,
|
||||
"ifneq", KEYWORD,
|
||||
"else", KEYWORD,
|
||||
"endif", KEYWORD,
|
||||
),
|
||||
"makefile", kit.Dict(PREFIX, kit.Dict("#", COMMENT), SUFFIX, kit.Dict(":", COMMENT),
|
||||
KEYWORD, kit.Dict("ifeq", KEYWORD, "ifneq", KEYWORD, "else", KEYWORD, "endif", KEYWORD),
|
||||
),
|
||||
),
|
||||
)},
|
||||
|
@ -2,6 +2,7 @@ package code
|
||||
|
||||
import (
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
@ -31,6 +32,23 @@ func init() {
|
||||
}
|
||||
LoadPlug(m, JS)
|
||||
}},
|
||||
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) {
|
||||
key := ice.GetFileKey(kit.Replace(path.Join(arg[2], arg[1]), ".js", ".go"))
|
||||
if key == "" {
|
||||
for p, k := range ice.Info.File {
|
||||
if strings.HasPrefix(p, path.Dir(path.Join(arg[2], arg[1]))) {
|
||||
key = k
|
||||
}
|
||||
}
|
||||
}
|
||||
m.Display(path.Join("/require", ice.Info.Make.Module, path.Join(arg[2], arg[1])))
|
||||
m.ProcessCommand(kit.Select("can.code.inner.plugin", key), kit.Simple())
|
||||
}},
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(cli.SYSTEM, NODE, "-e", kit.Format(`global.plugin = "%s", require("%s")`,
|
||||
kit.Path(arg[2], arg[1]), kit.Path("usr/volcanos/proto.js"))).SetAppend()
|
||||
m.Echo(ice.NL)
|
||||
}},
|
||||
mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if arg[0] == mdb.FOREACH {
|
||||
return
|
||||
@ -38,19 +56,6 @@ func init() {
|
||||
_go_find(m, kit.Select(cli.MAIN, arg, 1), arg[2])
|
||||
_go_grep(m, kit.Select(cli.MAIN, arg, 1), arg[2])
|
||||
}},
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(cli.SYSTEM, NODE, arg[1], kit.Dict(cli.CMD_DIR, arg[2])).SetAppend()
|
||||
}},
|
||||
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if key, ok := ice.Info.File[kit.Replace(path.Join(arg[2], arg[1]), ".js", ".go")]; ok && key != "" {
|
||||
m.Display(path.Join(web.SHARE_LOCAL, path.Join(arg[2], arg[1])))
|
||||
m.ProcessCommand(key, kit.Simple())
|
||||
} else {
|
||||
m.Display(path.Join(web.SHARE_LOCAL, path.Join(arg[2], arg[1])))
|
||||
m.ProcessCommand("can.code.inner.plugin", kit.Simple())
|
||||
// m.ProcessCommand("web.wiki.word", kit.Simple(strings.ReplaceAll(path.Join(arg[2], arg[1]), ".go", ".shy")))
|
||||
}
|
||||
}},
|
||||
}, PlugAction())},
|
||||
NODE: {Name: "node auto download", Help: "前端", Action: map[string]*ice.Action{
|
||||
web.DOWNLOAD: {Name: "download", Help: "下载", Hand: func(m *ice.Message, arg ...string) {
|
||||
@ -62,24 +67,28 @@ func init() {
|
||||
nfs.SOURCE, "https://nodejs.org/dist/v10.13.0/node-v10.13.0-linux-x64.tar.xz",
|
||||
)},
|
||||
JS: {Name: JS, Help: "js", Value: kit.Data(PLUG, kit.Dict(
|
||||
mdb.RENDER, kit.Dict(),
|
||||
SPLIT, kit.Dict("space", " \t", "operator", "{[(&.,;!|<>)]}"),
|
||||
PREFIX, kit.Dict("//", COMMENT, "/*", COMMENT, "*", COMMENT), PREPARE, kit.Dict(
|
||||
KEYWORD, kit.Simple(
|
||||
"import", "from", "export",
|
||||
|
||||
"var", "new", "delete", "typeof", "const", "function",
|
||||
|
||||
"if", "else", "for", "while", "break", "continue", "switch", "case", "default",
|
||||
"return", "try", "throw", "catch", "finally",
|
||||
|
||||
"can", "sub", "msg", "res", "target",
|
||||
),
|
||||
FUNCTION, kit.Simple(
|
||||
|
||||
"window",
|
||||
"console",
|
||||
"document",
|
||||
"arguments",
|
||||
"event",
|
||||
),
|
||||
CONSTANT, kit.Simple(
|
||||
"true", "false",
|
||||
"undefined", "null",
|
||||
"-1", "0", "1", "2", "10",
|
||||
),
|
||||
FUNCTION, kit.Simple(
|
||||
"arguments",
|
||||
"Date",
|
||||
"JSON",
|
||||
|
||||
@ -101,11 +110,6 @@ func init() {
|
||||
"pane",
|
||||
"plugin",
|
||||
),
|
||||
CONSTANT, kit.Simple(
|
||||
"true", "false",
|
||||
"undefined", "null",
|
||||
"-1", "0", "1", "2", "10",
|
||||
),
|
||||
), KEYWORD, kit.Dict(),
|
||||
))},
|
||||
}}, nil)
|
||||
|
@ -26,8 +26,7 @@ const PPROF = "pprof"
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
||||
PPROF: {Name: PPROF, Help: "性能分析", Value: kit.Data(
|
||||
mdb.SHORT, mdb.ZONE, mdb.FIELD, "time,id,text,file",
|
||||
PPROF, kit.List(GO, "tool", PPROF),
|
||||
mdb.SHORT, mdb.ZONE, mdb.FIELD, "time,id,text,file", PPROF, kit.List(GO, "tool", PPROF),
|
||||
)},
|
||||
}, Commands: map[string]*ice.Command{
|
||||
PPROF: {Name: "pprof zone id auto", Help: "性能分析", Action: ice.MergeAction(map[string]*ice.Action{
|
||||
@ -43,9 +42,9 @@ func init() {
|
||||
mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
|
||||
switch arg[0] {
|
||||
case BINNARY:
|
||||
m.Cmdy(nfs.DIR, "bin/", nfs.DIR_CLI_FIELDS).RenameAppend(nfs.PATH, BINNARY)
|
||||
m.Cmdy(nfs.DIR, ice.BIN, nfs.DIR_CLI_FIELDS).RenameAppend(nfs.PATH, BINNARY)
|
||||
case SERVICE:
|
||||
m.Cmd(web.SPIDE).Table(func(index int, value map[string]string, head []string) {
|
||||
m.Cmd(web.SPIDE).Tables(func(value map[string]string) {
|
||||
m.Push(SERVICE, kit.MergeURL2(value["client.url"], "/debug/pprof/profile"))
|
||||
})
|
||||
}
|
||||
@ -54,22 +53,17 @@ func init() {
|
||||
|
||||
ice.RUN: {Name: "run", Help: "执行", Hand: func(m *ice.Message, arg ...string) {
|
||||
msg := m.Cmd(web.SPIDE, ice.DEV, web.SPIDE_CACHE, web.SPIDE_GET, m.Option(SERVICE), SECONDS, m.Option(SECONDS))
|
||||
|
||||
cmd := kit.Simple(m.Configv(PPROF), "-text", m.Option(BINNARY), msg.Append(nfs.FILE))
|
||||
res := kit.Slice(strings.Split(m.Cmdx(cli.SYSTEM, cmd), ice.NL), 0, 20)
|
||||
|
||||
m.Cmd(mdb.INSERT, PPROF, "", mdb.ZONE, m.Option(mdb.ZONE),
|
||||
mdb.TEXT, strings.Join(res, ice.NL), nfs.FILE, msg.Append(nfs.FILE))
|
||||
m.Echo(strings.Join(res, ice.NL))
|
||||
m.ProcessInner()
|
||||
m.Option(mdb.TEXT, strings.Join(kit.Slice(strings.Split(m.Cmdx(cli.SYSTEM, cmd), ice.NL), 0, 20), ice.NL))
|
||||
m.Option(nfs.FILE, msg.Append(nfs.FILE))
|
||||
m.Cmd(mdb.INSERT, PPROF, "", m.OptionSimple("zone,text,file"))
|
||||
m.Echo(m.Option(mdb.TEXT)).ProcessInner()
|
||||
}},
|
||||
web.SERVE: {Name: "serve", Help: "展示", Hand: func(m *ice.Message, arg ...string) {
|
||||
u := kit.ParseURL(m.Option(ice.MSG_USERWEB))
|
||||
p := u.Hostname() + ":" + m.Cmdx(tcp.PORT, aaa.RIGHT)
|
||||
|
||||
m.Cmd(cli.DAEMON, m.Configv(PPROF), "-http="+p, m.Option(BINNARY), m.Option(nfs.FILE))
|
||||
m.Echo("http://%s/ui/top", p)
|
||||
m.ProcessInner()
|
||||
m.Echo("http://%s/ui/top", p).ProcessInner()
|
||||
}},
|
||||
}, mdb.ZoneAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Fields(len(arg), "time,zone,count,binnary,service,seconds", m.Config(mdb.FIELD))
|
||||
@ -79,7 +73,7 @@ func init() {
|
||||
return
|
||||
}
|
||||
|
||||
m.Table(func(index int, value map[string]string, head []string) {
|
||||
m.Tables(func(value map[string]string) {
|
||||
m.PushDownload(mdb.LINK, "pprof.pd.gz", value[nfs.FILE])
|
||||
m.PushButton(web.SERVE)
|
||||
})
|
||||
|
@ -90,7 +90,7 @@ func init() {
|
||||
kit.Select(kit.Select("80", "443", u.Scheme == "https"), strings.Split(u.Host, ice.DF), 1)))
|
||||
|
||||
if len(arg) == 0 {
|
||||
arg = append(arg, ice.CORE, ice.BASE)
|
||||
arg = append(arg, ice.MISC, ice.CORE, ice.BASE)
|
||||
}
|
||||
for _, k := range arg {
|
||||
if buf, err := kit.Render(m.Config(kit.Keys(ice.CONTEXTS, k)), m); m.Assert(err) {
|
||||
@ -139,12 +139,10 @@ func init() {
|
||||
}
|
||||
|
||||
var _contexts = kit.Dict(
|
||||
"misc", `# 终端环境
|
||||
"misc", `# 完整版
|
||||
export ctx_dev={{.Option "httphost"}}; ctx_temp=$(mktemp); curl -fsSL $ctx_dev -o $ctx_temp; source $ctx_temp dev
|
||||
export ctx_dev={{.Option "httphost"}}; ctx_temp=$(mktemp); wget -O $ctx_temp $ctx_dev; source $ctx_temp dev
|
||||
`,
|
||||
"core", `# 定制版
|
||||
export ctx_dev={{.Option "httphost"}}; ctx_temp=$(mktemp); curl -o $ctx_temp -fsSL $ctx_dev; source $ctx_temp app
|
||||
"core", `# 标准版
|
||||
export ctx_dev={{.Option "httphost"}}; ctx_temp=$(mktemp); wget -O $ctx_temp $ctx_dev; source $ctx_temp app
|
||||
`,
|
||||
"base", `# 官方版
|
||||
|
@ -1,34 +0,0 @@
|
||||
package code
|
||||
|
||||
import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
const PYTHON = "python"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
||||
PYTHON: {Name: PYTHON, Help: "脚本命令", Value: kit.Data(
|
||||
nfs.SOURCE, "http://mirrors.sohu.com/python/3.5.2/Python-3.5.2.tar.xz",
|
||||
PYTHON, "python", "pip", "pip",
|
||||
)},
|
||||
}, Commands: map[string]*ice.Command{
|
||||
PYTHON: {Name: "python path auto order build download", Help: "脚本命令", Action: ice.MergeAction(map[string]*ice.Action{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(mdb.ENGINE, mdb.CREATE, mdb.TYPE, "py", mdb.NAME, m.PrefixKey())
|
||||
}},
|
||||
ice.RUN: {Name: "run", Help: "运行", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(cli.SYSTEM, m.Config(PYTHON), arg)
|
||||
}},
|
||||
"pip": {Name: "pip", Help: "安装", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(cli.SYSTEM, m.Config("pip"), "install", arg)
|
||||
}},
|
||||
}, InstallAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Cmdy(INSTALL, nfs.SOURCE, m.Config(nfs.SOURCE), arg)
|
||||
}},
|
||||
}})
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
section "python"
|
||||
refer `
|
||||
官网 https://www.python.org/
|
||||
源码 https://www.python.org/downloads/source/
|
||||
文档 https://docs.python.org/3/reference/index.html
|
||||
`
|
||||
|
@ -2,14 +2,14 @@ package code
|
||||
|
||||
import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
|
||||
"sess": {Name: "sess hash auto save load", Help: "会话", Action: mdb.HashAction(
|
||||
mdb.FIELD, "time,hash,tabs,tool",
|
||||
"action", "load",
|
||||
mdb.FIELD, "time,hash,tabs,tool", ctx.ACTION, "load",
|
||||
)},
|
||||
}})
|
||||
}
|
||||
|
@ -18,6 +18,12 @@ func init() {
|
||||
}
|
||||
LoadPlug(m, SH)
|
||||
}},
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(cli.SYSTEM, SH, "-c", `#! /bin/sh
|
||||
|
||||
source `+arg[1]+`
|
||||
`, kit.Dict(cli.CMD_DIR, arg[2])).SetAppend()
|
||||
}},
|
||||
mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if arg[0] == mdb.FOREACH {
|
||||
return
|
||||
@ -28,15 +34,13 @@ func init() {
|
||||
_go_find(m, kit.Select(cli.MAIN, arg, 1), arg[2])
|
||||
_go_grep(m, kit.Select(cli.MAIN, arg, 1), arg[2])
|
||||
}},
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(cli.SYSTEM, SH, arg[1], kit.Dict(cli.CMD_DIR, arg[2])).SetAppend()
|
||||
}},
|
||||
MAN: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Echo(_c_help(m, arg[0], arg[1]))
|
||||
}},
|
||||
}, PlugAction())},
|
||||
}, Configs: map[string]*ice.Config{
|
||||
SH: {Name: SH, Help: "命令", Value: kit.Data(PLUG, kit.Dict(
|
||||
mdb.ENGINE, kit.Dict(),
|
||||
SPLIT, kit.Dict("space", " ", "operator", "{[(.,;!|<>)]}"),
|
||||
PREFIX, kit.Dict("#", COMMENT),
|
||||
SUFFIX, kit.Dict("{", COMMENT),
|
||||
|
@ -21,21 +21,22 @@ func init() {
|
||||
}
|
||||
LoadPlug(m, SHY)
|
||||
}},
|
||||
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.ProcessCommand("web.wiki.word", kit.Simple(path.Join(arg[2], arg[1])))
|
||||
}},
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(nfs.SOURCE, path.Join(arg[2], arg[1]), kit.Dict(ice.MSG_ALIAS, m.Confv("web.wiki.word", kit.Keym(mdb.ALIAS))))
|
||||
}},
|
||||
mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if arg[0] == SHY {
|
||||
_go_find(m, kit.Select(cli.MAIN, arg, 1), arg[2])
|
||||
_go_grep(m, kit.Select(cli.MAIN, arg, 1), arg[2])
|
||||
}
|
||||
}},
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(nfs.SOURCE, path.Join(arg[2], arg[1]), kit.Dict(ice.MSG_ALIAS, m.Confv("web.wiki.word", kit.Keym(mdb.ALIAS))))
|
||||
}},
|
||||
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.ProcessCommand("web.wiki.word", kit.Simple(path.Join(arg[2], arg[1])))
|
||||
}},
|
||||
}, PlugAction())},
|
||||
}, Configs: map[string]*ice.Config{
|
||||
SHY: {Name: SHY, Help: "脚本", Value: kit.Data(PLUG, kit.Dict(
|
||||
mdb.RENDER, kit.Dict(),
|
||||
PREFIX, kit.Dict("# ", COMMENT), PREPARE, kit.Dict(
|
||||
KEYWORD, kit.Simple(
|
||||
"source", "return",
|
||||
|
@ -10,25 +10,50 @@ import (
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
const TEMPLATE = "template"
|
||||
|
||||
func init() {
|
||||
const TEMPLATE = "template"
|
||||
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
|
||||
TEMPLATE: {Name: "template name auto create", Help: "模板", Action: ice.MergeAction(map[string]*ice.Action{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(TEMPLATE, mdb.CREATE, kit.SimpleKV("", "txt", "网站索引", `
|
||||
for _, _template := range _template_list {
|
||||
m.Cmd(TEMPLATE, mdb.CREATE, kit.SimpleKV(kit.Format(_template[0]), _template[1:]...))
|
||||
}
|
||||
}},
|
||||
mdb.CREATE: {Name: "create type name text args", Help: "创建"},
|
||||
nfs.DEFS: {Name: "defs file=hi/hi.go", Help: "生成", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Option("tags", "`"+m.Option("tags")+"`")
|
||||
if buf, err := kit.Render(m.Option(mdb.TEXT), m); !m.Warn(err) {
|
||||
switch m.Cmd(nfs.DEFS, path.Join(m.Option(nfs.PATH), m.Option(nfs.FILE)), string(buf)); kit.Ext(m.Option(nfs.FILE)) {
|
||||
case GO:
|
||||
if m.Option(cli.MAIN) != "" && m.Option(mdb.ZONE) != "" {
|
||||
_autogen_import(m, path.Join(m.Option(nfs.PATH), m.Option(cli.MAIN)), m.Option(mdb.ZONE), _autogen_mod(m, ice.GO_MOD))
|
||||
}
|
||||
}
|
||||
}
|
||||
}},
|
||||
}, mdb.HashAction(mdb.SHORT, mdb.NAME, mdb.FIELD, "time,type,name,text,args")), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
mdb.HashSelect(m, arg...).Sort(mdb.NAME).Cut("time,action,type,name,text,args")
|
||||
m.PushAction(nfs.DEFS, mdb.REMOVE)
|
||||
}}},
|
||||
})
|
||||
}
|
||||
|
||||
var _template_list = [][]interface{}{
|
||||
[]interface{}{"", "txt", "网站索引", `
|
||||
hi
|
||||
hi
|
||||
cli.qrcode
|
||||
cli.system
|
||||
cli.runtime
|
||||
|
||||
`))
|
||||
m.Cmd(TEMPLATE, mdb.CREATE, kit.SimpleKV("", "js", "前端模块", `Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, cb, target) {
|
||||
`},
|
||||
[]interface{}{"", "js", "前端模块", `Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, cb, target) {
|
||||
can.onmotion.clear(can)
|
||||
can.onappend.table(can, msg)
|
||||
can.onappend.board(can, msg)
|
||||
}})`))
|
||||
m.Cmd(TEMPLATE, mdb.CREATE, kit.SimpleKV("", "go", "后端模块", `package {{.Option "zone"}}
|
||||
}})`},
|
||||
[]interface{}{"", "go", "后端模块", `package {{.Option "zone"}}
|
||||
|
||||
import (
|
||||
"shylinux.com/x/ice"
|
||||
@ -45,33 +70,12 @@ func (h {{.Option "name"}}) List(m *ice.Message, arg ...string) {
|
||||
}
|
||||
|
||||
func init() { ice.Cmd("{{.Option "key"}}", {{.Option "name"}}{}) }
|
||||
`), "args", `[
|
||||
`, "args", `[
|
||||
{"name": "zone", "value": "hi"},
|
||||
{"name": "name", "value": "hi"},
|
||||
{"name": "key", "value": "web.code.hi.hi"},
|
||||
{"name": "type", "values": "Hash,Zone,List"},
|
||||
{"name": "tags", "value": "name:\"list hash id auto insert\" help:\"数据\""},
|
||||
{"name": "main", "value": "main.go"}
|
||||
]`)
|
||||
}},
|
||||
mdb.CREATE: {Name: "create type name text args", Help: "创建"},
|
||||
nfs.DEFS: {Name: "defs file=hi/hi.go", Help: "生成", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Option("tags", "`"+m.Option("tags")+"`")
|
||||
if buf, err := kit.Render(m.Option(mdb.TEXT), m); !m.Warn(err) {
|
||||
m.Cmd(nfs.DEFS, path.Join(m.Option(nfs.PATH), m.Option(nfs.FILE)), string(buf))
|
||||
switch kit.Ext(m.Option(nfs.FILE)) {
|
||||
case GO:
|
||||
if m.Option(cli.MAIN) != "" && m.Option(mdb.ZONE) != "" {
|
||||
_autogen_import(m, path.Join(m.Option(nfs.PATH), m.Option(cli.MAIN)), m.Option(mdb.ZONE), _autogen_mod(m, ice.GO_MOD))
|
||||
}
|
||||
}
|
||||
}
|
||||
}},
|
||||
}, mdb.HashAction(mdb.SHORT, "name", mdb.FIELD, "time,type,name,text,args")), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
mdb.HashSelect(m, arg...)
|
||||
m.PushAction(nfs.DEFS, mdb.REMOVE)
|
||||
m.Sort("name")
|
||||
m.Cut("time,action,type,name,text,args")
|
||||
}}},
|
||||
})
|
||||
]`},
|
||||
}
|
||||
|
@ -24,22 +24,25 @@ func init() {
|
||||
COMPILE: {Name: "compile", Help: "编译", Hand: func(m *ice.Message, arg ...string) {
|
||||
if msg := m.Cmd(COMPILE, ice.SRC_MAIN_GO, ice.BIN_ICE_BIN); !cli.IsSuccess(msg) {
|
||||
_inner_make(m, msg)
|
||||
return
|
||||
} else {
|
||||
m.Cmd(UPGRADE, cli.RESTART)
|
||||
}
|
||||
m.Go(func() { m.Sleep("1s", ice.EXIT, "1") })
|
||||
}},
|
||||
BINPACK: {Name: "binpack", Help: "打包", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(AUTOGEN, BINPACK)
|
||||
BINPACK: {Name: "binpack", Help: "打包模式", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(nfs.COPY, ice.GO_MOD, path.Join(ice.SRC_RELEASE, ice.GO_MOD))
|
||||
m.Cmd(nfs.COPY, ice.GO_SUM, path.Join(ice.SRC_RELEASE, ice.GO_SUM))
|
||||
m.Cmdy(nfs.CAT, ice.GO_MOD)
|
||||
m.Cmdy(AUTOGEN, BINPACK)
|
||||
m.ToastSuccess()
|
||||
m.ProcessInner()
|
||||
}},
|
||||
DEVPACK: {Name: "devpack", Help: "开发模式", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(nfs.COPY, ice.GO_MOD, path.Join(ice.SRC_DEBUG, ice.GO_MOD))
|
||||
m.Cmd(nfs.COPY, ice.GO_SUM, path.Join(ice.SRC_DEBUG, ice.GO_SUM))
|
||||
m.Cmdy(nfs.CAT, ice.GO_MOD)
|
||||
m.Cmdy(WEBPACK, mdb.REMOVE)
|
||||
m.ToastSuccess()
|
||||
m.ProcessHold()
|
||||
m.ProcessInner()
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Cmdy(INNER, arg) }},
|
||||
}})
|
||||
|
@ -43,11 +43,19 @@ func _webpack_cache(m *ice.Message, dir string, write bool) {
|
||||
return
|
||||
}
|
||||
|
||||
m.Option(nfs.DIR_ROOT, dir)
|
||||
m.Option(nfs.DIR_ROOT, "")
|
||||
m.Option(nfs.DIR_DEEP, true)
|
||||
m.Option(nfs.DIR_PACK, true)
|
||||
m.Option(nfs.DIR_TYPE, nfs.CAT)
|
||||
|
||||
m.Cmd(nfs.DIR, ice.SRC).Tables(func(value map[string]string) {
|
||||
if kit.Ext(value[nfs.PATH]) == JS {
|
||||
fmt.Fprintln(js, `_can_name = "`+path.Join("/require", ice.Info.Make.Module, value[nfs.PATH])+`"`)
|
||||
fmt.Fprintln(js, m.Cmdx(nfs.CAT, value[nfs.PATH]))
|
||||
}
|
||||
})
|
||||
|
||||
m.Option(nfs.DIR_ROOT, dir)
|
||||
for _, k := range []string{LIB, PANEL, PLUGIN} {
|
||||
m.Cmd(nfs.DIR, k).Tables(func(value map[string]string) {
|
||||
if kit.Ext(value[nfs.PATH]) == CSS {
|
||||
@ -69,6 +77,7 @@ func _webpack_cache(m *ice.Message, dir string, write bool) {
|
||||
fmt.Fprintln(js, `_can_name = "`+path.Join(ice.PS, k)+`"`)
|
||||
fmt.Fprintln(js, m.Cmdx(nfs.CAT, k))
|
||||
}
|
||||
|
||||
}
|
||||
func _webpack_build(m *ice.Message, file string) {
|
||||
if f, _, e := kit.Create(kit.Keys(file, JS)); m.Assert(e) {
|
||||
|
7
info.go
7
info.go
@ -10,6 +10,7 @@ import (
|
||||
type MakeInfo struct {
|
||||
Time string
|
||||
Hash string
|
||||
Module string
|
||||
Remote string
|
||||
Branch string
|
||||
Version string
|
||||
@ -54,6 +55,12 @@ source: https://shylinux.com/x/icebergs
|
||||
names: map[string]interface{}{},
|
||||
}
|
||||
|
||||
func AddFileKey(dir, key string) {
|
||||
Info.File[strings.TrimPrefix(dir, kit.Path("")+PS)] = key
|
||||
}
|
||||
func GetFileKey(dir string) string {
|
||||
return Info.File[strings.TrimPrefix(dir, kit.Path("")+PS)]
|
||||
}
|
||||
func Dump(w io.Writer, name string, cb func(string)) bool {
|
||||
for _, key := range []string{name, strings.TrimPrefix(name, USR_VOLCANOS)} {
|
||||
if b, ok := Info.Pack[key]; ok {
|
||||
|
2
init.go
2
init.go
@ -81,6 +81,8 @@ var Index = &Context{Name: "ice", Help: "冰山模块", Configs: map[string]*Con
|
||||
}},
|
||||
CTX_EXIT: {Hand: func(m *Message, c *Context, cmd string, arg ...string) {
|
||||
defer m.Cost(CTX_EXIT)
|
||||
m.Option("cmd_dir", "")
|
||||
m.Option("dir_root", "")
|
||||
m.root.Travel(func(p *Context, c *Context) {
|
||||
if cmd, ok := c.Commands[CTX_EXIT]; ok && p != nil {
|
||||
m.TryCatch(m.Spawn(c), true, func(msg *Message) {
|
||||
|
@ -267,6 +267,12 @@ func init() {
|
||||
_repos_cmd(m, m.Option(REPOS), TAG, m.Option(VERSION))
|
||||
_repos_cmd(m, m.Option(REPOS), PUSH, "--tags")
|
||||
}},
|
||||
code.BINPACK: {Name: "binpack", Help: "打包模式", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(code.VIMER, code.BINPACK)
|
||||
}},
|
||||
code.DEVPACK: {Name: "devpack", Help: "开发模式", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(code.VIMER, code.DEVPACK)
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
m.Action(PULL, MAKE, PUSH, TAGS, STASH, PIE)
|
||||
|
Loading…
x
Reference in New Issue
Block a user