1
0
forked from x/icebergs
This commit is contained in:
harveyshao 2023-01-01 22:45:10 +08:00
parent 3ad6a45ec6
commit 66f7ec1b72
13 changed files with 54 additions and 22 deletions

View File

@ -144,7 +144,7 @@ const SYSTEM = "system"
func init() {
Index.MergeCommands(ice.Commands{
SYSTEM: {Name: "system cmd auto", Help: "系统命令", Actions: ice.MergeActions(ice.Actions{
SYSTEM: {Name: "system cmd", Help: "系统命令", Actions: ice.MergeActions(ice.Actions{
nfs.PUSH: {Hand: func(m *ice.Message, arg ...string) {
for _, p := range arg {
if !strings.Contains(m.Cmdx(nfs.CAT, ice.ETC_PATH), p) {

View File

@ -55,7 +55,7 @@ func _command_search(m *ice.Message, kind, name, text string) {
if name != "" && !strings.HasPrefix(key, name) && !strings.Contains(s.Name, name) {
return
}
m.PushSearch(ice.CTX, kit.PathName(1), ice.CMD, kit.FileName(1), kit.SimpleKV("", s.Cap(ice.CTX_FOLLOW), cmd.Name, cmd.Help),
m.PushSearch(ice.CTX, kit.PathName(1), ice.CMD, kit.FileName(1), kit.SimpleKV("", s.Cap(ice.CTX_FOLLOW), kit.Select(key, cmd.Name), kit.Select(key, cmd.Help)),
CONTEXT, s.Cap(ice.CTX_FOLLOW), COMMAND, key, INDEX, kit.Keys(s.Cap(ice.CTX_FOLLOW), key),
mdb.HELP, cmd.Help, nfs.FILE, FileURI(cmd.GetFileLines()),
)

View File

@ -262,6 +262,12 @@ func HashSelectField(m *ice.Message, key string, field string) (value string) {
func HashSelectTarget(m *ice.Message, key string, create Any) (target Any) {
HashSelectUpdate(m, key, func(value ice.Map) {
target = value[TARGET]
if _target, ok := target.([]string); ok && len(_target) == 0 {
target = nil
}
if _target, ok := target.(ice.List); ok && len(_target) == 0 {
target = nil
}
if _target, ok := target.(Map); ok && len(_target) == 0 {
target = nil
}

View File

@ -13,6 +13,7 @@ import (
type Any = interface{}
type Map = map[string]Any
type Maps = map[string]string
type List = []interface{}
func _file_name(m *ice.Message, arg ...string) string {
if len(arg) > 3 && strings.Contains(arg[3], ice.PS) {

View File

@ -12,6 +12,7 @@ import (
"shylinux.com/x/icebergs/base/ctx"
"shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/nfs"
"shylinux.com/x/icebergs/base/tcp"
kit "shylinux.com/x/toolkits"
"shylinux.com/x/toolkits/miss"
)
@ -181,7 +182,7 @@ func RenderCache(m *ice.Message, h string) {
func Upload(m *ice.Message) []string {
if up := kit.Simple(m.Optionv(ice.MSG_UPLOAD)); len(up) == 1 {
if m.Cmdy(CACHE, UPLOAD).Optionv(ice.MSG_UPLOAD, kit.Simple(m.Append(mdb.HASH), m.Append(mdb.NAME), m.Append(nfs.SIZE))); m.Option(ice.MSG_USERPOD) != "" {
m.Cmd(SPACE, m.Option(ice.MSG_USERPOD), SPIDE, ice.DEV, SPIDE_CACHE, http.MethodGet, MergeURL2(m, path.Join(SHARE_CACHE, m.Append(mdb.HASH))))
m.Cmd(SPACE, m.Option(ice.MSG_USERPOD), SPIDE, ice.DEV, SPIDE_CACHE, http.MethodGet, tcp.PublishLocalhost(m, MergeURL2(m, path.Join(SHARE_CACHE, m.Append(mdb.HASH)))))
}
return kit.Simple(m.Optionv(ice.MSG_UPLOAD))
} else {

View File

@ -26,11 +26,7 @@ func PushNotice(m *ice.Message, arg ...ice.Any) {
msg.Optionv(ice.MSG_OPTS, msg.Optionv(ice.MSG_OPTION, []string{}))
msg.Cmd(SPACE, m.Option(ice.MSG_DAEMON), arg)
} else {
opts := kit.Dict(ice.POD, m.Option(ice.MSG_DAEMON), "cmds", kit.Simple(arg...))
for _, k := range kit.Simple(m.Optionv(ice.MSG_OPTS)) {
opts[k] = m.Option(k)
}
m.Cmd("web.spide", ice.OPS, MergeURL2(m, SHARE_TOAST), kit.Format(opts))
m.Cmd("web.spide", ice.OPS, MergeURL2(m, SHARE_TOAST+m.Option(ice.MSG_DAEMON)), "arg", kit.Format(arg))
}
}
func PushNoticeGrow(m *ice.Message, arg ...ice.Any) {
@ -53,9 +49,9 @@ func ToastProcess(m *ice.Message, arg ...ice.Any) func() {
Toast(m, ice.PROCESS, arg...)
return func() { Toast(m, ice.SUCCESS) }
}
func ToastRestart(m *ice.Message, arg ...ice.Any) { Toast(m, gdb.RESTART, arg...) }
func ToastFailure(m *ice.Message, arg ...ice.Any) { Toast(m, ice.FAILURE, arg...) }
func ToastSuccess(m *ice.Message, arg ...ice.Any) { Toast(m, ice.SUCCESS, arg...) }
func ToastRestart(m *ice.Message, arg ...ice.Any) { Toast(m, gdb.RESTART, arg...) }
func ToastFailure(m *ice.Message, arg ...ice.Any) { Toast(m, ice.FAILURE, arg...) }
func ToastSuccess(m *ice.Message, arg ...ice.Any) { Toast(m, ice.SUCCESS, arg...) }
func Toast(m *ice.Message, text string, arg ...ice.Any) { // [title [duration [progress]]]
if len(arg) > 1 {
switch val := arg[1].(type) {
@ -159,9 +155,9 @@ func MergePodWebSite(m Message, pod, web string, arg ...ice.Any) string {
func ProcessWebsite(m *ice.Message, pod, cmd string, arg ...ice.Any) {
m.ProcessOpen(MergePodCmd(m, pod, cmd, arg...))
}
func ProcessIframe(m *ice.Message, link string, arg ...string) {
func ProcessIframe(m *ice.Message, name, link string, arg ...string) {
if len(arg) == 0 || arg[0] != ice.RUN {
arg = []string{m.Cmdx("web.chat.iframe", mdb.CREATE, mdb.TYPE, LINK, mdb.NAME, "", LINK, link)}
arg = []string{m.Cmdx("web.chat.iframe", mdb.CREATE, mdb.TYPE, LINK, mdb.NAME, name, LINK, link)}
}
ctx.ProcessField(m, "web.chat.iframe", arg, arg...)
}

View File

@ -220,7 +220,7 @@ func init() {
PP(ice.REQUIRE, ice.NODE_MODULES): {Name: "/require/node_modules/", Help: "依赖库", Hand: func(m *ice.Message, arg ...string) {
p := path.Join(ice.SRC, ice.NODE_MODULES, path.Join(arg...))
if !nfs.ExistsFile(m, p) {
m.Cmd(cli.SYSTEM, "npm", "install", arg[0], kit.Dict(cli.CMD_DIR, path.Join(ice.SRC)))
m.Cmd(cli.SYSTEM, "npm", "install", arg[0], kit.Dict(cli.CMD_DIR, ice.SRC))
}
m.RenderDownload(p)
}},

View File

@ -157,7 +157,7 @@ func init() {
m.RenderDownload(strings.TrimPrefix(m.CmdAppend(aaa.USER, m.Option(ice.MSG_USERNAME), aaa.BACKGROUND), SHARE_LOCAL))
}},
SHARE_PROXY: {Hand: func(m *ice.Message, arg ...string) { _share_proxy(m) }},
SHARE_TOAST: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(SPACE, m.Option(ice.POD), m.Optionv("cmds")) }},
SHARE_TOAST: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(SPACE, arg[0], kit.UnMarshal(m.Option("arg"))) }},
})
}
func IsNotValidShare(m *ice.Message, time string) bool {

View File

@ -32,7 +32,7 @@ func init() {
web.RenderCmd(m, web.SPACE)
} else if len(arg) == 1 {
if m.Cmd(web.SPACE, arg[0]).Length() == 0 && !strings.Contains(arg[0], ice.PT) {
m.Cmd(web.DREAM, cli.START, mdb.NAME, arg[0])
m.Cmd(web.DREAM, cli.START, kit.Dict(mdb.NAME, arg[0]))
}
web.RenderMain(aaa.UserRoot(m), arg[0], "")
} else if arg[1] == CMD {

View File

@ -50,8 +50,7 @@ func _xterm_get(m *ice.Message, h string) _xterm {
for {
if n, e := tty.Read(buf); !m.Warn(e) && e == nil {
m.Option(ice.MSG_DAEMON, mdb.HashSelectField(m, h, "view"))
m.Option(mdb.TEXT, string(buf[:n]))
web.PushNoticeGrow(m)
web.PushNoticeGrow(m, string(buf[:n]))
} else {
break
}
@ -94,6 +93,10 @@ func init() {
_xterm_get(m, "").Write(string(b))
}
}},
"debug": {Help: "日志", Hand: func(m *ice.Message, arg ...string) {
_xterm_get(m, kit.Select("", arg, 0)).Write("cd ~/contexts; tail -f var/log/bench.log" + ice.NL)
ctx.ProcessHold(m)
}},
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)
@ -104,7 +107,7 @@ func init() {
m.PushAction(web.WEBSITE, mdb.REMOVE).Action(mdb.CREATE, mdb.PRUNES)
} else {
ctx.Toolkit(m, FAVOR, "web.chat.iframe")
m.Action(INSTALL, "波浪线", "反引号")
m.Action(INSTALL, "debug", "波浪线", "反引号")
ctx.DisplayLocal(m, "")
}
}},

View File

@ -221,6 +221,7 @@ func (m *Message) _command(arg ...Any) *Message {
defer func() { m.Table(val) }()
case func(Maps):
defer func() { m.Tables(val) }()
case nil:
default:
if reflect.TypeOf(val).Kind() == reflect.Func {
cbs = val

View File

@ -21,7 +21,7 @@ func _configs_read(m *ice.Message, p string) ice.Maps {
res, block := ice.Maps{}, ""
m.Cmd(nfs.CAT, p, func(text string) {
if strings.HasPrefix(text, "[") {
block = kit.Join(kit.Split(text, " []"), ".")
block = kit.Join(kit.Split(text, " []"), ice.PT)
return
}
ls := kit.Split(text, " =")

View File

@ -13,6 +13,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/gdb"
"shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/nfs"
@ -114,7 +115,7 @@ func init() {
m.Warn(_server_repos(m, arg...), ice.ErrNotValid)
}}})
Index.MergeCommands(ice.Commands{
SERVER: {Name: "server path commit auto create import", Help: "服务器", Actions: ice.MergeActions(ice.Actions{
SERVER: {Name: "server repos branch commit path auto create import", Help: "服务器", Actions: ice.MergeActions(ice.Actions{
mdb.CREATE: {Name: "create name*", Hand: func(m *ice.Message, arg ...string) {
_repos_init(m, path.Join(ice.USR_LOCAL_REPOS, m.Option(mdb.NAME)))
}},
@ -136,10 +137,33 @@ func init() {
m.Cmd("", func(value ice.Maps) { m.Push(nfs.PATH, _git_url(m, value[nfs.PATH])) })
}
}},
"inner": {Help: "编辑器", Hand: func(m *ice.Message, arg ...string) {
if len(arg) == 0 || arg[0] != ice.RUN {
arg = []string{path.Join(ice.USR_LOCAL_REPOS, arg[0]), kit.Select("README.md", arg, 3)}
} else if kit.Select("", arg, 1) != ctx.ACTION {
if dir := path.Join(ice.USR_LOCAL_REPOS, m.Option(REPOS)); len(arg) < 3 {
_repos_dir(m, dir, m.Option(BRANCH), m.Option(COMMIT), kit.Select("", arg, 1), nil)
} else {
_repos_cat(m, dir, m.Option(BRANCH), m.Option(COMMIT), arg[2])
ctx.DisplayLocal(m, "code/inner.js")
}
return
}
ctx.ProcessField(m, "", arg, arg...)
}},
}, gdb.EventAction(web.DREAM_INPUTS)), Hand: func(m *ice.Message, arg ...string) {
if m.Option(nfs.DIR_ROOT, ice.USR_LOCAL_REPOS); len(arg) == 0 {
m.Cmdy(nfs.DIR, nfs.PWD, func(value ice.Maps) { m.PushScript("git clone " + _git_url(m, value[nfs.PATH])) }).Cut("time,path,size,script,action")
m.Cmdy(nfs.DIR, nfs.PWD, func(value ice.Maps) { m.PushScript("git clone " + _git_url(m, value[nfs.PATH])) }).Cut("time,path,size,script,action").RenameAppend("path", "repos")
} else if dir := path.Join(m.Option(nfs.DIR_ROOT), arg[0]); len(arg) == 1 {
_repos_branch(m, dir)
} else if len(arg) == 2 {
_repos_commit(m, dir, arg[1], nil)
} else if len(arg) == 3 || arg[3] == "" || strings.HasSuffix(arg[3], ice.PS) {
_repos_dir(m, dir, arg[1], arg[2], kit.Select("", arg, 3), nil)
} else {
m.Cmdy("", "inner", arg)
}
m.StatusTimeCount()
}},
})
}