1
0
mirror of https://shylinux.com/x/icebergs synced 2025-05-06 13:17:03 +08:00
This commit is contained in:
harveyshao 2023-01-10 21:42:28 +08:00
parent d131489b19
commit 511204504c
5 changed files with 60 additions and 11 deletions

View File

@ -126,8 +126,8 @@ func init() {
} }
}}, }},
}, Hand: func(m *ice.Message, arg ...string) { }, Hand: func(m *ice.Message, arg ...string) {
m.Option(FG, kit.Select(kit.Select(BLUE, CYAN, m.Option(ice.TOPIC) == BLACK), arg, 1)) m.Option(FG, kit.Select(kit.Select(CYAN, BLUE, m.Option(ice.TOPIC) == WHITE), arg, 1))
m.Option(BG, kit.Select(kit.Select(WHITE, BLACK, m.Option(ice.TOPIC) == BLACK), arg, 2)) m.Option(BG, kit.Select(kit.Select(BLACK, WHITE, m.Option(ice.TOPIC) == WHITE), arg, 2))
if m.IsCliUA() { if m.IsCliUA() {
_qrcode_cli(m, kit.Select(kit.Select(ice.Info.Make.Domain, ice.Info.Domain), arg, 0)) _qrcode_cli(m, kit.Select(kit.Select(ice.Info.Make.Domain, ice.Info.Domain), arg, 0))
} else { } else {

View File

@ -167,15 +167,16 @@ func RenderMain(m *ice.Message, pod, index string, arg ...ice.Any) *ice.Message
func RenderCmd(m *ice.Message, cmd string, arg ...ice.Any) { func RenderCmd(m *ice.Message, cmd string, arg ...ice.Any) {
RenderPodCmd(m, "", cmd, arg...) RenderPodCmd(m, "", cmd, arg...)
} }
func RenderCmds(m *ice.Message, list ...ice.Any) {
m.Echo(kit.Renders(_cmd_template, ice.Maps{"version": renderVersion(m), "list": kit.Format(list)})).RenderResult()
}
func RenderPodCmd(m *ice.Message, pod, cmd string, arg ...ice.Any) { func RenderPodCmd(m *ice.Message, pod, cmd string, arg ...ice.Any) {
msg := m.Cmd(Space(m, pod), ctx.COMMAND, kit.Select("web.wiki.word", cmd)) msg := m.Cmd(Space(m, pod), ctx.COMMAND, kit.Select("web.wiki.word", cmd))
list := kit.Format(kit.List(kit.Dict(msg.AppendSimple(mdb.NAME, mdb.HELP), list := kit.Format(kit.List(kit.Dict(msg.AppendSimple(mdb.NAME, mdb.HELP),
ctx.INDEX, cmd, ctx.ARGS, kit.Simple(arg), ctx.DISPLAY, m.Option(ice.MSG_DISPLAY), ctx.INDEX, cmd, ctx.ARGS, kit.Simple(arg), ctx.DISPLAY, m.Option(ice.MSG_DISPLAY),
mdb.LIST, kit.UnMarshal(msg.Append(mdb.LIST)), mdb.META, kit.UnMarshal(msg.Append(mdb.META)), mdb.LIST, kit.UnMarshal(msg.Append(mdb.LIST)), mdb.META, kit.UnMarshal(msg.Append(mdb.META)),
))) )))
m.Echo(kit.Renders(_cmd_template, ice.Maps{ m.Echo(kit.Renders(_cmd_template, ice.Maps{"version": renderVersion(m), "list": list})).RenderResult()
"version": renderVersion(m), "list": list,
})).RenderResult()
} }
func renderVersion(m *ice.Message) string { func renderVersion(m *ice.Message) string {
if strings.Contains(m.R.URL.RawQuery, "debug=true") { if strings.Contains(m.R.URL.RawQuery, "debug=true") {

View File

@ -89,10 +89,17 @@ func init() {
if m.Option(nfs.CONTENT) == "" { if m.Option(nfs.CONTENT) == "" {
m.Option(nfs.CONTENT, m.Cmdx("", TEMPLATE)) m.Option(nfs.CONTENT, m.Cmdx("", TEMPLATE))
} }
switch m.Cmdy(nfs.SAVE, path.Join(m.Option(nfs.PATH), m.Option(nfs.FILE))); m.Option(nfs.FILE) { p := path.Join(m.Option(nfs.PATH), m.Option(nfs.FILE))
switch m.Cmd(nfs.SAVE, p); m.Option(nfs.FILE) {
case "proto.js", "page/index.css": case "proto.js", "page/index.css":
m.Cmd("", DEVPACK) m.Cmd("", DEVPACK)
} }
switch arg[0] {
case nfs.GO:
m.Cmd(cli.SYSTEM, "gofmt", "-w", p)
m.Cmd(cli.SYSTEM, "goimports", "-w", p)
m.Cmdy(nfs.CAT, p)
}
}}, }},
nfs.TRASH: {Hand: func(m *ice.Message, arg ...string) { nfs.Trash(m, arg[0]) }}, 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.SCRIPT: {Name: "script file*=hi/hi.js", Help: "脚本", Hand: func(m *ice.Message, arg ...string) {

View File

@ -89,11 +89,17 @@ func _repos_commit(m *ice.Message, dir, branch string, cb func(*gogit.Commit, *g
} }
} }
func _repos_dir(m *ice.Message, dir, branch, commit, file string, cb func(*gogit.TreeEntry, *gogit.Repository) bool) { func _repos_dir(m *ice.Message, dir, branch, commit, file string, cb func(*gogit.TreeEntry, *gogit.Repository) bool) {
if commit == cli.PWD { if commit == cli.PWD && strings.HasPrefix(dir, ".git") {
nfs.DirDeepAll(m, path.Dir(dir), file, nil, "time,line,path") nfs.DirDeepAll(m, path.Dir(dir), file, nil, "time,line,path")
m.Option(cli.CMD_DIR, path.Dir(dir)) m.Option(cli.CMD_DIR, path.Dir(dir))
m.Echo(_git_cmds(m, DIFF)) m.Echo(_git_cmds(m, DIFF))
return return
} else if commit == cli.PWD {
if repos, e := gogit.OpenRepository(dir); !m.Warn(e, ice.ErrNotFound, dir) {
if refer, e := repos.LookupReference(REFS_HEADS + branch); !m.Warn(e, ice.ErrNotFound, branch) {
commit = refer.Oid.String()
}
}
} else if file == nfs.PWD { } else if file == nfs.PWD {
file = "" file = ""
} }
@ -114,10 +120,15 @@ func _repos_dir(m *ice.Message, dir, branch, commit, file string, cb func(*gogit
} }
if tree, e := repos.LookupTree(ci.TreeId()); !m.Warn(e, ice.ErrNotValid, ci.TreeId().String) { if tree, e := repos.LookupTree(ci.TreeId()); !m.Warn(e, ice.ErrNotValid, ci.TreeId().String) {
m.Logs(mdb.SELECT, REPOS, dir, BRANCH, branch, COMMIT, commit, "tree", tree.Oid.Short()) m.Logs(mdb.SELECT, REPOS, dir, BRANCH, branch, COMMIT, commit, "tree", tree.Oid.Short())
m.Logs("what", file, file)
tree.Walk(func(p string, v *gogit.TreeEntry) bool { tree.Walk(func(p string, v *gogit.TreeEntry) bool {
if pp := path.Join(p, v.Name) + kit.Select("", ice.PS, v.Type == gogit.ObjectTree); strings.HasPrefix(pp, file) { if pp := path.Join(p, v.Name) + kit.Select("", ice.PS, v.Type == gogit.ObjectTree); strings.HasPrefix(pp, file) {
m.Logs("what", file, pp)
if cb == nil { if cb == nil {
if v.Type == gogit.ObjectTree { m.Logs("what", file, pp)
if path.Dir(file) != path.Dir(pp) {
} else if v.Type == gogit.ObjectTree {
} else if id, ok := prev[pp]; ok && id == v.Oid.String() { } else if id, ok := prev[pp]; ok && id == v.Oid.String() {
if m.Option("_index") == web.CODE_INNER { if m.Option("_index") == web.CODE_INNER {
@ -130,13 +141,20 @@ func _repos_dir(m *ice.Message, dir, branch, commit, file string, cb func(*gogit
} }
delete(prev, pp) delete(prev, pp)
} else if cb(v, repos) { } else if cb(v, repos) {
m.Logs("what", file, pp)
return true return true
} }
} }
return false return false
}) })
} }
kit.Fetch(prev, func(pp, id string) { m.Push(mdb.HASH, id[:6]).Push(nfs.PATH, pp).Push(mdb.STATUS, "---") }) kit.Fetch(prev, func(pp, id string) {
m.Logs("what", path.Dir(file), path.Dir(pp))
if path.Dir(file) != path.Dir(pp) {
return
}
m.Push(mdb.HASH, id[:6]).Push(nfs.PATH, pp).Push(mdb.STATUS, "---")
})
if m.Sort(kit.Fields(mdb.STATUS, nfs.PATH), ice.STR_R, ice.STR); cb == nil { if m.Sort(kit.Fields(mdb.STATUS, nfs.PATH), ice.STR_R, ice.STR); cb == nil {
m.Option(cli.CMD_DIR, dir) m.Option(cli.CMD_DIR, dir)
m.Echo(_git_cmds(m, DIFF, ci.Oid.String()+"^", ci.Oid.String())) m.Echo(_git_cmds(m, DIFF, ci.Oid.String()+"^", ci.Oid.String()))
@ -146,9 +164,15 @@ func _repos_dir(m *ice.Message, dir, branch, commit, file string, cb func(*gogit
}) })
} }
func _repos_cat(m *ice.Message, dir, branch, commit, file string) { func _repos_cat(m *ice.Message, dir, branch, commit, file string) {
if commit == cli.PWD { if commit == cli.PWD && strings.HasPrefix(dir, ".git") {
m.Cmdy(nfs.CAT, path.Join(path.Dir(dir), file)) m.Cmdy(nfs.CAT, path.Join(path.Dir(dir), file))
return return
} else if commit == cli.PWD {
if repos, e := gogit.OpenRepository(dir); !m.Warn(e, ice.ErrNotFound, dir) {
if refer, e := repos.LookupReference(REFS_HEADS + branch); !m.Warn(e, ice.ErrNotFound, branch) {
commit = refer.Oid.String()
}
}
} }
_repos_dir(m, dir, branch, commit, file, func(v *gogit.TreeEntry, repos *gogit.Repository) bool { _repos_dir(m, dir, branch, commit, file, func(v *gogit.TreeEntry, repos *gogit.Repository) bool {
if blob, e := repos.LookupBlob(v.Oid); e == nil { if blob, e := repos.LookupBlob(v.Oid); e == nil {

View File

@ -92,7 +92,13 @@ const (
const SERVER = "server" const SERVER = "server"
func init() { func init() {
web.Index.MergeCommands(ice.Commands{"/x/": {Actions: aaa.WhiteAction(), Hand: func(m *ice.Message, arg ...string) { web.Index.MergeCommands(ice.Commands{"/x/": {Actions: ice.MergeActions(ctx.CmdAction(), aaa.WhiteAction()), Hand: func(m *ice.Message, arg ...string) {
if !m.IsCliUA() {
web.RenderCmds(m,
kit.Dict(ctx.DISPLAY, "/plugin/local/code/repos.js", ctx.INDEX, "web.code.git.inner", ctx.ARGS, kit.List(strings.TrimSuffix(arg[0], ".git"), kit.Select("master", arg, 1), "pwd", kit.Select("README.md", path.Join(kit.Slice(arg, 2)...)))),
)
return
}
if m.RenderVoid(); m.Option("go-get") == "1" { if m.RenderVoid(); m.Option("go-get") == "1" {
p := _git_url(m, path.Join(arg...)) p := _git_url(m, path.Join(arg...))
m.RenderResult(kit.Format(`<meta name="go-import" content="%s">`, kit.Format(`%s git %s`, strings.TrimSuffix(strings.Split(p, "://")[1], ".git"), p))) m.RenderResult(kit.Format(`<meta name="go-import" content="%s">`, kit.Format(`%s git %s`, strings.TrimSuffix(strings.Split(p, "://")[1], ".git"), p)))
@ -115,6 +121,17 @@ func init() {
m.Warn(_server_repos(m, arg...), ice.ErrNotValid) m.Warn(_server_repos(m, arg...), ice.ErrNotValid)
}}}) }}})
Index.MergeCommands(ice.Commands{ Index.MergeCommands(ice.Commands{
"inner": {Name: "inner repos branch commit path auto", Help: "服务器", Actions: ice.MergeActions(ice.Actions{}), Hand: func(m *ice.Message, arg ...string) {
if m.Option(nfs.DIR_ROOT, ice.USR_LOCAL_REPOS); len(arg) == 0 {
} else if dir := path.Join(m.Option(nfs.DIR_ROOT), arg[0]); len(arg) == 1 {
} else if len(arg) == 2 {
} else if len(arg) == 3 || strings.HasSuffix(arg[3], "/") {
_repos_dir(m, dir, arg[1], arg[2], kit.Select("", arg, 3), nil)
} else {
m.Option("file", kit.Select("", arg, 3))
_repos_cat(m, dir, arg[1], arg[2], kit.Select("", arg, 3))
}
}},
SERVER: {Name: "server repos branch commit path 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) { 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))) _repos_init(m, path.Join(ice.USR_LOCAL_REPOS, m.Option(mdb.NAME)))