1
0
mirror of https://shylinux.com/x/icebergs synced 2025-04-26 17:44:05 +08:00
This commit is contained in:
harveyshao 2021-11-19 23:25:09 +08:00
parent 9f37afd1c8
commit 3c7a731381
18 changed files with 44 additions and 40 deletions

View File

@ -151,7 +151,7 @@ func _dir_list(m *ice.Message, root string, name string, level int, deep bool, d
return m return m
} }
func _dir_search(m *ice.Message, kind, name string) { func _dir_search(m *ice.Message, kind, name string) {
msg := _dir_list(m.Spawn(), "./", "", 0, true, TYPE_BOTH, nil, kit.Split("time,type,name")) msg := _dir_list(m.Spawn(), ice.PWD, "", 0, true, TYPE_BOTH, nil, kit.Split("time,type,name"))
msg.Table(func(index int, value map[string]string, head []string) { msg.Table(func(index int, value map[string]string, head []string) {
if !strings.Contains(value[kit.MDB_NAME], name) { if !strings.Contains(value[kit.MDB_NAME], name) {
return return
@ -167,10 +167,10 @@ func _dir_search(m *ice.Message, kind, name string) {
func Dir(m *ice.Message, sort string) *ice.Message { func Dir(m *ice.Message, sort string) *ice.Message {
m.Option(DIR_TYPE, TYPE_DIR) m.Option(DIR_TYPE, TYPE_DIR)
m.Copy(m.Cmd(DIR, "./").Sort(sort)) m.Copy(m.Cmd(DIR, ice.PWD).Sort(sort))
m.Option(DIR_TYPE, TYPE_CAT) m.Option(DIR_TYPE, TYPE_CAT)
m.Copy(m.Cmd(DIR, "./").Sort(sort)) m.Copy(m.Cmd(DIR, ice.PWD).Sort(sort))
return m return m
} }
@ -217,7 +217,7 @@ func init() {
if m.Option(DIR_ROOT) != "" { if m.Option(DIR_ROOT) != "" {
m.Info("dir_root: %v", m.Option(DIR_ROOT)) m.Info("dir_root: %v", m.Option(DIR_ROOT))
} }
_dir_list(m, kit.Select("./", m.Option(DIR_ROOT)), kit.Select("./", arg, 0), _dir_list(m, kit.Select(ice.PWD, m.Option(DIR_ROOT)), kit.Select(ice.PWD, arg, 0),
0, m.Option(DIR_DEEP) == ice.TRUE, kit.Select(TYPE_BOTH, m.Option(DIR_TYPE)), kit.Regexp(m.Option(DIR_REG)), 0, m.Option(DIR_DEEP) == ice.TRUE, kit.Select(TYPE_BOTH, m.Option(DIR_TYPE)), kit.Regexp(m.Option(DIR_REG)),
kit.Split(kit.Select(kit.Select("time,path,size,action", m.OptionFields()), kit.Join(kit.Slice(arg, 1))))) kit.Split(kit.Select(kit.Select("time,path,size,action", m.OptionFields()), kit.Join(kit.Slice(arg, 1)))))
m.SortTimeR(kit.MDB_TIME) m.SortTimeR(kit.MDB_TIME)

View File

@ -53,7 +53,7 @@ func init() {
mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) { mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
switch arg[0] { switch arg[0] {
case FILE: case FILE:
m.Cmdy(DIR, kit.Select("./", arg, 1), PATH).RenameAppend(PATH, FILE) m.Cmdy(DIR, kit.Select(ice.PWD, arg, 1), PATH).RenameAppend(PATH, FILE)
m.ProcessAgain() m.ProcessAgain()
case kit.MDB_NAME: case kit.MDB_NAME:
m.Push(arg[0], kit.Split(m.Option(FILE), ice.PS)) m.Push(arg[0], kit.Split(m.Option(FILE), ice.PS))

View File

@ -56,8 +56,7 @@ func init() {
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) == 0 { if len(arg) == 0 {
m.Option(nfs.DIR_ROOT, m.Conf(cli.DAEMON, kit.META_PATH)) m.Option(nfs.DIR_ROOT, m.Conf(cli.DAEMON, kit.META_PATH))
m.Cmd(nfs.DIR, "./", "time,path,size").Table(func(index int, value map[string]string, head []string) { m.Cmd(nfs.DIR, ice.PWD, "time,path,size").Table(func(index int, value map[string]string, head []string) {
m.Debug("what %v", value)
m.Push(kit.MDB_TIME, value[kit.MDB_TIME]) m.Push(kit.MDB_TIME, value[kit.MDB_TIME])
m.Push(PORT, path.Base(value[kit.MDB_PATH])) m.Push(PORT, path.Base(value[kit.MDB_PATH]))
m.Push(kit.MDB_SIZE, value[kit.MDB_SIZE]) m.Push(kit.MDB_SIZE, value[kit.MDB_SIZE])

View File

@ -17,7 +17,7 @@ const CMD = "cmd"
func init() { func init() {
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{ Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
CMD: {Name: CMD, Help: "命令", Value: kit.Data( CMD: {Name: CMD, Help: "命令", Value: kit.Data(
kit.MDB_SHORT, "type", kit.MDB_PATH, "./", kit.MDB_SHORT, "type", kit.MDB_PATH, ice.PWD,
)}, )},
}, Commands: map[string]*ice.Command{ }, Commands: map[string]*ice.Command{
"/cmd/": {Name: "/cmd/", Help: "命令", Action: ice.MergeAction(map[string]*ice.Action{ "/cmd/": {Name: "/cmd/", Help: "命令", Action: ice.MergeAction(map[string]*ice.Action{
@ -65,7 +65,7 @@ func init() {
} else if strings.HasSuffix(m.R.URL.Path, ice.PS) { } else if strings.HasSuffix(m.R.URL.Path, ice.PS) {
m.ProcessLocation("../") m.ProcessLocation("../")
} else { } else {
m.ProcessLocation("./") m.ProcessLocation(ice.PWD)
} }
}}, }},
}, mdb.HashAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { }, mdb.HashAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {

View File

@ -185,7 +185,7 @@ func init() {
}}, }},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if m.Option(nfs.DIR_ROOT, ice.SRC); len(arg) == 0 || strings.HasSuffix(arg[0], ice.PS) { if m.Option(nfs.DIR_ROOT, ice.SRC); len(arg) == 0 || strings.HasSuffix(arg[0], ice.PS) {
m.Cmdy(nfs.DIR, kit.Select("./", arg, 0)) m.Cmdy(nfs.DIR, kit.Select(ice.PWD, arg, 0))
} else { } else {
m.Cmdy(nfs.CAT, arg[0]) m.Cmdy(nfs.CAT, arg[0])
} }

View File

@ -40,7 +40,7 @@ func _pack_dir(m *ice.Message, pack *os.File, dir string) {
m.Option(nfs.DIR_TYPE, nfs.CAT) m.Option(nfs.DIR_TYPE, nfs.CAT)
m.Option(nfs.DIR_ROOT, dir) m.Option(nfs.DIR_ROOT, dir)
m.Cmd(nfs.DIR, "./").Sort(kit.MDB_PATH).Table(func(index int, value map[string]string, head []string) { m.Cmd(nfs.DIR, ice.PWD).Sort(kit.MDB_PATH).Table(func(index int, value map[string]string, head []string) {
if path.Base(value[kit.MDB_PATH]) == "binpack.go" { if path.Base(value[kit.MDB_PATH]) == "binpack.go" {
return return
} }

View File

@ -13,7 +13,7 @@ import (
func _c_tags(m *ice.Message, key string) { func _c_tags(m *ice.Message, key string) {
if _, e := os.Stat(path.Join(m.Option(cli.CMD_DIR), _TAGS)); e != nil { if _, e := os.Stat(path.Join(m.Option(cli.CMD_DIR), _TAGS)); e != nil {
m.Cmd(cli.SYSTEM, "ctags", "-R", "-f", _TAGS, "./") m.Cmd(cli.SYSTEM, "ctags", "-R", "-f", _TAGS, ice.PWD)
} }
_go_tags(m, key) _go_tags(m, key)
} }
@ -71,7 +71,7 @@ func init() {
m.Copy(msg) m.Copy(msg)
return return
} }
m.Cmdy(cli.SYSTEM, "./"+name) m.Cmdy(cli.SYSTEM, ice.PWD+name)
}}, }},
mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) { mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) {
if arg[0] == kit.MDB_FOREACH { if arg[0] == kit.MDB_FOREACH {

View File

@ -86,14 +86,14 @@ func init() {
"run": {Name: "run", Help: "运行", Hand: func(m *ice.Message, arg ...string) { "run": {Name: "run", Help: "运行", Hand: func(m *ice.Message, arg ...string) {
// cli.Follow(m, "run", func() { // cli.Follow(m, "run", func() {
m.Option(cli.CMD_DIR, kit.Select(path.Dir(arg[0]), arg[0], strings.HasSuffix(arg[0], "/"))) m.Option(cli.CMD_DIR, kit.Select(path.Dir(arg[0]), arg[0], strings.HasSuffix(arg[0], "/")))
m.Cmdy(cli.SYSTEM, "go", "test", "./", "-v", "-run="+arg[1]) m.Cmdy(cli.SYSTEM, "go", "test", ice.PWD, "-v", "-run="+arg[1])
// }) // })
}}, }},
"case": {Name: "case", Help: "用例", Hand: func(m *ice.Message, arg ...string) { "case": {Name: "case", Help: "用例", Hand: func(m *ice.Message, arg ...string) {
msg := m.Spawn() msg := m.Spawn()
if strings.HasSuffix(arg[0], "/") { if strings.HasSuffix(arg[0], "/") {
msg.Option(cli.CMD_DIR, arg[0]) msg.Option(cli.CMD_DIR, arg[0])
msg.Split(msg.Cmdx(cli.SYSTEM, "grep", "-r", "func Test.*(", "./"), "file:line", ":", "\n") msg.Split(msg.Cmdx(cli.SYSTEM, "grep", "-r", "func Test.*(", ice.PWD), "file:line", ":", "\n")
msg.Table(func(index int, value map[string]string, head []string) { msg.Table(func(index int, value map[string]string, head []string) {
if strings.HasPrefix(strings.TrimSpace(value["line"]), "//") { if strings.HasPrefix(strings.TrimSpace(value["line"]), "//") {
return return
@ -111,7 +111,7 @@ func init() {
}}, }},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) == 0 || arg[0] == "" { if len(arg) == 0 || arg[0] == "" {
m.Cmdy(nfs.DIR, "./") m.Cmdy(nfs.DIR, ice.PWD)
return return
} }
if len(arg) == 1 { if len(arg) == 1 {
@ -127,7 +127,7 @@ func init() {
} }
m.Option(cli.CMD_DIR, kit.Select(path.Dir(arg[0]), arg[0], strings.HasSuffix(arg[0], "/"))) m.Option(cli.CMD_DIR, kit.Select(path.Dir(arg[0]), arg[0], strings.HasSuffix(arg[0], "/")))
m.Cmdy(cli.SYSTEM, "go", "test", "./", "-v", "-run="+arg[1]) m.Cmdy(cli.SYSTEM, "go", "test", ice.PWD, "-v", "-run="+arg[1])
}}, }},
}}) }})
} }

View File

@ -15,7 +15,7 @@ import (
func _go_tags(m *ice.Message, key string) { func _go_tags(m *ice.Message, key string) {
if s, e := os.Stat(path.Join(m.Option(cli.CMD_DIR), _TAGS)); os.IsNotExist(e) || s.ModTime().Before(time.Now().Add(kit.Duration("-72h"))) { if s, e := os.Stat(path.Join(m.Option(cli.CMD_DIR), _TAGS)); os.IsNotExist(e) || s.ModTime().Before(time.Now().Add(kit.Duration("-72h"))) {
m.Cmd(cli.SYSTEM, "gotags", "-R", "-f", _TAGS, "./") m.Cmd(cli.SYSTEM, "gotags", "-R", "-f", _TAGS, ice.PWD)
} }
ls := strings.Split(key, ice.PT) ls := strings.Split(key, ice.PT)
@ -40,7 +40,7 @@ func _go_tags(m *ice.Message, key string) {
bio := bufio.NewScanner(f) bio := bufio.NewScanner(f)
for i := 1; bio.Scan(); i++ { for i := 1; bio.Scan(); i++ {
if i == line || bio.Text() == text { if i == line || bio.Text() == text {
m.PushSearch(ice.CMD, "tags", kit.MDB_FILE, strings.TrimPrefix(file, "./"), kit.MDB_LINE, kit.Format(i), kit.MDB_TEXT, bio.Text()) m.PushSearch(ice.CMD, "tags", kit.MDB_FILE, strings.TrimPrefix(file, ice.PWD), kit.MDB_LINE, kit.Format(i), kit.MDB_TEXT, bio.Text())
} }
} }
} }
@ -57,7 +57,7 @@ func _go_find(m *ice.Message, key string) {
if p == "" { if p == "" {
continue continue
} }
m.PushSearch(ice.CMD, FIND, kit.MDB_FILE, strings.TrimPrefix(p, "./"), kit.MDB_LINE, 1, kit.MDB_TEXT, "") m.PushSearch(ice.CMD, FIND, kit.MDB_FILE, strings.TrimPrefix(p, ice.PWD), kit.MDB_LINE, 1, kit.MDB_TEXT, "")
} }
} }
func _go_grep(m *ice.Message, key string) { func _go_grep(m *ice.Message, key string) {
@ -103,9 +103,9 @@ func init() {
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) {
m.Option(cli.CMD_DIR, arg[2]) m.Option(cli.CMD_DIR, arg[2])
if strings.HasSuffix(arg[1], "test.go") { if strings.HasSuffix(arg[1], "test.go") {
m.Cmdy(cli.SYSTEM, GO, "test", "-v", "./"+arg[1]) m.Cmdy(cli.SYSTEM, GO, "test", "-v", ice.PWD+arg[1])
} else { } else {
m.Cmdy(cli.SYSTEM, GO, "run", "./"+arg[1]) m.Cmdy(cli.SYSTEM, GO, "run", ice.PWD+arg[1])
} }
m.Set(ice.MSG_APPEND) m.Set(ice.MSG_APPEND)
}}, }},

View File

@ -188,7 +188,7 @@ func init() {
default: // 目录列表 default: // 目录列表
m.Option(nfs.DIR_ROOT, path.Join(m.Conf(cli.DAEMON, kit.META_PATH), arg[1])) m.Option(nfs.DIR_ROOT, path.Join(m.Conf(cli.DAEMON, kit.META_PATH), arg[1]))
m.Cmdy(nfs.CAT, kit.Select("./", arg, 2)) m.Cmdy(nfs.CAT, kit.Select(ice.PWD, arg, 2))
} }
}}, }},
}}) }})

View File

@ -53,7 +53,7 @@ func _publish_list(m *ice.Message, arg ...string) {
m.Option(nfs.DIR_DEEP, ice.TRUE) m.Option(nfs.DIR_DEEP, ice.TRUE)
m.Option(nfs.DIR_REG, kit.Select("", arg, 0)) m.Option(nfs.DIR_REG, kit.Select("", arg, 0))
m.Option(nfs.DIR_ROOT, m.Config(kit.MDB_PATH)) m.Option(nfs.DIR_ROOT, m.Config(kit.MDB_PATH))
m.Cmdy(nfs.DIR, "./", kit.Select("time,size,line,path,link", arg, 1)) m.Cmdy(nfs.DIR, ice.PWD, kit.Select("time,size,line,path,link", arg, 1))
} }
const PUBLISH = "publish" const PUBLISH = "publish"

View File

@ -85,6 +85,10 @@ func init() {
if pod := msg.Append(kit.KeyExtra(ice.POD)); pod != "" { if pod := msg.Append(kit.KeyExtra(ice.POD)); pod != "" {
m.Option(ice.POD, pod) m.Option(ice.POD, pod)
} }
m.Debug(msg.FormatMeta())
m.Debug("what %v", kit.KeyExtra(ice.CTX))
m.Debug("what %v", msg.Append(kit.KeyExtra(ice.CTX)))
m.Debug("what %v", msg.Append(kit.KeyExtra(ice.CMD)))
args := kit.Simple(kit.Keys(msg.Append(kit.KeyExtra(ice.CTX)), msg.Append(kit.KeyExtra(ice.CMD))), arg[2:]) args := kit.Simple(kit.Keys(msg.Append(kit.KeyExtra(ice.CTX)), msg.Append(kit.KeyExtra(ice.CMD))), arg[2:])
if !m.PodCmd(args) { if !m.PodCmd(args) {
m.Cmdy(args) m.Cmdy(args)

View File

@ -21,7 +21,7 @@ func init() {
_wiki_save(m, m.CommandKey(), arg[0], arg[1]) _wiki_save(m, m.CommandKey(), arg[0], arg[1])
}}, }},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if !_wiki_list(m, m.CommandKey(), kit.Select("./", arg, 0)) { if !_wiki_list(m, m.CommandKey(), kit.Select(ice.PWD, arg, 0)) {
m.CSV(m.Cmd(nfs.CAT, arg[0]).Result()) m.CSV(m.Cmd(nfs.CAT, arg[0]).Result())
} }
}}, }},

View File

@ -1,8 +1,6 @@
package wiki package wiki
import ( import (
"path"
ice "shylinux.com/x/icebergs" ice "shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/base/ctx" "shylinux.com/x/icebergs/base/ctx"
"shylinux.com/x/icebergs/base/nfs" "shylinux.com/x/icebergs/base/nfs"
@ -15,15 +13,15 @@ func init() {
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{ Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
DRAW: {Name: DRAW, Help: "思维导图", Value: kit.Data(kit.MDB_REGEXP, ".*\\.svg")}, DRAW: {Name: DRAW, Help: "思维导图", Value: kit.Data(kit.MDB_REGEXP, ".*\\.svg")},
}, Commands: map[string]*ice.Command{ }, Commands: map[string]*ice.Command{
DRAW: {Name: "draw path=src/main.svg refresh:button=auto edit save project actions", Help: "思维导图", Meta: kit.Dict( DRAW: {Name: "draw path=src/main.svg pid refresh:button=auto edit save actions", Help: "思维导图", Meta: kit.Dict(
ice.Display("/plugin/local/wiki/draw.js"), ice.DisplayLocal(""),
), Action: ice.MergeAction(map[string]*ice.Action{ ), Action: ice.MergeAction(map[string]*ice.Action{
nfs.SAVE: {Name: "save path", Help: "保存", Hand: func(m *ice.Message, arg ...string) { nfs.SAVE: {Name: "save", Help: "保存", Hand: func(m *ice.Message, arg ...string) {
_wiki_save(m, DRAW, path.Join(arg...), m.Option(kit.MDB_CONTENT)) _wiki_save(m, DRAW, arg[0], m.Option(kit.MDB_CONTENT))
}}, }},
}, ctx.CmdAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { }, ctx.CmdAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if !_wiki_list(m, DRAW, kit.Select("./", path.Join(arg...))) { if !_wiki_list(m, DRAW, kit.Select(ice.PWD, arg, 0)) {
_wiki_show(m, DRAW, path.Join(arg...)) _wiki_show(m, DRAW, arg[0])
} }
}}, }},
}}) }})

View File

@ -28,7 +28,7 @@ func init() {
os.Remove(strings.TrimPrefix(arg[0], "/share/local/")) os.Remove(strings.TrimPrefix(arg[0], "/share/local/"))
}}, }},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
_wiki_list(m, m.CommandKey(), kit.Select("./", arg, 0)) _wiki_list(m, m.CommandKey(), kit.Select(ice.PWD, arg, 0))
}}, }},
}}) }})
} }

View File

@ -70,7 +70,7 @@ func init() {
m.Echo(`</div>`) m.Echo(`</div>`)
}}, }},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if !_wiki_list(m, JSON, kit.Select("./", arg, 0)) { if !_wiki_list(m, JSON, kit.Select(ice.PWD, arg, 0)) {
m.Cmdy(nfs.CAT, arg[0]) m.Cmdy(nfs.CAT, arg[0])
} }
}}, }},

View File

@ -42,12 +42,12 @@ func _wiki_list(m *ice.Message, cmd string, arg ...string) bool {
if len(arg) == 0 || strings.HasSuffix(arg[0], ice.PS) { if len(arg) == 0 || strings.HasSuffix(arg[0], ice.PS) {
if m.Option(nfs.DIR_DEEP) != ice.TRUE { // 目录列表 if m.Option(nfs.DIR_DEEP) != ice.TRUE { // 目录列表
m.Option(nfs.DIR_TYPE, nfs.DIR) m.Option(nfs.DIR_TYPE, nfs.DIR)
m.Cmdy(nfs.DIR, kit.Select("./", arg, 0)) m.Cmdy(nfs.DIR, kit.Select(ice.PWD, arg, 0))
} }
// 文件列表 // 文件列表
m.Option(nfs.DIR_TYPE, nfs.CAT) m.Option(nfs.DIR_TYPE, nfs.CAT)
m.Cmdy(nfs.DIR, kit.Select("./", arg, 0)) m.Cmdy(nfs.DIR, kit.Select(ice.PWD, arg, 0))
return true return true
} }
return false return false

View File

@ -320,13 +320,16 @@ func (c *Context) split(name string) (list []interface{}) {
} }
func Display(file string, arg ...string) map[string]string { func Display(file string, arg ...string) map[string]string {
return Display0(2, file, arg...)
}
func DisplayLocal(file string, arg ...string) map[string]string {
if file == "" { if file == "" {
file = kit.FileName(2) + ".js" file = path.Join(kit.PathName(2), kit.FileName(2)+".js")
} }
if !strings.HasPrefix(file, "/") { if !strings.HasPrefix(file, "/") {
file = path.Join("/require", kit.ModPath(2, file)) file = path.Join("/plugin/local", file)
} }
return map[string]string{"display": file, kit.MDB_STYLE: kit.Join(arg, " ")} return Display0(2, file, arg...)
} }
func Display0(n int, file string, arg ...string) map[string]string { func Display0(n int, file string, arg ...string) map[string]string {
if file == "" { if file == "" {