forked from x/icebergs
opt code
This commit is contained in:
parent
9e8563071a
commit
9f3e99dcf7
@ -55,7 +55,7 @@ func _serve_main(m *ice.Message, w http.ResponseWriter, r *http.Request) bool {
|
||||
} else {
|
||||
r.Header.Set(ice.MSG_USERIP, strings.Split(r.RemoteAddr, ice.DF)[0])
|
||||
}
|
||||
if m.Logs(r.Method, r.Header.Get(ice.MSG_USERIP), r.URL.String()); m.Config(LOGHEADERS) == ice.TRUE {
|
||||
if m.Logs(r.Header.Get(ice.MSG_USERIP), r.Method, r.URL.String()); m.Config(LOGHEADERS) == ice.TRUE {
|
||||
kit.Fetch(r.Header, func(k string, v []string) { m.Logs("Header", k, v) })
|
||||
}
|
||||
if r.Method == http.MethodGet && r.URL.Path != PP(SPACE) {
|
||||
|
@ -40,13 +40,13 @@ func init() {
|
||||
H: {Name: "h path auto", Help: "系统编程", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { _c_show(m, arg...) }},
|
||||
NAVIGATE: {Hand: func(m *ice.Message, arg ...string) { _c_tags(m, MAN, "ctags", "-a", "-R", nfs.PWD) }},
|
||||
}, PlugAction(), LangAction())},
|
||||
}, PlugAction())},
|
||||
C: {Name: "c path auto", Help: "系统编程", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { _c_show(m, arg...) }},
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { _c_exec(m, arg...) }},
|
||||
NAVIGATE: {Hand: func(m *ice.Message, arg ...string) { _c_tags(m, MAN, "ctags", "-a", "-R", nfs.PWD) }},
|
||||
TEMPLATE: {Hand: func(m *ice.Message, arg ...string) { kit.If(arg[0] == C, func() { m.Echo(_c_template) }) }},
|
||||
}, PlugAction(), LangAction())},
|
||||
}, PlugAction())},
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -71,6 +71,6 @@ func init() {
|
||||
CSS: {Name: "css path auto", Help: "样式表", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { _css_show(m, arg...) }},
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { _css_exec(m, arg...) }},
|
||||
}, PlugAction(), LangAction())},
|
||||
}, PlugAction())},
|
||||
})
|
||||
}
|
||||
|
@ -61,7 +61,8 @@ func _go_exec(m *ice.Message, arg ...string) {
|
||||
}
|
||||
}
|
||||
func _go_show(m *ice.Message, arg ...string) {
|
||||
TagsList(m, "gotags", path.Join(m.Option(nfs.PATH), m.Option(nfs.FILE)))
|
||||
// TagsList(m, "gotags", path.Join(m.Option(nfs.PATH), m.Option(nfs.FILE)))
|
||||
TagsList(m, "gotags", path.Join(arg[2], arg[1]))
|
||||
}
|
||||
func _mod_show(m *ice.Message, file string) {
|
||||
const (
|
||||
@ -130,7 +131,7 @@ func init() {
|
||||
kit.If(arg[0] == GO, func() { m.Echo(_go_template, path.Base(path.Dir(path.Join(arg[2], arg[1])))) })
|
||||
}},
|
||||
NAVIGATE: {Hand: func(m *ice.Message, arg ...string) { _c_tags(m, GODOC, "gotags", "-f", nfs.TAGS, "-R", nfs.PWD) }},
|
||||
}, PlugAction(), LangAction())},
|
||||
}, PlugAction())},
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -101,25 +101,16 @@ func init() {
|
||||
mdb.PLUGIN: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(mdb.PLUGIN, arg) }},
|
||||
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { _inner_show(m, arg[0], arg[1], arg[2]) }},
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { _inner_exec(m, arg[0], arg[1], arg[2]) }},
|
||||
nfs.GREP: {Name: "grep", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
||||
nfs.GREP: {Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(nfs.GREP, arg[0], m.Option(nfs.PATH)).StatusTimeCount(mdb.INDEX, 0)
|
||||
}},
|
||||
nfs.TAGS: {Name: "tags", Help: "索引", Hand: func(m *ice.Message, arg ...string) {
|
||||
nfs.TAGS: {Help: "索引", Hand: func(m *ice.Message, arg ...string) {
|
||||
if _inner_tags(m, m.Option(nfs.PATH), arg[0]); m.Length() == 0 {
|
||||
_inner_tags(m, "", arg[0])
|
||||
}
|
||||
}},
|
||||
}}, FAVOR: {},
|
||||
NAVIGATE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(NAVIGATE, kit.Ext(m.Option(mdb.FILE)), m.Option(nfs.FILE), m.Option(nfs.PATH))
|
||||
}}, FAVOR: {},
|
||||
ctx.COMMAND: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if !ctx.PodCmd(m, ctx.COMMAND, arg) {
|
||||
m.Cmdy(ctx.COMMAND, arg)
|
||||
}
|
||||
if len(arg) == 2 && arg[0] == mdb.SEARCH && arg[1] == ctx.COMMAND {
|
||||
return
|
||||
}
|
||||
m.Cmd(FAVOR, mdb.INSERT, mdb.ZONE, "_recent_cmd", nfs.FILE, arg[0])
|
||||
}},
|
||||
}, ctx.CmdAction(), aaa.RoleAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
if arg[0] = strings.Split(arg[0], ice.FS)[0]; !strings.HasSuffix(arg[0], ice.PS) && len(arg) == 1 {
|
||||
@ -154,12 +145,9 @@ func init() {
|
||||
}
|
||||
}
|
||||
case nfs.SOURCE:
|
||||
m.Debug("what %v", cmd)
|
||||
if file := ctx.GetCmdFile(m, cmd); nfs.ExistsFile(m, file) {
|
||||
m.Debug("what %v", file)
|
||||
return process(m, file)
|
||||
}
|
||||
m.Debug("what %v", cmd)
|
||||
}
|
||||
return false
|
||||
})
|
||||
|
@ -122,7 +122,7 @@ func init() {
|
||||
m.Cmdy("web.code.vim.tags").Cut(mdb.ZONE)
|
||||
}
|
||||
}},
|
||||
}, PlugAction(), LangAction())},
|
||||
}, PlugAction())},
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -15,18 +15,16 @@ import (
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
const PPROF = "pprof"
|
||||
|
||||
func init() {
|
||||
const (
|
||||
BINNARY = "binnary"
|
||||
SERVICE = "service"
|
||||
SECONDS = "seconds"
|
||||
)
|
||||
|
||||
const PPROF = "pprof"
|
||||
|
||||
func init() {
|
||||
web.Index.MergeCommands(ice.Commands{"/debug/": {Hand: func(m *ice.Message, arg ...string) {
|
||||
web.Index.MergeCommands(ice.Commands{"/debug/": {Actions: aaa.WhiteAction(), Hand: func(m *ice.Message, arg ...string) {
|
||||
defer m.Render(ice.RENDER_VOID)
|
||||
m.R.URL.Path = "/debug" + m.R.URL.Path
|
||||
http.DefaultServeMux.ServeHTTP(m.W, m.R)
|
||||
}}})
|
||||
Index.MergeCommands(ice.Commands{
|
||||
@ -36,38 +34,32 @@ func init() {
|
||||
case BINNARY:
|
||||
m.Cmdy(nfs.DIR, ice.BIN, nfs.DIR_CLI_FIELDS).RenameAppend(nfs.PATH, BINNARY)
|
||||
case SERVICE:
|
||||
m.Cmd(web.SPIDE, func(value ice.Maps) {
|
||||
m.Push(SERVICE, kit.MergeURL2(value[web.CLIENT_URL], "/debug/pprof/profile"))
|
||||
})
|
||||
m.Cmd(web.SPIDE, func(value ice.Maps) { m.Push(SERVICE, kit.MergeURL2(value[web.CLIENT_URL], "/debug/pprof/profile")) })
|
||||
}
|
||||
}},
|
||||
mdb.CREATE: {Name: "create zone=some binnary=bin/ice.bin service='http://localhost:9020/debug/pprof/profile' seconds=3", Help: "创建"},
|
||||
|
||||
ice.RUN: {Name: "run", Help: "执行", Hand: func(m *ice.Message, arg ...string) {
|
||||
msg := m.Cmd(web.SPIDE, ice.DEV, web.SPIDE_CACHE, http.MethodGet, m.Option(SERVICE), SECONDS, m.Option(SECONDS))
|
||||
mdb.CREATE: {Name: "create zone*=some binnary*=bin/ice.bin service*='http://localhost:9020/debug/pprof/profile' seconds*=30"},
|
||||
cli.START: {Help: "启动", Hand: func(m *ice.Message, arg ...string) {
|
||||
if m.Option(BINNARY) == "" {
|
||||
return
|
||||
}
|
||||
msg := m.Cmd(web.SPIDE, ice.DEV, web.SPIDE_CACHE, http.MethodGet, m.Option(SERVICE), m.OptionSimple(SECONDS))
|
||||
cmd := kit.Simple(m.Configv(PPROF), "-text", m.Option(BINNARY), msg.Append(nfs.FILE))
|
||||
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))
|
||||
mdb.ZoneInsert(m, m.OptionSimple("zone,text,file"))
|
||||
mdb.ZoneInsert(m, m.OptionSimple("zone,text"), msg.AppendSimple(nfs.FILE))
|
||||
m.Echo(m.Option(mdb.TEXT)).ProcessInner()
|
||||
}},
|
||||
web.SERVE: {Name: "serve", Help: "展示", Hand: func(m *ice.Message, arg ...string) {
|
||||
web.SERVE: {Help: "展示", Hand: func(m *ice.Message, arg ...string) {
|
||||
u := web.OptionUserWeb(m)
|
||||
p := u.Hostname() + ice.DF + 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).ProcessInner()
|
||||
}},
|
||||
}, mdb.ZoneAction(mdb.SHORT, mdb.ZONE, mdb.FIELD, "time,id,text,file", PPROF, kit.List(GO, "tool", PPROF))), Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Fields(len(arg), "time,zone,count,binnary,service,seconds", mdb.ZoneField(m))
|
||||
}, mdb.ZoneAction(mdb.FIELDS, "time,zone,count,binnary,service,seconds", mdb.FIELD, "time,id,text,file", PPROF, kit.List(GO, "tool", PPROF))), Hand: func(m *ice.Message, arg ...string) {
|
||||
if mdb.ZoneSelect(m, arg...); len(arg) == 0 {
|
||||
m.EchoAnchor(web.MergeLink(m, "/code/pprof/"))
|
||||
m.PushAction(ice.RUN, mdb.REMOVE)
|
||||
m.Action(mdb.CREATE)
|
||||
m.EchoAnchor(web.MergeLink(m, "/debug/pprof/"))
|
||||
m.PushAction(cli.START, mdb.REMOVE).Action(mdb.CREATE)
|
||||
} else {
|
||||
m.Tables(func(value ice.Maps) {
|
||||
m.PushDownload(mdb.LINK, "pprof.pd.gz", value[nfs.FILE])
|
||||
m.PushButton(web.SERVE)
|
||||
})
|
||||
m.Tables(func(value ice.Maps) { m.PushDownload(mdb.LINK, "pprof.pd.gz", value[nfs.FILE]).PushButton(web.SERVE) })
|
||||
}
|
||||
}},
|
||||
})
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/tcp"
|
||||
@ -18,20 +19,15 @@ import (
|
||||
)
|
||||
|
||||
func _publish_file(m *ice.Message, file string, arg ...string) string {
|
||||
if strings.HasSuffix(file, ice.ICE_BIN) { // 打包应用
|
||||
arg = kit.Simple(kit.Keys(ice.ICE, runtime.GOOS, runtime.GOARCH))
|
||||
file = cli.SystemFind(m, os.Args[0])
|
||||
|
||||
if strings.HasSuffix(file, ice.ICE_BIN) {
|
||||
file, arg = cli.SystemFind(m, os.Args[0]), kit.Simple(kit.Keys(ice.ICE, runtime.GOOS, runtime.GOARCH))
|
||||
} else if s, e := nfs.StatFile(m, file); m.Assert(e) && s.IsDir() {
|
||||
file = m.Cmdx(nfs.TAR, mdb.IMPORT, path.Base(file), file)
|
||||
defer func() { nfs.Remove(m, file) }()
|
||||
}
|
||||
|
||||
// 发布文件
|
||||
target := path.Join(ice.USR_PUBLISH, kit.Select(path.Base(file), arg, 0))
|
||||
m.Logs(mdb.EXPORT, PUBLISH, target, cli.FROM, file)
|
||||
m.Cmd(nfs.LINK, target, file)
|
||||
return target
|
||||
return m.Cmdx(nfs.LINK, target, file)
|
||||
}
|
||||
func _publish_list(m *ice.Message, arg ...string) {
|
||||
m.Option(nfs.DIR_REG, kit.Select("", arg, 0))
|
||||
@ -42,11 +38,8 @@ func _publish_bin_list(m *ice.Message, dir string) {
|
||||
for _, ls := range strings.Split(cli.SystemCmds(m, "ls |xargs file |grep executable"), ice.NL) {
|
||||
if file := strings.TrimSpace(strings.Split(ls, ice.DF)[0]); file != "" {
|
||||
if s, e := nfs.StatFile(m, path.Join(p, file)); e == nil {
|
||||
m.Push(mdb.TIME, s.ModTime())
|
||||
m.Push(nfs.SIZE, kit.FmtSize(s.Size()))
|
||||
m.Push(nfs.PATH, file)
|
||||
m.PushDownload(mdb.LINK, file, path.Join(p, file))
|
||||
m.PushButton(nfs.TRASH)
|
||||
m.Push(mdb.TIME, s.ModTime()).Push(nfs.SIZE, kit.FmtSize(s.Size())).Push(nfs.PATH, file)
|
||||
m.PushDownload(mdb.LINK, file, path.Join(p, file)).PushButton(nfs.TRASH)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -54,30 +47,20 @@ func _publish_bin_list(m *ice.Message, dir string) {
|
||||
}
|
||||
func _publish_contexts(m *ice.Message, arg ...string) {
|
||||
u := web.OptionUserWeb(m)
|
||||
host := strings.Split(u.Host, ice.DF)[0]
|
||||
if host == tcp.LOCALHOST {
|
||||
host = m.Cmd(tcp.HOST).Append(aaa.IP)
|
||||
}
|
||||
host := tcp.PublishLocalhost(m, strings.Split(u.Host, ice.DF)[0])
|
||||
m.Option(cli.CTX_ENV, kit.Select("", ice.SP+kit.JoinKV(ice.EQ, ice.SP, cli.CTX_POD, m.Option(ice.MSG_USERPOD)), m.Option(ice.MSG_USERPOD) != ""))
|
||||
m.Option("httphost", fmt.Sprintf("%s://%s:%s", u.Scheme, host, kit.Select(kit.Select("443", "80", u.Scheme == ice.HTTP), strings.Split(u.Host, ice.DF), 1)))
|
||||
|
||||
if len(arg) == 0 {
|
||||
arg = append(arg, ice.MISC)
|
||||
}
|
||||
for _, k := range arg {
|
||||
for _, k := range kit.Default(arg, ice.MISC) {
|
||||
switch k {
|
||||
case INSTALL:
|
||||
m.Echo(kit.Renders(`export ctx_dev={{.Option "httphost"}}{{.Option "ctx_env"}}; ctx_temp=$(mktemp); wget -O $ctx_temp -q $ctx_dev; source $ctx_temp app username {{.Option "user.name"}}`, m))
|
||||
return
|
||||
|
||||
case ice.MISC:
|
||||
_publish_file(m, ice.ICE_BIN)
|
||||
|
||||
case ice.BASE:
|
||||
m.Option("remote", kit.Select(ice.Info.Make.Remote, cli.SystemExec(m, "git", "config", "remote.origin.url")))
|
||||
m.Option("pathname", strings.TrimSuffix(path.Base(m.Option("remote")), ".git"))
|
||||
}
|
||||
|
||||
if buf, err := kit.Render(m.Config(kit.Keys(ice.CONTEXTS, k)), m); m.Assert(err) {
|
||||
m.EchoScript(strings.TrimSpace(string(buf)))
|
||||
}
|
||||
@ -90,44 +73,31 @@ const (
|
||||
const PUBLISH = "publish"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{Commands: ice.Commands{
|
||||
Index.MergeCommands(ice.Commands{
|
||||
PUBLISH: {Name: "publish path auto create volcanos icebergs intshell", Help: "发布", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Config(ice.CONTEXTS, _contexts)
|
||||
}},
|
||||
web.SERVE_START: {Name: "serve.start", Help: "服务启动", Hand: func(m *ice.Message, arg ...string) {
|
||||
_publish_file(m, ice.ICE_BIN)
|
||||
}},
|
||||
ice.VOLCANOS: {Name: "volcanos", Help: "火山架", Hand: func(m *ice.Message, arg ...string) {
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { m.Config(ice.CONTEXTS, _contexts) }},
|
||||
web.SERVE_START: {Hand: func(m *ice.Message, arg ...string) { _publish_file(m, ice.ICE_BIN) }},
|
||||
ice.VOLCANOS: {Help: "火山架", Hand: func(m *ice.Message, arg ...string) {
|
||||
defer func() { m.EchoQRCode(m.Option(ice.MSG_USERWEB)) }()
|
||||
defer func() { m.Cmdy(PUBLISH, ice.CONTEXTS, ice.MISC) }()
|
||||
_publish_list(m, `.*\.(html|css|js)$`)
|
||||
_publish_list(m, kit.ExtReg(`(html|css|js)`))
|
||||
}},
|
||||
ice.ICEBERGS: {Name: "icebergs", Help: "冰山架", Hand: func(m *ice.Message, arg ...string) {
|
||||
ice.ICEBERGS: {Help: "冰山架", Hand: func(m *ice.Message, arg ...string) {
|
||||
defer func() { m.Cmdy(PUBLISH, ice.CONTEXTS, ice.CORE) }()
|
||||
_publish_bin_list(m, ice.USR_PUBLISH)
|
||||
}},
|
||||
ice.INTSHELL: {Name: "intshell", Help: "神农架", Hand: func(m *ice.Message, arg ...string) {
|
||||
ice.INTSHELL: {Help: "神农架", Hand: func(m *ice.Message, arg ...string) {
|
||||
defer func() { m.Cmdy(PUBLISH, ice.CONTEXTS, ice.BASE) }()
|
||||
_publish_list(m, `.*\.(sh|vim|conf)$`)
|
||||
_publish_list(m, kit.ExtReg(`(sh|vim|conf)`))
|
||||
}},
|
||||
ice.CONTEXTS: {Name: "contexts", Help: "环境", Hand: func(m *ice.Message, arg ...string) {
|
||||
_publish_contexts(m, arg...)
|
||||
ice.CONTEXTS: {Hand: func(m *ice.Message, arg ...string) { _publish_contexts(m, arg...) }},
|
||||
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(nfs.DIR, arg[1:]).Cut("path,size,time").ProcessAgain() }},
|
||||
mdb.CREATE: {Name: "create file", Help: "添加", Hand: func(m *ice.Message, arg ...string) { _publish_file(m, m.Option(nfs.FILE)) }},
|
||||
nfs.TRASH: {Hand: func(m *ice.Message, arg ...string) { nfs.Trash(m, path.Join(ice.USR_PUBLISH, m.Option(nfs.PATH))) }},
|
||||
}, ctx.ConfAction(ice.CONTEXTS, _contexts), aaa.RoleAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(nfs.DIR, kit.Select("", arg, 0), nfs.DIR_WEB_FIELDS, kit.Dict(nfs.DIR_ROOT, ice.USR_PUBLISH)).SortTimeR(mdb.TIME)
|
||||
}},
|
||||
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(nfs.DIR, kit.Select(nfs.PWD, arg, 1)).ProcessAgain()
|
||||
}},
|
||||
mdb.CREATE: {Name: "create file", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
|
||||
_publish_file(m, m.Option(nfs.FILE))
|
||||
}},
|
||||
nfs.TRASH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
nfs.Trash(m, path.Join(ice.USR_PUBLISH, m.Option(nfs.PATH)))
|
||||
}},
|
||||
}, aaa.RoleAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Option(nfs.DIR_ROOT, ice.USR_PUBLISH)
|
||||
m.Cmdy(nfs.DIR, kit.Select("", arg, 0), nfs.DIR_WEB_FIELDS)
|
||||
}},
|
||||
}, Configs: ice.Configs{PUBLISH: {Value: kit.Data(ice.CONTEXTS, _contexts)}}})
|
||||
})
|
||||
}
|
||||
|
||||
var _contexts = kit.Dict(
|
||||
|
@ -11,17 +11,12 @@ import (
|
||||
|
||||
func _py_exec(m *ice.Message, arg ...string) {
|
||||
const PYTHON2 = "python2"
|
||||
|
||||
if _, e := nfs.DiskFile.StatFile(path.Join(arg[2], arg[1])); e == nil {
|
||||
m.Cmdy(cli.SYSTEM, PYTHON2, path.Join(arg[2], arg[1]))
|
||||
|
||||
} else if b, e := nfs.ReadFile(m, path.Join(arg[2], arg[1])); e == nil {
|
||||
m.Cmdy(cli.SYSTEM, PYTHON2, "-c", string(b))
|
||||
}
|
||||
|
||||
if m.StatusTime(); cli.IsSuccess(m) {
|
||||
m.SetAppend()
|
||||
}
|
||||
m.StatusTime()
|
||||
}
|
||||
|
||||
const PY = nfs.PY
|
||||
@ -36,6 +31,6 @@ func init() {
|
||||
}},
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { _py_exec(m, arg...) }},
|
||||
TEMPLATE: {Hand: func(m *ice.Message, arg ...string) { m.Echo(`print "hello world"`) }},
|
||||
}, PlugAction(), LangAction())},
|
||||
}, PlugAction())},
|
||||
})
|
||||
}
|
||||
|
@ -13,7 +13,30 @@ import (
|
||||
|
||||
func _sh_exec(m *ice.Message, arg ...string) (res []string) {
|
||||
if cmd := ctx.GetFileCmd(path.Join(arg[2], arg[1])); cmd != "" {
|
||||
res = append(res, kit.Format(`#! /bin/sh
|
||||
res = append(res, kit.Format(_sh_template, "http://localhost:9020", m.Option(ice.MSG_USERPOD), cmd))
|
||||
}
|
||||
if _, e := nfs.DiskFile.StatFile(path.Join(arg[2], arg[1])); e == nil {
|
||||
res = append(res, kit.Format("source %s", kit.Path(arg[2], arg[1])))
|
||||
} else if b, e := nfs.ReadFile(m, path.Join(arg[2], arg[1])); e == nil {
|
||||
res = append(res, string(b))
|
||||
}
|
||||
m.Cmdy(cli.SYSTEM, SH, "-c", kit.Join(res, ice.NL)).StatusTime()
|
||||
return
|
||||
}
|
||||
|
||||
const SH = nfs.SH
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
SH: {Name: "sh path auto", Help: "命令", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { _c_show(m, arg...) }},
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { _sh_exec(m, arg...) }},
|
||||
NAVIGATE: {Hand: func(m *ice.Message, arg ...string) { _c_tags(m, MAN, "ctags", "-a", "-R", nfs.PWD) }},
|
||||
}, PlugAction())},
|
||||
})
|
||||
}
|
||||
|
||||
var _sh_template = `#! /bin/sh
|
||||
export ctx_dev=%s; ctx_pod=%s ctx_temp=$(mktemp); curl -fsSL $ctx_dev -o $ctx_temp; source $ctx_temp &>/dev/null
|
||||
_done=""
|
||||
_list() {
|
||||
@ -27,27 +50,4 @@ _list() {
|
||||
_action() {
|
||||
_list action "$@"
|
||||
}
|
||||
`, "http://localhost:9020", m.Option(ice.MSG_USERPOD), cmd))
|
||||
}
|
||||
|
||||
if _, e := nfs.DiskFile.StatFile(path.Join(arg[2], arg[1])); e == nil {
|
||||
res = append(res, kit.Format("source %s", kit.Path(arg[2], arg[1])))
|
||||
} else if b, e := nfs.ReadFile(m, path.Join(arg[2], arg[1])); e == nil {
|
||||
res = append(res, string(b))
|
||||
}
|
||||
m.Cmdy(cli.SYSTEM, SH, "-c", kit.Join(res, ice.NL))
|
||||
m.StatusTime()
|
||||
return
|
||||
}
|
||||
|
||||
const SH = nfs.SH
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
SH: {Name: "sh path auto", Help: "命令", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { _c_show(m, arg...) }},
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { _sh_exec(m, arg...) }},
|
||||
NAVIGATE: {Hand: func(m *ice.Message, arg ...string) { _c_tags(m, MAN, "ctags", "-a", "-R", nfs.PWD) }},
|
||||
}, PlugAction(), LangAction())},
|
||||
})
|
||||
}
|
||||
`
|
||||
|
@ -8,29 +8,23 @@ import (
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/ssh"
|
||||
"shylinux.com/x/icebergs/base/web"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
const SHY = "shy"
|
||||
|
||||
func init() {
|
||||
const WEB_WIKI_WORD = "web.wiki.word"
|
||||
Index.MergeCommands(ice.Commands{
|
||||
SHY: {Name: "shy path auto", Help: "脚本", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) {
|
||||
ctx.ProcessCommand(m, WEB_WIKI_WORD, kit.Simple(path.Join(arg[2], arg[1])))
|
||||
}},
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(ssh.SOURCE, path.Join(arg[2], arg[1]))
|
||||
}},
|
||||
TEMPLATE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Echo(`chapter "hi"`)
|
||||
}},
|
||||
}, PlugAction(), LangAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { ctx.ProcessCommand(m, web.WIKI_WORD, kit.Simple(path.Join(arg[2], arg[1]))) }},
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(ssh.SOURCE, path.Join(arg[2], arg[1])) }},
|
||||
TEMPLATE: {Hand: func(m *ice.Message, arg ...string) { m.Echo(`chapter "hi"`) }},
|
||||
}, PlugAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) > 0 && kit.Ext(arg[0]) == m.CommandKey() {
|
||||
m.Cmdy(WEB_WIKI_WORD, path.Join(ice.SRC, strings.TrimPrefix(arg[0], "src/")))
|
||||
m.Cmdy(web.WIKI_WORD, path.Join(ice.SRC, strings.TrimPrefix(arg[0], "src/")))
|
||||
} else {
|
||||
m.Cmdy(WEB_WIKI_WORD, arg)
|
||||
m.Cmdy(web.WIKI_WORD, arg)
|
||||
}
|
||||
}},
|
||||
})
|
||||
|
@ -17,28 +17,23 @@ const UPGRADE = "upgrade"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{Configs: ice.Configs{
|
||||
UPGRADE: {Name: UPGRADE, Help: "升级", Value: kit.Dict(mdb.HASH, kit.Dict(
|
||||
UPGRADE: {Value: kit.Dict(mdb.HASH, kit.Dict(
|
||||
nfs.TARGET, kit.Dict(mdb.LIST, kit.List(mdb.TYPE, ice.BIN, nfs.FILE, ice.ICE_BIN)),
|
||||
nfs.BINARY, kit.Dict(mdb.LIST, kit.List(mdb.TYPE, nfs.TAR, nfs.FILE, "contexts.bin.tar.gz")),
|
||||
nfs.SOURCE, kit.Dict(mdb.LIST, kit.List(mdb.TYPE, nfs.TAR, nfs.FILE, "contexts.src.tar.gz")),
|
||||
))},
|
||||
}, Commands: ice.Commands{
|
||||
UPGRADE: {Name: "upgrade item=target,binary,source run restart", Help: "升级", Actions: ice.MergeActions(ice.Actions{
|
||||
cli.RESTART: {Name: "restart", Help: "重启", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Go(func() { m.Sleep300ms(ice.EXIT, 1) })
|
||||
}},
|
||||
cli.RESTART: {Hand: func(m *ice.Message, arg ...string) { m.Go(func() { m.Sleep300ms(ice.EXIT, 1) }) }},
|
||||
}, mdb.ClearHashOnExitAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.ZoneSelect(m, kit.Select(nfs.TARGET, arg, 0)).Tables(func(value ice.Maps) {
|
||||
if value[nfs.FILE] == ice.ICE_BIN { // 程序文件
|
||||
if value[nfs.FILE] == ice.ICE_BIN {
|
||||
value[nfs.FILE] = kit.Keys(ice.ICE, runtime.GOOS, runtime.GOARCH)
|
||||
defer nfs.Rename(m, value[nfs.FILE], ice.BIN_ICE_BIN)
|
||||
m.Option(ice.EXIT, ice.TRUE)
|
||||
}
|
||||
|
||||
// 下载文件
|
||||
dir := kit.Select(kit.Format(value[nfs.FILE]), value[nfs.PATH])
|
||||
web.SpideSave(m, dir, "/publish/"+kit.Format(value[nfs.FILE]), nil)
|
||||
switch value[mdb.TYPE] {
|
||||
switch web.SpideSave(m, dir, "/publish/"+kit.Format(value[nfs.FILE]), nil); value[mdb.TYPE] {
|
||||
case ice.BIN:
|
||||
os.Chmod(dir, 0755)
|
||||
case nfs.TAR:
|
||||
|
@ -53,9 +53,9 @@ func init() {
|
||||
VIMER: {Name: "vimer path=src/@key file=main.go line=1 list", Help: "编辑器", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) {
|
||||
switch m.Option(ctx.ACTION) {
|
||||
case AUTOGEN, web.DREAM, XTERM:
|
||||
case web.DREAM, AUTOGEN, XTERM:
|
||||
m.Cmdy(m.Option(ctx.ACTION), mdb.INPUTS, arg)
|
||||
case nfs.SCRIPT, web.WEBSITE:
|
||||
case web.WEBSITE, nfs.SCRIPT:
|
||||
m.Cmdy(COMPLETE, mdb.FOREACH, kit.Select("", arg, 1), m.Option(ctx.ACTION))
|
||||
case "extension":
|
||||
nfs.DirDeepAll(m, "usr/volcanos/plugin/local/code/", "inner/", nil, nfs.PATH)
|
||||
@ -63,34 +63,29 @@ func init() {
|
||||
switch arg[0] {
|
||||
case ctx.INDEX:
|
||||
m.Cmdy(ctx.COMMAND, mdb.SEARCH, ctx.COMMAND, ice.OptionFields(ctx.INDEX))
|
||||
case nfs.PATH:
|
||||
m.Cmdy(INNER, mdb.INPUTS, arg).Cut("path,size,time")
|
||||
case nfs.FILE:
|
||||
p := m.Option(nfs.PATH)
|
||||
list := ice.Map{}
|
||||
list, p := ice.Map{}, m.Option(nfs.PATH)
|
||||
m.Cmd(FAVOR, "_recent_file").Tables(func(value ice.Maps) {
|
||||
if p := value[nfs.PATH] + value[nfs.FILE]; list[p] == nil {
|
||||
m.Push(nfs.PATH, p)
|
||||
list[p] = value
|
||||
}
|
||||
kit.IfNoKey(list, value[nfs.PATH]+value[nfs.FILE], func(p string) { m.Push(nfs.PATH, p) })
|
||||
})
|
||||
for _, p := range kit.Split(kit.Select(m.Option(nfs.PATH), m.Option("paths"))) {
|
||||
nfs.DirDeepAll(m, nfs.PWD, p, func(value ice.Maps) { kit.IfNoKey(list, value[nfs.PATH], func(p string) { m.Push(nfs.PATH, p) }) }, nfs.PATH)
|
||||
}
|
||||
m.Cmd(mdb.RENDER, kit.Ext(m.Option(nfs.FILE)), m.Option(nfs.FILE), p).Tables(func(value ice.Maps) {
|
||||
m.Push(nfs.PATH, kit.Format("line:%s:%s:%s", value[nfs.LINE], value["kind"], value[mdb.NAME]))
|
||||
})
|
||||
for _, p := range kit.Split(kit.Select(m.Option(nfs.PATH), m.Option("paths"))) {
|
||||
nfs.DirDeepAll(m, nfs.PWD, p, nil, nfs.PATH)
|
||||
}
|
||||
m.Cmd(ctx.COMMAND, mdb.SEARCH, ctx.COMMAND, ice.OptionFields(ctx.INDEX)).Tables(func(value ice.Maps) {
|
||||
m.Push(nfs.PATH, "index:"+value[ctx.INDEX])
|
||||
})
|
||||
m.Cmd(FAVOR, "_system_app").Tables(func(value ice.Maps) {
|
||||
m.Push(nfs.PATH, "_open:"+strings.ToLower(value[mdb.NAME]))
|
||||
m.Push(nfs.PATH, "_open:"+strings.ToLower(kit.Select(value[mdb.TEXT], value[mdb.NAME])))
|
||||
})
|
||||
case nfs.PATH:
|
||||
m.Cmdy(INNER, mdb.INPUTS, arg).Cut("path,size,time")
|
||||
default:
|
||||
}
|
||||
}
|
||||
}},
|
||||
nfs.SAVE: {Name: "save", Help: "保存", Hand: func(m *ice.Message, arg ...string) {
|
||||
nfs.SAVE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if m.Option(nfs.CONTENT) == "" {
|
||||
m.Option(nfs.CONTENT, m.Cmdx("", TEMPLATE))
|
||||
}
|
||||
@ -99,38 +94,29 @@ func init() {
|
||||
m.Cmd("", DEVPACK)
|
||||
}
|
||||
}},
|
||||
nfs.TRASH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
nfs.Trash(m, arg[0])
|
||||
}},
|
||||
nfs.SCRIPT: {Name: "script file=hi/hi.js", Help: "脚本", Hand: func(m *ice.Message, arg ...string) {
|
||||
nfs.TRASH: {Hand: func(m *ice.Message, arg ...string) { nfs.Trash(m, arg[0]) }},
|
||||
nfs.SCRIPT: {Name: "script file*=hi/hi.js", Help: "脚本", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(nfs.DEFS, path.Join(m.Option(nfs.PATH), m.Option(nfs.FILE)), m.Cmdx("", TEMPLATE))
|
||||
}},
|
||||
web.WEBSITE: {Name: "website file=hi.zml", Help: "网页", Hand: func(m *ice.Message, arg ...string) {
|
||||
web.WEBSITE: {Name: "website file*=hi.zml", Help: "网页", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(nfs.DEFS, path.Join(m.Option(nfs.PATH), m.Option(nfs.FILE)), m.Cmdx("", TEMPLATE))
|
||||
}},
|
||||
web.DREAM: {Name: "dream name=hi repos", Help: "空间", Hand: func(m *ice.Message, arg ...string) {
|
||||
web.DREAM: {Name: "dream name*=hi repos", Help: "空间", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(web.DREAM, cli.START, arg)
|
||||
}},
|
||||
"_open": {Help: "打开", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(cli.DAEMON, cli.OPEN, "-a", kit.Split(arg[0], ice.PT, ice.PT)[0])
|
||||
}},
|
||||
XTERM: {Name: "xterm type=sh name text", Help: "终端", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(XTERM, mdb.CREATE, arg)
|
||||
}},
|
||||
FAVOR: {Name: "favor", Help: "收藏"},
|
||||
|
||||
"_open": {Name: "_open", Help: "打开", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(cli.DAEMON, cli.OPEN, "-a", kit.Split(arg[0], ice.PT, ice.PT)[0])
|
||||
}},
|
||||
cli.MAKE: {Name: "make", Help: "构建", Hand: func(m *ice.Message, arg ...string) {
|
||||
_vimer_make(m, m.Option(nfs.PATH), m.Cmd(cli.SYSTEM, cli.MAKE, arg))
|
||||
}},
|
||||
|
||||
TEMPLATE: {Name: "template", Help: "模板", Hand: func(m *ice.Message, arg ...string) {
|
||||
}}, FAVOR: {Help: "收藏"},
|
||||
TEMPLATE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(TEMPLATE, kit.Ext(m.Option(mdb.FILE)), m.Option(nfs.FILE), m.Option(nfs.PATH))
|
||||
}},
|
||||
COMPLETE: {Name: "complete", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
|
||||
COMPLETE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(COMPLETE, kit.Ext(m.Option(mdb.FILE)), m.Option(nfs.FILE), m.Option(nfs.PATH))
|
||||
}},
|
||||
|
||||
DEVPACK: {Name: "devpack", Help: "开发模式", Hand: func(m *ice.Message, arg ...string) {
|
||||
DEVPACK: {Help: "开发模式", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(nfs.LINK, ice.GO_SUM, path.Join(ice.SRC_DEBUG, ice.GO_SUM))
|
||||
m.Cmd(nfs.LINK, ice.GO_MOD, path.Join(ice.SRC_DEBUG, ice.GO_MOD))
|
||||
m.Cmdy(nfs.CAT, ice.GO_MOD)
|
||||
@ -138,7 +124,7 @@ func init() {
|
||||
web.ToastSuccess(m)
|
||||
m.ProcessInner()
|
||||
}},
|
||||
BINPACK: {Name: "binpack", Help: "打包模式", Hand: func(m *ice.Message, arg ...string) {
|
||||
BINPACK: {Help: "打包模式", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(WEBPACK, mdb.CREATE)
|
||||
m.Cmdy(AUTOGEN, BINPACK)
|
||||
web.ToastSuccess(m)
|
||||
@ -147,12 +133,11 @@ func init() {
|
||||
AUTOGEN: {Name: "create name*=h2 help=示例 type*=Zone,Hash,Data,Code main*=main.go zone key", Help: "模块", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(AUTOGEN, nfs.MODULE, arg)
|
||||
}},
|
||||
COMPILE: {Name: "compile", Help: "编译", Hand: func(m *ice.Message, arg ...string) {
|
||||
COMPILE: {Help: "编译", Hand: func(m *ice.Message, arg ...string) {
|
||||
cmds := []string{COMPILE, ice.SRC_MAIN_GO, ice.BIN_ICE_BIN}
|
||||
if strings.HasSuffix(os.Args[0], "contexts.app/Contents/MacOS/contexts") {
|
||||
m.Option(cli.ENV, "CGO_ENABLED", "1", cli.HOME, kit.Env(cli.HOME), cli.PATH, kit.Path("usr/local/go/bin")+ice.DF+kit.Env(cli.PATH))
|
||||
cmds = []string{COMPILE, "src/webview.go", "usr/publish/contexts.app/Contents/MacOS/contexts"}
|
||||
// cmds = []string{cli.SYSTEM, cli.MAKE, "app"}
|
||||
}
|
||||
if msg := m.Cmd(cmds); cli.IsSuccess(msg) {
|
||||
m.Cmd(UPGRADE, cli.RESTART)
|
||||
@ -160,27 +145,17 @@ func init() {
|
||||
_vimer_make(m, nfs.PWD, msg)
|
||||
}
|
||||
}},
|
||||
PUBLISH: {Name: "publish", Help: "发布", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(PUBLISH, ice.CONTEXTS)
|
||||
}},
|
||||
PUBLISH: {Help: "发布", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(PUBLISH, ice.CONTEXTS) }},
|
||||
web.DREAM_TABLES: {Hand: func(m *ice.Message, arg ...string) {
|
||||
switch m.Option(mdb.TYPE) {
|
||||
case web.SERVER, web.WORKER:
|
||||
m.PushButton(kit.Dict(m.CommandKey(), "源码"))
|
||||
}
|
||||
kit.Switch(m.Option(mdb.TYPE), kit.Simple(web.SERVER, web.WORKER), func() { m.PushButton(kit.Dict(m.CommandKey(), "源码")) })
|
||||
}},
|
||||
web.DREAM_ACTION: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if arg[1] == m.CommandKey() {
|
||||
// web.ProcessIframe(m, web.MergePodCmd(m, m.Option(mdb.NAME), m.PrefixKey()), arg...)
|
||||
web.ProcessWebsite(m, m.Option(mdb.NAME), m.PrefixKey())
|
||||
}
|
||||
kit.If(arg[1] == m.CommandKey(), func() { web.ProcessWebsite(m, m.Option(mdb.NAME), m.PrefixKey()) })
|
||||
}},
|
||||
}, web.DreamAction(), aaa.RoleAction(ctx.COMMAND)), Hand: func(m *ice.Message, arg ...string) {
|
||||
if m.Cmdy(INNER, arg); arg[0] != ctx.ACTION {
|
||||
m.Action(AUTOGEN, nfs.SCRIPT, web.DREAM, web.WEBSITE, nfs.SAVE, COMPILE)
|
||||
m.Option("tabs", m.Config("show.tabs"))
|
||||
m.Option("plug", m.Config("show.plug"))
|
||||
m.Option("exts", m.Config("show.exts"))
|
||||
m.Options("tabs", m.Config("show.tabs"), "plug", m.Config("show.plug"), "exts", m.Config("show.exts"))
|
||||
ctx.DisplayLocal(m, "")
|
||||
}
|
||||
}},
|
||||
@ -195,27 +170,19 @@ func init() {
|
||||
Index.MergeCommands(ice.Commands{TEMPLATE: {Name: "template type name text auto", Help: "模板", Actions: mdb.RenderAction()}})
|
||||
Index.MergeCommands(ice.Commands{COMPLETE: {Name: "complete type name text auto", Help: "补全", Actions: mdb.RenderAction()}})
|
||||
Index.MergeCommands(ice.Commands{NAVIGATE: {Name: "navigate type name text auto", Help: "跳转", Actions: mdb.RenderAction()}})
|
||||
ice.AddMerges(func(c *ice.Context, key string, cmd *ice.Command, sub string, action *ice.Action) (ice.Handler, ice.Handler) {
|
||||
switch sub {
|
||||
case TEMPLATE, COMPLETE, NAVIGATE:
|
||||
return func(m *ice.Message, arg ...string) { m.Cmd(sub, mdb.CREATE, key, m.PrefixKey()) }, nil
|
||||
}
|
||||
func LangAction() ice.Actions {
|
||||
return ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
for _, cmd := range []string{TEMPLATE, COMPLETE, NAVIGATE} {
|
||||
m.Cmd(cmd, mdb.CREATE, m.CommandKey(), m.PrefixKey())
|
||||
}
|
||||
}},
|
||||
TEMPLATE: {Hand: func(m *ice.Message, arg ...string) {}},
|
||||
COMPLETE: {Hand: func(m *ice.Message, arg ...string) {}},
|
||||
NAVIGATE: {Hand: func(m *ice.Message, arg ...string) {}},
|
||||
}
|
||||
return nil, nil
|
||||
})
|
||||
}
|
||||
func Complete(m *ice.Message, text string, data ice.Map) {
|
||||
if strings.HasSuffix(text, ice.PT) {
|
||||
key := kit.Slice(kit.Split(text, " ."), -1)[0]
|
||||
m.Push(mdb.TEXT, kit.Simple(data[key]))
|
||||
m.Push(mdb.TEXT, kit.Simple(data[kit.Slice(kit.Split(text, " ."), -1)[0]]))
|
||||
} else {
|
||||
m.Push(mdb.TEXT, data[""])
|
||||
for k := range data {
|
||||
m.Push(mdb.TEXT, k)
|
||||
}
|
||||
kit.Fetch(data, func(k string, v ice.Any) { m.Push(mdb.TEXT, k) })
|
||||
}
|
||||
}
|
||||
|
@ -15,12 +15,8 @@ import (
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _volcanos(m *ice.Message, file ...string) string {
|
||||
return path.Join(ice.USR_VOLCANOS, path.Join(file...))
|
||||
}
|
||||
func _publish(m *ice.Message, file ...string) string {
|
||||
return path.Join(ice.USR_PUBLISH, path.Join(file...))
|
||||
}
|
||||
func _volcanos(m *ice.Message, file ...string) string { return path.Join(ice.USR_VOLCANOS, path.Join(file...)) }
|
||||
func _publish(m *ice.Message, file ...string) string { return path.Join(ice.USR_PUBLISH, path.Join(file...)) }
|
||||
func _webpack_can(m *ice.Message) {
|
||||
m.Option(nfs.DIR_ROOT, "")
|
||||
m.Cmd(nfs.COPY, _volcanos(m, PAGE_CAN_CSS), _volcanos(m, PAGE_INDEX_CSS), _volcanos(m, PAGE_CACHE_CSS))
|
||||
@ -45,21 +41,17 @@ func _webpack_cache(m *ice.Message, dir string, write bool) {
|
||||
if _, e := nfs.DiskFile.StatFile(ice.USR_VOLCANOS); os.IsNotExist(e) {
|
||||
return
|
||||
}
|
||||
|
||||
css, _, e := nfs.CreateFile(m, path.Join(dir, PAGE_CACHE_CSS))
|
||||
m.Assert(e)
|
||||
defer css.Close()
|
||||
|
||||
js, _, e := nfs.CreateFile(m, path.Join(dir, PAGE_CACHE_JS))
|
||||
m.Assert(e)
|
||||
defer js.Close()
|
||||
|
||||
defer fmt.Fprintln(js, `_can_name = ""`)
|
||||
defer _webpack_can(m)
|
||||
if !write {
|
||||
return
|
||||
}
|
||||
|
||||
for _, k := range []string{LIB, PANEL, PLUGIN} {
|
||||
nfs.DirDeepAll(m, dir, k, func(value ice.Maps) {
|
||||
if kit.Ext(value[nfs.PATH]) == CSS {
|
||||
@ -68,7 +60,6 @@ func _webpack_cache(m *ice.Message, dir string, write bool) {
|
||||
})
|
||||
}
|
||||
fmt.Fprintln(js)
|
||||
|
||||
for _, k := range []string{LIB, PANEL, PLUGIN} {
|
||||
nfs.DirDeepAll(m, dir, k, func(value ice.Maps) {
|
||||
if kit.Ext(value[nfs.PATH]) == JS {
|
||||
@ -79,7 +70,6 @@ func _webpack_cache(m *ice.Message, dir string, write bool) {
|
||||
for _, k := range []string{ice.FRAME_JS} {
|
||||
_webpack_js(m, js, k)
|
||||
}
|
||||
|
||||
m.Option(nfs.DIR_ROOT, "")
|
||||
mdb.HashSelects(m).Sort(nfs.PATH).Tables(func(value ice.Maps) {
|
||||
defer fmt.Fprintln(js)
|
||||
@ -102,25 +92,10 @@ func _webpack_build(m *ice.Message, file string) {
|
||||
fmt.Fprintln(f, `Volcanos.meta.pack = `+kit.Formats(kit.UnMarshal(kit.Select("{}", m.Option(nfs.CONTENT)))))
|
||||
fmt.Fprintln(f, `Volcanos.meta.args = `+kit.Formats(kit.Dict(m.OptionSimple(kit.Split(m.Option(ctx.ARGS))...))))
|
||||
}
|
||||
|
||||
if f, p, e := nfs.CreateFile(m, kit.Keys(file, HTML)); m.Assert(e) {
|
||||
defer f.Close()
|
||||
defer m.Echo(p)
|
||||
|
||||
fmt.Fprintf(f, `
|
||||
<!DOCTYPE html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<style type="text/css">%s</style>
|
||||
<style type="text/css">%s</style>
|
||||
</head>
|
||||
<body>
|
||||
<script>%s</script>
|
||||
<script>%s</script>
|
||||
<script>%s</script>
|
||||
<script>%s</script>
|
||||
</body>
|
||||
`,
|
||||
fmt.Fprintf(f, _webpack_template,
|
||||
m.Cmdx(nfs.CAT, _volcanos(m, PAGE_INDEX_CSS)), m.Cmdx(nfs.CAT, _volcanos(m, PAGE_CACHE_CSS)),
|
||||
m.Cmdx(nfs.CAT, _volcanos(m, ice.PROTO_JS)), m.Cmdx(nfs.CAT, kit.Keys(file, JS)),
|
||||
m.Cmdx(nfs.CAT, _volcanos(m, PAGE_CACHE_JS)), m.Cmdx(nfs.CAT, _volcanos(m, PAGE_INDEX_JS)),
|
||||
@ -155,10 +130,10 @@ func init() {
|
||||
mdb.REMOVE: {Name: "remove", Help: "调试", Hand: func(m *ice.Message, arg ...string) {
|
||||
_webpack_cache(m.Spawn(), _volcanos(m), false)
|
||||
}},
|
||||
mdb.INSERT: {Name: "insert path", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashCreate(m, nfs.PATH, m.Option(nfs.PATH))
|
||||
mdb.INSERT: {Name: "insert path*", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashCreate(m, m.OptionSimple(nfs.PATH))
|
||||
}},
|
||||
cli.BUILD: {Name: "build name=hi", Help: "构建", Hand: func(m *ice.Message, arg ...string) {
|
||||
cli.BUILD: {Name: "build name*=hi", Hand: func(m *ice.Message, arg ...string) {
|
||||
_webpack_cache(m.Spawn(), _volcanos(m), true)
|
||||
_webpack_build(m, _publish(m, WEBPACK, m.Option(mdb.NAME)))
|
||||
}},
|
||||
@ -168,11 +143,23 @@ func init() {
|
||||
}
|
||||
}},
|
||||
}, mdb.HashAction(mdb.SHORT, nfs.PATH, mdb.FIELD, "time,path"), mdb.ClearHashOnExitAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Option(nfs.DIR_TYPE, nfs.CAT)
|
||||
m.Option(nfs.DIR_DEEP, ice.TRUE)
|
||||
m.OptionFields(nfs.DIR_WEB_FIELDS)
|
||||
m.Cmdy(nfs.DIR, _volcanos(m, PAGE))
|
||||
m.Cmdy(nfs.DIR, _publish(m, WEBPACK))
|
||||
m.Options(nfs.DIR_TYPE, nfs.CAT, nfs.DIR_DEEP, ice.TRUE)
|
||||
m.Cmdy(nfs.DIR, _volcanos(m, PAGE)).Cmdy(nfs.DIR, _publish(m, WEBPACK))
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
||||
var _webpack_template = `
|
||||
<!DOCTYPE html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<style type="text/css">%s</style>
|
||||
<style type="text/css">%s</style>
|
||||
</head>
|
||||
<body>
|
||||
<script>%s</script>
|
||||
<script>%s</script>
|
||||
<script>%s</script>
|
||||
<script>%s</script>
|
||||
</body>
|
||||
`
|
@ -35,20 +35,16 @@ func (s _xterm) Close() error {
|
||||
func _xterm_get(m *ice.Message, h string) _xterm {
|
||||
h = kit.Select(m.Option(mdb.HASH), h)
|
||||
m.Assert(h != "")
|
||||
|
||||
t := mdb.HashSelectField(m, m.Option(mdb.HASH, h), mdb.TYPE)
|
||||
mdb.HashModify(m, "view", m.Option(ice.MSG_DAEMON))
|
||||
return mdb.HashSelectTarget(m, h, func() ice.Any {
|
||||
ls := kit.Split(kit.Select(nfs.SH, t))
|
||||
cmd := exec.Command(cli.SystemFind(m, ls[0]), ls[1:]...)
|
||||
|
||||
tty, err := pty.Start(cmd)
|
||||
m.Assert(err)
|
||||
|
||||
m.Go(func() {
|
||||
defer mdb.HashSelectUpdate(m, h, func(value ice.Map) { delete(value, mdb.TARGET) })
|
||||
defer tty.Close()
|
||||
|
||||
// m.Option("log.disable", ice.TRUE)
|
||||
buf := make([]byte, ice.MOD_BUFS)
|
||||
for {
|
||||
@ -70,7 +66,7 @@ const XTERM = "xterm"
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
XTERM: {Name: "xterm hash auto", Help: "命令行", Actions: ice.MergeActions(ice.Actions{
|
||||
ctx.PROCESS: {Name: "process", Help: "响应", Hand: func(m *ice.Message, arg ...string) {
|
||||
ctx.PROCESS: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 || arg[0] != ice.RUN {
|
||||
arg = []string{m.Cmdx("", mdb.CREATE, arg)}
|
||||
}
|
||||
@ -80,36 +76,32 @@ func init() {
|
||||
switch mdb.HashInputs(m, arg).Cmdy(FAVOR, "_system_term", ice.OptionFields(arg[0])).Cut(arg[0]); arg[0] {
|
||||
case mdb.TYPE:
|
||||
if m.Option(nfs.LINE) != "" && m.Option(nfs.FILE) != "" {
|
||||
m.Push(arg[0], "vim +"+m.Option(nfs.LINE)+" "+m.Option(nfs.PATH)+m.Option(nfs.FILE))
|
||||
m.Push(arg[0], "vim +"+m.Option(nfs.LINE)+ice.SP+m.Option(nfs.PATH)+m.Option(nfs.FILE))
|
||||
}
|
||||
m.Push(arg[0], "bash", "sh")
|
||||
case mdb.NAME:
|
||||
m.Push(arg[0], ice.Info.Hostname, path.Base(m.Option(mdb.TYPE)))
|
||||
}
|
||||
}},
|
||||
mdb.CREATE: {Name: "create type=sh name text", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.CREATE: {Name: "create type=sh name text", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashCreate(m, mdb.NAME, kit.Split(m.Option(mdb.TYPE))[0], m.OptionSimple(mdb.TYPE, mdb.NAME, mdb.TEXT))
|
||||
ctx.ProcessRefresh(m)
|
||||
}},
|
||||
"resize": {Name: "resize", Help: "大小", Hand: func(m *ice.Message, arg ...string) {
|
||||
"resize": {Hand: func(m *ice.Message, arg ...string) {
|
||||
_xterm_get(m, "").Setsize(m.OptionDefault("rows", "24"), m.OptionDefault("cols", "80"))
|
||||
}},
|
||||
"input": {Name: "input", Help: "输入", Hand: func(m *ice.Message, arg ...string) {
|
||||
"input": {Hand: func(m *ice.Message, arg ...string) {
|
||||
if b, e := base64.StdEncoding.DecodeString(strings.Join(arg, "")); !m.Warn(e) {
|
||||
_xterm_get(m, "").Write(string(b))
|
||||
}
|
||||
}},
|
||||
INSTALL: {Name: "install", Help: "安装", Hand: func(m *ice.Message, arg ...string) {
|
||||
INSTALL: {Help: "安装", Hand: func(m *ice.Message, arg ...string) {
|
||||
_xterm_get(m, kit.Select("", arg, 0)).Write(m.Cmdx(PUBLISH, ice.CONTEXTS, INSTALL) + ice.NL)
|
||||
ctx.ProcessHold(m)
|
||||
}},
|
||||
web.WEBSITE: {Name: "website", Help: "网页", Hand: func(m *ice.Message, arg ...string) {
|
||||
web.ProcessWebsite(m, "", "", m.OptionSimple(mdb.HASH))
|
||||
}},
|
||||
web.WEBSITE: {Help: "网页", Hand: func(m *ice.Message, arg ...string) { web.ProcessWebsite(m, "", "", m.OptionSimple(mdb.HASH)) }},
|
||||
}, mdb.HashAction(mdb.FIELD, "time,hash,type,name,text,view", mdb.TOOLS, FAVOR), ctx.CmdAction(), ctx.ProcessAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
if mdb.HashSelect(m, arg...); len(arg) == 0 {
|
||||
m.PushAction(web.WEBSITE, mdb.REMOVE)
|
||||
m.Action(mdb.CREATE, mdb.PRUNES)
|
||||
m.PushAction(web.WEBSITE, mdb.REMOVE).Action(mdb.CREATE, mdb.PRUNES)
|
||||
} else {
|
||||
ctx.Toolkit(m, FAVOR, "web.chat.iframe")
|
||||
m.Action(INSTALL, "波浪线", "反引号")
|
||||
|
@ -105,6 +105,6 @@ func init() {
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Echo(_website_url(m, strings.TrimPrefix(path.Join(arg[2], arg[1]), SRC_WEBSITE)))
|
||||
}},
|
||||
}, PlugAction(), LangAction())},
|
||||
}, PlugAction())},
|
||||
})
|
||||
}
|
||||
|
@ -199,10 +199,11 @@ func (m *Message) PushScript(arg ...string) {
|
||||
m.Push(SCRIPT, Render(m, RENDER_SCRIPT, arg))
|
||||
}
|
||||
}
|
||||
func (m *Message) PushDownload(key string, arg ...string) {
|
||||
func (m *Message) PushDownload(key string, arg ...string) *Message {
|
||||
if !m.IsCliUA() {
|
||||
m.Push(key, Render(m, RENDER_DOWNLOAD, arg))
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *Message) EchoButton(arg ...Any) *Message {
|
||||
|
Loading…
x
Reference in New Issue
Block a user