forked from x/icebergs
add 20200202
This commit is contained in:
parent
f00e1e17f8
commit
b82e74f038
1
base.go
1
base.go
@ -58,6 +58,7 @@ var Index = &Context{Name: "ice", Help: "冰山模块",
|
||||
Caches: map[string]*Cache{
|
||||
CTX_STATUS: {Value: "begin"},
|
||||
CTX_STREAM: {Value: "shy"},
|
||||
CTX_FOLLOW: {Value: ""},
|
||||
},
|
||||
Configs: map[string]*Config{
|
||||
"table": {Name: "数据缓存", Value: map[string]interface{}{
|
||||
|
@ -16,25 +16,46 @@ var Index = &ice.Context{Name: "ctx", Help: "配置模块",
|
||||
ice.CTX_CONFIG: {Name: "config", Help: "配置", Value: kit.Data("path", "var/conf")},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
ice.CTX_CONTEXT: {Name: "context", Help: "模块", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
ice.Pulse.Travel(func(p *ice.Context, s *ice.Context) {
|
||||
if p != nil {
|
||||
m.Push("ups", p.Name)
|
||||
} else {
|
||||
m.Push("ups", "shy")
|
||||
ice.CTX_CONTEXT: {Name: "context [all]", Help: "模块", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
all := false
|
||||
if len(arg) > 0 && arg[0] == "all" {
|
||||
all, arg = true, arg[1:]
|
||||
}
|
||||
|
||||
if p := m.Spawn(m.Source()); len(arg) == 0 {
|
||||
if all == true {
|
||||
p = ice.Pulse
|
||||
}
|
||||
m.Push("name", s.Name)
|
||||
m.Push(ice.CTX_STATUS, s.Cap(ice.CTX_STATUS))
|
||||
m.Push(ice.CTX_STREAM, s.Cap(ice.CTX_STREAM))
|
||||
m.Push("help", s.Help)
|
||||
})
|
||||
// 模块列表
|
||||
p.Travel(func(p *ice.Context, s *ice.Context) {
|
||||
if p != nil {
|
||||
m.Push("ups", p.Name)
|
||||
} else {
|
||||
m.Push("ups", "shy")
|
||||
}
|
||||
m.Push("name", s.Name)
|
||||
m.Push(ice.CTX_STATUS, s.Cap(ice.CTX_STATUS))
|
||||
m.Push(ice.CTX_STREAM, s.Cap(ice.CTX_STREAM))
|
||||
m.Push("help", s.Help)
|
||||
})
|
||||
}
|
||||
}},
|
||||
ice.CTX_COMMAND: {Name: "command", Help: "命令", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
ice.Pulse.Travel(func(p *ice.Context, s *ice.Context) {
|
||||
ice.CTX_COMMAND: {Name: "command [all] [context [command run arg...]]", Help: "命令", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
all := false
|
||||
if len(arg) > 0 && arg[0] == "all" {
|
||||
all, arg = true, arg[1:]
|
||||
}
|
||||
|
||||
if p := m.Spawn(m.Source()); len(arg) == 0 {
|
||||
if all == true {
|
||||
p = ice.Pulse
|
||||
}
|
||||
// 命令列表
|
||||
p.Travel(func(p *ice.Context, s *ice.Context) {
|
||||
list := []string{}
|
||||
for k := range s.Commands {
|
||||
if k[0] == '/' || k[0] == '_' {
|
||||
// 内部命令
|
||||
continue
|
||||
}
|
||||
list = append(list, k)
|
||||
@ -43,11 +64,7 @@ var Index = &ice.Context{Name: "ctx", Help: "配置模块",
|
||||
|
||||
for _, k := range list {
|
||||
v := s.Commands[k]
|
||||
if p != nil && p != ice.Index {
|
||||
m.Push("key", p.Name+"."+s.Name)
|
||||
} else {
|
||||
m.Push("key", s.Name)
|
||||
}
|
||||
m.Push("key", s.Cap(ice.CTX_FOLLOW))
|
||||
m.Push("index", k)
|
||||
m.Push("name", v.Name)
|
||||
m.Push("help", v.Help)
|
||||
@ -64,22 +81,35 @@ var Index = &ice.Context{Name: "ctx", Help: "配置模块",
|
||||
arg = arg[1:]
|
||||
m.Search(chain, func(p *ice.Context, s *ice.Context, key string, cmd *ice.Command) {
|
||||
if len(arg) == 0 {
|
||||
// 命令列表
|
||||
m.Push("name", cmd.Name)
|
||||
m.Push("help", cmd.Help)
|
||||
m.Push("meta", kit.Format(cmd.Meta))
|
||||
m.Push("list", kit.Format(cmd.List))
|
||||
} else {
|
||||
if you := m.Option(kit.Format(kit.Value(cmd.Meta, "remote"))); you != "" {
|
||||
// 远程命令
|
||||
m.Copy(m.Spawns(s).Cmd("web.space", you, "ctx.command", chain, "run", arg[1:]))
|
||||
} else {
|
||||
// 本地命令
|
||||
m.Copy(s.Run(m.Spawns(s), cmd, key, arg[1:]...))
|
||||
}
|
||||
}
|
||||
})
|
||||
}},
|
||||
ice.CTX_CONFIG: {Name: "config", Help: "配置", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
ice.CTX_CONFIG: {Name: "config [all] save|load", Help: "配置", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
all := false
|
||||
if len(arg) > 0 && arg[0] == "all" {
|
||||
all, arg = true, arg[1:]
|
||||
}
|
||||
|
||||
msg := m.Spawn(m.Source())
|
||||
if len(arg) == 0 {
|
||||
ice.Pulse.Travel(func(p *ice.Context, s *ice.Context, key string, conf *ice.Config) {
|
||||
if all == true {
|
||||
msg = ice.Pulse
|
||||
}
|
||||
// 配置列表
|
||||
msg.Travel(func(p *ice.Context, s *ice.Context, key string, conf *ice.Config) {
|
||||
m.Push("key", key)
|
||||
m.Push("name", conf.Name)
|
||||
m.Push("value", kit.Format(conf.Value))
|
||||
@ -89,11 +119,12 @@ var Index = &ice.Context{Name: "ctx", Help: "配置模块",
|
||||
|
||||
switch arg[0] {
|
||||
case "save":
|
||||
arg[1] = path.Join(m.Conf(ice.CTX_CONFIG, ice.Meta("path")), arg[1])
|
||||
// 保存配置
|
||||
arg[1] = path.Join(msg.Conf(ice.CTX_CONFIG, ice.Meta("path")), arg[1])
|
||||
if f, p, e := kit.Create(arg[1]); m.Assert(e) {
|
||||
data := map[string]interface{}{}
|
||||
for _, k := range arg[2:] {
|
||||
data[k] = m.Confv(k)
|
||||
data[k] = msg.Confv(k)
|
||||
}
|
||||
if s, e := json.MarshalIndent(data, "", " "); m.Assert(e) {
|
||||
if n, e := f.Write(s); m.Assert(e) {
|
||||
@ -103,13 +134,14 @@ var Index = &ice.Context{Name: "ctx", Help: "配置模块",
|
||||
m.Echo(p)
|
||||
}
|
||||
case "load":
|
||||
arg[1] = path.Join(m.Conf(ice.CTX_CONFIG, ice.Meta("path")), arg[1])
|
||||
// 加载配置
|
||||
arg[1] = path.Join(msg.Conf(ice.CTX_CONFIG, ice.Meta("path")), arg[1])
|
||||
if f, e := os.Open(arg[1]); e == nil {
|
||||
data := map[string]interface{}{}
|
||||
json.NewDecoder(f).Decode(&data)
|
||||
|
||||
for k, v := range data {
|
||||
m.Search(k, func(p *ice.Context, s *ice.Context, key string) {
|
||||
msg.Search(k, func(p *ice.Context, s *ice.Context, key string) {
|
||||
m.Log("info", "load %s.%s %v", s.Name, key, kit.Format(v))
|
||||
s.Configs[key].Value = v
|
||||
})
|
||||
@ -117,12 +149,15 @@ var Index = &ice.Context{Name: "ctx", Help: "配置模块",
|
||||
}
|
||||
default:
|
||||
if len(arg) > 2 {
|
||||
m.Conf(arg[0], arg[1], arg[2])
|
||||
// 修改配置
|
||||
msg.Conf(arg[0], arg[1], arg[2])
|
||||
}
|
||||
if len(arg) > 1 {
|
||||
m.Echo(m.Conf(arg[0], arg[1]))
|
||||
// 读取配置
|
||||
m.Echo(msg.Conf(arg[0], arg[1]))
|
||||
} else {
|
||||
m.Echo(kit.Formats(m.Confv(arg[0])))
|
||||
// 读取配置
|
||||
m.Echo(kit.Formats(msg.Confv(arg[0])))
|
||||
}
|
||||
}
|
||||
}},
|
||||
|
@ -141,10 +141,8 @@ var Index = &ice.Context{Name: "nfs", Help: "存储模块",
|
||||
Caches: map[string]*ice.Cache{},
|
||||
Configs: map[string]*ice.Config{},
|
||||
Commands: map[string]*ice.Command{
|
||||
ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
}},
|
||||
ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
}},
|
||||
ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}},
|
||||
ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}},
|
||||
|
||||
"dir": {Name: "dir", Help: "目录", List: kit.List(
|
||||
kit.MDB_INPUT, "text", "name", "path", "action", "auto",
|
||||
@ -155,6 +153,17 @@ var Index = &ice.Context{Name: "nfs", Help: "存储模块",
|
||||
dir(m, kit.Select("./", m.Option("dir_root")), kit.Select("", arg, 0), 0, m.Options("dir_deep"), "both", rg,
|
||||
strings.Split(kit.Select("time size line path", arg, 1), " "), ice.ICE_TIME)
|
||||
}},
|
||||
"cat": {Name: "cat path", Help: "保存", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if f, e := os.OpenFile(arg[0], os.O_RDONLY, 0777); m.Assert(e) {
|
||||
defer f.Close()
|
||||
buf := make([]byte, 1024)
|
||||
if n, e := f.Read(buf); m.Assert(e) {
|
||||
m.Log(ice.LOG_IMPORT, "%d: %s", n, arg[0])
|
||||
m.Echo(string(buf[:n]))
|
||||
}
|
||||
}
|
||||
}},
|
||||
|
||||
"save": {Name: "save path text", Help: "保存", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if f, p, e := kit.Create(arg[0]); m.Assert(e) {
|
||||
defer f.Close()
|
||||
@ -176,16 +185,6 @@ var Index = &ice.Context{Name: "nfs", Help: "存储模块",
|
||||
}
|
||||
}
|
||||
}},
|
||||
"cat": {Name: "cat path", Help: "保存", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if f, e := os.OpenFile(arg[0], os.O_RDONLY, 0777); m.Assert(e) {
|
||||
defer f.Close()
|
||||
buf := make([]byte, 1024)
|
||||
if n, e := f.Read(buf); m.Assert(e) {
|
||||
m.Log(ice.LOG_IMPORT, "%d: %s", n, arg[0])
|
||||
m.Echo(string(buf[:n]))
|
||||
}
|
||||
}
|
||||
}},
|
||||
"copy": {Name: "save path text", Help: "保存", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if f, _, e := kit.Create(arg[0]); m.Assert(e) {
|
||||
defer f.Close()
|
||||
|
@ -64,21 +64,20 @@ func (f *Frame) Start(m *ice.Message, arg ...string) bool {
|
||||
if len(ls) > 0 && strings.HasPrefix(ls[0], "~") {
|
||||
// 切换模块
|
||||
target := ls[0][1:]
|
||||
if ls = ls[1:]; len(target) == 0 {
|
||||
if ls = ls[1:]; len(target) == 0 && len(ls) > 0 {
|
||||
target, ls = ls[0], ls[1:]
|
||||
}
|
||||
ice.Pulse.Search(target+".", func(p *ice.Context, s *ice.Context, key string) {
|
||||
m.Spawn(f.target).Search(target+".", func(p *ice.Context, s *ice.Context, key string) {
|
||||
m.Info("choice: %s", s.Name)
|
||||
f.target = s
|
||||
})
|
||||
}
|
||||
|
||||
if len(ls) == 0 {
|
||||
continue
|
||||
}
|
||||
msg := m.Spawns(f.target)
|
||||
|
||||
// 执行命令
|
||||
msg := m.Spawns(f.target)
|
||||
if msg.Cmdy(ls); !msg.Hand {
|
||||
msg = msg.Set("result").Cmdy(ice.CLI_SYSTEM, ls)
|
||||
}
|
||||
@ -116,6 +115,13 @@ var Index = &ice.Context{Name: "ssh", Help: "终端模块",
|
||||
"scan": {Name: "scan", Help: "解析", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Starts(arg[0], arg[1], arg[2:]...)
|
||||
}},
|
||||
"show": {Name: "show", Help: "解析", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
msg := m.Spawn()
|
||||
msg.Option("title", "疫情分布")
|
||||
msg.Info("what %v", msg.Format("meta"))
|
||||
m.Copy(msg)
|
||||
msg.Info("what %v", m.Format("meta"))
|
||||
}},
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -1457,6 +1457,9 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
|
||||
|
||||
"/share/": {Name: "/share/", Help: "共享链", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
switch arg[0] {
|
||||
case "local":
|
||||
http.ServeFile(m.W, m.R, "usr/"+path.Join(arg[1:]...))
|
||||
|
||||
case "login":
|
||||
Cookie(m, m.Cmdx(ice.AAA_USER, "login", m.Option("username"), m.Option("password")))
|
||||
|
||||
|
1
conf.go
1
conf.go
@ -10,6 +10,7 @@ const ( // ICE
|
||||
const ( // CTX
|
||||
CTX_STATUS = "status"
|
||||
CTX_STREAM = "stream"
|
||||
CTX_FOLLOW = "follow"
|
||||
CTX_CONFIG = "config"
|
||||
CTX_COMMAND = "command"
|
||||
CTX_CONTEXT = "context"
|
||||
|
@ -37,18 +37,18 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心",
|
||||
m.Cmd(ice.WEB_FAVOR, "river.root", "field", "share")
|
||||
|
||||
m.Cmd(ice.WEB_FAVOR, "river.root", "storm", "misc")
|
||||
m.Cmd(ice.WEB_FAVOR, "river.root", "field", "buffer", "cli.tmux")
|
||||
m.Cmd(ice.WEB_FAVOR, "river.root", "field", "session", "cli.tmux")
|
||||
m.Cmd(ice.WEB_FAVOR, "river.root", "field", "image", "cli.docker")
|
||||
m.Cmd(ice.WEB_FAVOR, "river.root", "field", "container", "cli.docker")
|
||||
m.Cmd(ice.WEB_FAVOR, "river.root", "field", "command", "cli.docker")
|
||||
m.Cmd(ice.WEB_FAVOR, "river.root", "field", "repos", "cli.git")
|
||||
m.Cmd(ice.WEB_FAVOR, "river.root", "field", "total", "cli.git")
|
||||
m.Cmd(ice.WEB_FAVOR, "river.root", "field", "branch", "cli.git")
|
||||
m.Cmd(ice.WEB_FAVOR, "river.root", "field", "status", "cli.git")
|
||||
m.Cmd(ice.WEB_FAVOR, "river.root", "field", "buffer", "web.code.tmux")
|
||||
m.Cmd(ice.WEB_FAVOR, "river.root", "field", "session", "web.code.tmux")
|
||||
m.Cmd(ice.WEB_FAVOR, "river.root", "field", "image", "web.code.docker")
|
||||
m.Cmd(ice.WEB_FAVOR, "river.root", "field", "container", "web.code.docker")
|
||||
m.Cmd(ice.WEB_FAVOR, "river.root", "field", "command", "web.code.docker")
|
||||
m.Cmd(ice.WEB_FAVOR, "river.root", "field", "repos", "web.code.git")
|
||||
m.Cmd(ice.WEB_FAVOR, "river.root", "field", "total", "web.code.git")
|
||||
m.Cmd(ice.WEB_FAVOR, "river.root", "field", "branch", "web.code.git")
|
||||
m.Cmd(ice.WEB_FAVOR, "river.root", "field", "status", "web.code.git")
|
||||
|
||||
m.Cmd(ice.WEB_FAVOR, "river.root", "storm", "note")
|
||||
m.Cmd(ice.WEB_FAVOR, "river.root", "field", "total", "cli.git")
|
||||
m.Cmd(ice.WEB_FAVOR, "river.root", "field", "total", "web.code.git")
|
||||
m.Cmd(ice.WEB_FAVOR, "river.root", "field", "date", "web.team")
|
||||
m.Cmd(ice.WEB_FAVOR, "river.root", "field", "miss", "web.team")
|
||||
m.Cmd(ice.WEB_FAVOR, "river.root", "field", "progress", "web.team")
|
||||
|
@ -33,16 +33,12 @@ var Index = &ice.Context{Name: "code", Help: "编程中心",
|
||||
|
||||
"compile": {Name: "compile", Help: "编译", Value: kit.Data("path", "usr/publish")},
|
||||
"publish": {Name: "publish", Help: "发布", Value: kit.Data("path", "usr/publish")},
|
||||
"upgrade": {Name: "upgrade", Help: "升级", Value: kit.Dict(
|
||||
kit.MDB_HASH, kit.Dict(
|
||||
"system", kit.Dict(
|
||||
kit.MDB_LIST, kit.List(
|
||||
kit.MDB_INPUT, "bin", "file", "ice.sh", "path", "bin/ice.sh",
|
||||
kit.MDB_INPUT, "bin", "file", "ice.bin", "path", "bin/ice.bin",
|
||||
),
|
||||
),
|
||||
),
|
||||
)},
|
||||
"upgrade": {Name: "upgrade", Help: "升级", Value: kit.Dict(kit.MDB_HASH, kit.Dict(
|
||||
"system", kit.Dict(kit.MDB_LIST, kit.List(
|
||||
kit.MDB_INPUT, "bin", "file", "ice.sh", "path", "bin/ice.sh",
|
||||
kit.MDB_INPUT, "bin", "file", "ice.bin", "path", "bin/ice.bin",
|
||||
)),
|
||||
))},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
@ -249,12 +245,6 @@ var Index = &ice.Context{Name: "code", Help: "编程中心",
|
||||
m.Push("_output", "result")
|
||||
}
|
||||
}},
|
||||
"/input/": {Name: "/input/", Help: "编辑器", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Cmd("cli.input.match", arg[0]).Table(func(index int, value map[string]string, head []string) {
|
||||
m.Echo("%s %s\n", value["code"], value["text"])
|
||||
m.Push("_output", "result")
|
||||
})
|
||||
}},
|
||||
"/vim": {Name: "/vim", Help: "编辑器", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if f, _, e := m.R.FormFile("sub"); e == nil {
|
||||
defer f.Close()
|
||||
@ -288,19 +278,21 @@ var Index = &ice.Context{Name: "code", Help: "编程中心",
|
||||
arg := kit.Split(strings.TrimPrefix(strings.TrimSpace(m.Option("arg")), "ice "))
|
||||
switch arg[0] {
|
||||
case "add":
|
||||
m.Cmd("cli.input.input", "push", arg[1:])
|
||||
// 添加词汇
|
||||
m.Cmd("input.push", arg[1:])
|
||||
m.Option("arg", arg[2])
|
||||
default:
|
||||
// 执行命令
|
||||
m.Set("append")
|
||||
if m.Cmdy(arg).Table(); strings.TrimSpace(m.Result()) == "" {
|
||||
m.Cmdy(ice.CLI_SYSTEM, arg)
|
||||
}
|
||||
m.Info("trans: --%s--", m.Result())
|
||||
m.Push("_output", "result")
|
||||
return
|
||||
}
|
||||
}
|
||||
m.Cmd("cli.input.match", m.Option("arg")).Table(func(index int, value map[string]string, head []string) {
|
||||
// 词汇列表
|
||||
m.Cmd("input.find", m.Option("arg")).Table(func(index int, value map[string]string, head []string) {
|
||||
m.Echo("%s\n", value["text"])
|
||||
m.Push("_output", "result")
|
||||
})
|
||||
|
@ -37,8 +37,19 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心",
|
||||
"order": {Name: "order", Help: "列表", Value: kit.Data("template", order)},
|
||||
"table": {Name: "table", Help: "表格", Value: kit.Data("template", table)},
|
||||
"chart": {Name: "chart", Help: "绘图", Value: kit.Data("prefix", prefix, "suffix", `</svg>`)},
|
||||
|
||||
"mind": {Name: "mind", Help: "思维导图", Value: kit.Data(kit.MDB_SHORT, "name", "prefix", `<svg vertion="1.1" xmlns="http://www.w3.org/2000/svg" width="%v" height="%v">`, "suffix", `</svg>`)},
|
||||
"word": {Name: "word", Help: "语言文字", Value: kit.Data(kit.MDB_SHORT, "name")},
|
||||
"data": {Name: "data", Help: "数据表格", Value: kit.Data(kit.MDB_SHORT, "name")},
|
||||
"feel": {Name: "feel", Help: "影音媒体", Value: kit.Data(kit.MDB_SHORT, "name")},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Cmd(ice.CTX_CONFIG, "load", kit.Keys(m.Cap(ice.CTX_FOLLOW), "json"))
|
||||
}},
|
||||
ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Cmd(ice.CTX_CONFIG, "save", kit.Keys(m.Cap(ice.CTX_FOLLOW), "json"), kit.Keys(m.Cap(ice.CTX_FOLLOW), "mind"))
|
||||
}},
|
||||
"chart": {Name: "chart block|chain|table name text [fg bg fs ls p m]", Help: "绘图", Meta: map[string]interface{}{
|
||||
"display": "inner",
|
||||
}, List: kit.List(
|
||||
@ -243,6 +254,99 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心",
|
||||
}
|
||||
m.Cmdy(kit.Select("_tree", "_text", len(arg) > 0 && strings.HasSuffix(arg[0], ".md")), arg)
|
||||
}},
|
||||
|
||||
"mind": {Name: "mind", Help: "思维导图", Meta: kit.Dict("display", "wiki/mind"), List: kit.List(
|
||||
kit.MDB_INPUT, "text", "name", "name",
|
||||
kit.MDB_INPUT, "button", "name", "执行",
|
||||
kit.MDB_INPUT, "button", "name", "返回", "cb", "Last",
|
||||
), Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
|
||||
if len(arg) > 0 && arg[0] == "action" {
|
||||
switch arg[1] {
|
||||
case "保存":
|
||||
m.Cmd("nfs.save", path.Join("usr", arg[2]), arg[3:])
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
m.Option("dir_root", "usr")
|
||||
m.Cmdy("nfs.dir", kit.Select("./", arg, 0))
|
||||
if m.Append("path") == "" && m.Result() == "" {
|
||||
m.Echo(m.Conf("mind", "meta.prefix"), "100%", "100%")
|
||||
m.Echo(m.Conf("mind", "meta.suffix"))
|
||||
}
|
||||
}},
|
||||
"word": {Name: "word", Help: "语言文字", Meta: kit.Dict("display", "wiki/word"), List: kit.List(
|
||||
kit.MDB_INPUT, "text", "name", "name",
|
||||
kit.MDB_INPUT, "button", "name", "执行",
|
||||
kit.MDB_INPUT, "button", "name", "返回", "cb", "Last",
|
||||
), Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
|
||||
if len(arg) > 0 && arg[0] == "action" {
|
||||
switch arg[1] {
|
||||
case "保存":
|
||||
m.Cmd("nfs.save", path.Join("usr", arg[2]), arg[3])
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
m.Option("dir_root", "usr")
|
||||
m.Cmdy("nfs.dir", kit.Select("./", arg, 0))
|
||||
}},
|
||||
"data": {Name: "data", Help: "数据表格", Meta: kit.Dict("display", "wiki/data"), List: kit.List(
|
||||
kit.MDB_INPUT, "text", "name", "name",
|
||||
kit.MDB_INPUT, "button", "name", "执行",
|
||||
kit.MDB_INPUT, "button", "name", "返回", "cb", "Last",
|
||||
), Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
|
||||
if len(arg) > 0 && arg[0] == "action" {
|
||||
switch arg[1] {
|
||||
case "保存":
|
||||
m.Cmd("nfs.save", path.Join("usr", arg[2]), arg[3])
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
m.Option("dir_root", "usr")
|
||||
m.Cmdy("nfs.dir", kit.Select("./", arg, 0))
|
||||
if len(arg) > 0 && strings.HasSuffix(arg[0], ".csv") {
|
||||
m.CSV(m.Result())
|
||||
}
|
||||
}},
|
||||
"feel": {Name: "feel", Help: "影音媒体", Meta: kit.Dict("display", "wiki/feel"), List: kit.List(
|
||||
kit.MDB_INPUT, "text", "name", "name",
|
||||
kit.MDB_INPUT, "button", "name", "执行",
|
||||
kit.MDB_INPUT, "button", "name", "返回", "cb", "Last",
|
||||
), Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
|
||||
if len(arg) > 0 && arg[0] == "action" {
|
||||
switch arg[1] {
|
||||
case "保存":
|
||||
m.Cmd("nfs.save", path.Join("usr", arg[2]), arg[3])
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
m.Option("dir_root", "usr")
|
||||
m.Cmdy("nfs.dir", kit.Select("./", arg, 0))
|
||||
m.Sort("time", "time_r")
|
||||
}},
|
||||
"walk": {Name: "walk", Help: "走遍世界", Meta: kit.Dict("display", "wiki/walk"), List: kit.List(
|
||||
kit.MDB_INPUT, "text", "name", "file",
|
||||
kit.MDB_INPUT, "button", "name", "执行",
|
||||
kit.MDB_INPUT, "button", "name", "返回", "cb", "Last",
|
||||
), Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
|
||||
if len(arg) > 0 && arg[0] == "action" {
|
||||
switch arg[1] {
|
||||
case "保存":
|
||||
m.Cmd("nfs.save", path.Join("usr", arg[2]), arg[3])
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
m.Option("dir_root", "usr")
|
||||
m.Cmdy("nfs.dir", kit.Select("./", arg, 0))
|
||||
if len(arg) > 0 && strings.HasSuffix(arg[0], ".csv") {
|
||||
m.Option("title", "我走过的世界")
|
||||
m.CSV(m.Result())
|
||||
}
|
||||
}},
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"bytes"
|
||||
"encoding/csv"
|
||||
"github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/cli"
|
||||
"github.com/shylinux/icebergs/core/wiki"
|
||||
"github.com/shylinux/toolkits"
|
||||
"math/rand"
|
||||
"os"
|
||||
@ -23,7 +23,7 @@ var Index = &ice.Context{Name: "alpha", Help: "英汉词典",
|
||||
m.Cmd(ice.CTX_CONFIG, "load", "alpha.json")
|
||||
}},
|
||||
ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Cmd(ice.CTX_CONFIG, "save", "alpha.json", "cli.alpha.alpha")
|
||||
m.Cmd(ice.CTX_CONFIG, "save", "alpha.json", "alpha")
|
||||
}},
|
||||
|
||||
"alpha": {Name: "alpha [load|list]", Help: "英汉词典", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
@ -35,7 +35,7 @@ var Index = &ice.Context{Name: "alpha", Help: "英汉词典",
|
||||
switch arg[0] {
|
||||
case "load":
|
||||
// 加载词库
|
||||
m.Cmd(ice.MDB_IMPORT, "cli.alpha.alpha", "", "list",
|
||||
m.Cmd(ice.MDB_IMPORT, "web.wiki.alpha.alpha", "", "list",
|
||||
m.Cmd(ice.WEB_CACHE, "catch", "csv", arg[1]).Append("data"))
|
||||
case "list":
|
||||
// 词汇列表
|
||||
@ -75,7 +75,7 @@ var Index = &ice.Context{Name: "alpha", Help: "英汉词典",
|
||||
if field == nil {
|
||||
field = map[string]interface{}{}
|
||||
head := []string{}
|
||||
if f, e := os.Open(path.Join(m.Conf("alpha", "meta.store"), "cli.alpha.alpha..csv")); m.Assert(e) {
|
||||
if f, e := os.Open(path.Join(m.Conf("alpha", "meta.store"), "web.wiki.alpha.alpha.csv")); m.Assert(e) {
|
||||
defer f.Close()
|
||||
bio := csv.NewReader(f)
|
||||
head, e = bio.Read()
|
||||
@ -109,4 +109,4 @@ var Index = &ice.Context{Name: "alpha", Help: "英汉词典",
|
||||
},
|
||||
}
|
||||
|
||||
func init() { cli.Index.Register(Index, nil) }
|
||||
func init() { wiki.Index.Register(Index, nil) }
|
||||
|
@ -2,7 +2,7 @@ package docker
|
||||
|
||||
import (
|
||||
"github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/cli"
|
||||
"github.com/shylinux/icebergs/core/code"
|
||||
"github.com/shylinux/toolkits"
|
||||
"strings"
|
||||
)
|
||||
@ -95,4 +95,4 @@ var Index = &ice.Context{Name: "docker", Help: "容器管理",
|
||||
},
|
||||
}
|
||||
|
||||
func init() { cli.Index.Register(Index, nil) }
|
||||
func init() { code.Index.Register(Index, nil) }
|
||||
|
@ -2,7 +2,7 @@ package git
|
||||
|
||||
import (
|
||||
"github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/cli"
|
||||
"github.com/shylinux/icebergs/core/code"
|
||||
"github.com/shylinux/toolkits"
|
||||
|
||||
"os"
|
||||
@ -14,39 +14,44 @@ import (
|
||||
var Index = &ice.Context{Name: "git", Help: "代码管理",
|
||||
Caches: map[string]*ice.Cache{},
|
||||
Configs: map[string]*ice.Config{
|
||||
"repos": {Name: "repos", Help: "仓库", Value: kit.Data(kit.MDB_SHORT, "name")},
|
||||
"repos": {Name: "repos", Help: "仓库", Value: kit.Data(kit.MDB_SHORT, "name", "owner", "https://github.com/shylinux")},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
// 前端代码
|
||||
m.Rich("repos", nil, kit.Data(
|
||||
"name", "volcanos", "path", "usr/volcanos", "branch", "master",
|
||||
"remote", "https://github.com/shylinux/volcanos",
|
||||
))
|
||||
m.Rich("repos", nil, kit.Data(
|
||||
"name", "icebergs", "path", "../icebergs", "branch", "master",
|
||||
"remote", "https://github.com/shylinux/icebergs",
|
||||
))
|
||||
m.Rich("repos", nil, kit.Data(
|
||||
"name", "toolkits", "path", "../toolkits", "branch", "master",
|
||||
"remote", "https://github.com/shylinux/toolkits",
|
||||
))
|
||||
m.Rich("repos", nil, kit.Data(
|
||||
"name", "contexts", "path", "../contexts", "branch", "master",
|
||||
"remote", "https://github.com/shylinux/context",
|
||||
))
|
||||
for _, repos := range []string{"volcanos"} {
|
||||
m.Rich("repos", nil, kit.Data(
|
||||
"name", repos, "path", "usr/"+repos, "branch", "master",
|
||||
"remote", m.Conf("repos", "meta.owner")+"/"+repos,
|
||||
))
|
||||
}
|
||||
// 后端代码
|
||||
for _, repos := range []string{"contexts", "icebergs", "toolkits"} {
|
||||
m.Rich("repos", nil, kit.Data(
|
||||
"name", repos, "path", "../"+repos, "branch", "master",
|
||||
"remote", m.Conf("repos", "meta.owner")+"/"+repos,
|
||||
))
|
||||
}
|
||||
// 应用代码
|
||||
m.Cmd("nfs.dir", m.Conf(ice.WEB_DREAM, "meta.path"), "name path").Table(func(index int, value map[string]string, head []string) {
|
||||
if s, e := os.Stat(path.Join(value["path"], ".git")); e == nil && s.IsDir() {
|
||||
if s, e := os.Stat(m.Option("cmd_dir", path.Join(value["path"], ".git"))); e == nil && s.IsDir() {
|
||||
m.Rich("repos", nil, kit.Data(
|
||||
"name", value["name"], "path", value["path"], "branch", "master",
|
||||
"remote", m.Cmdx(ice.CLI_SYSTEM, "git", "remote", "get-url", "origin"),
|
||||
))
|
||||
}
|
||||
})
|
||||
m.Watch(ice.SYSTEM_INIT, "cli.git.check", "volcanos")
|
||||
m.Watch(ice.SYSTEM_INIT, "web.code.git.check", "volcanos")
|
||||
}},
|
||||
ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}},
|
||||
"repos": {Name: "repos", Help: "仓库", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
|
||||
"repos": {Name: "repos [name [path]]", Help: "仓库", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if len(arg) > 0 {
|
||||
m.Rich("repos", nil, kit.Data(
|
||||
"name", arg[0], "path", "usr/"+kit.Select(arg[0], arg, 1), "branch", "master",
|
||||
"remote", m.Conf("repos", "meta.owner")+"/"+arg[0],
|
||||
))
|
||||
}
|
||||
m.Richs("repos", nil, "*", func(key string, value map[string]interface{}) {
|
||||
m.Push(key, value["meta"], []string{"time", "name", "branch", "path", "remote"})
|
||||
})
|
||||
@ -192,4 +197,4 @@ var Index = &ice.Context{Name: "git", Help: "代码管理",
|
||||
},
|
||||
}
|
||||
|
||||
func init() { cli.Index.Register(Index, nil) }
|
||||
func init() { code.Index.Register(Index, nil) }
|
||||
|
@ -1,13 +1,14 @@
|
||||
package input
|
||||
|
||||
import (
|
||||
"github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/core/code"
|
||||
"github.com/shylinux/toolkits"
|
||||
|
||||
"bufio"
|
||||
"bytes"
|
||||
"encoding/csv"
|
||||
"fmt"
|
||||
"github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/cli"
|
||||
"github.com/shylinux/toolkits"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
@ -17,88 +18,88 @@ var Index = &ice.Context{Name: "input", Help: "输入法",
|
||||
Caches: map[string]*ice.Cache{},
|
||||
Configs: map[string]*ice.Config{
|
||||
"input": {Name: "input", Help: "输入法", Value: kit.Data(
|
||||
"store", "var/input/", "limit", "2000", "least", "1000", "fsize", "100000",
|
||||
"field", kit.Dict("file", 0, "line", 1, "code", 2, "id", 3, "text", 4, "time", 5, "weight", 6),
|
||||
"store", "var/input/", "fsize", "100000", "limit", "2000", "least", "1000",
|
||||
"repos", "wubi-dict", "local", "some",
|
||||
)},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Cmd(ice.CTX_CONFIG, "load", "input.json")
|
||||
m.Cmd(ice.CTX_CONFIG, "load", kit.Keys(m.Cap(ice.CTX_FOLLOW), "json"))
|
||||
m.Cmd("web.code.git.repos", m.Conf("input", "meta.repos"))
|
||||
}},
|
||||
ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Cmd(ice.CTX_CONFIG, "save", "input.json", "cli.input.input")
|
||||
m.Cmd(ice.CTX_CONFIG, "save", kit.Keys(m.Cap(ice.CTX_FOLLOW), "json"), kit.Keys(m.Cap(ice.CTX_FOLLOW), "input"))
|
||||
}},
|
||||
|
||||
"input": {Name: "input load|list|push|save", Help: "输入法", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
"load": {Name: "load file [name]", Help: "加载词库", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
arg = append(arg, "list")
|
||||
// 默认词库
|
||||
if m.Cmd("web.code.git.check", m.Conf("input", "meta.repos")); m.Confs("input", "wubi86") {
|
||||
m.Echo("wubi86: %v", m.Conf("input", "wubi86.meta.count"))
|
||||
return
|
||||
}
|
||||
arg = append(arg, path.Join("usr", m.Conf("input", "meta.repos"), "wubi86"))
|
||||
}
|
||||
lib := kit.Select(path.Base(arg[0]), arg, 1)
|
||||
|
||||
switch arg[0] {
|
||||
case "load":
|
||||
// 缓存配置
|
||||
m.Option("cache.least", m.Conf("input", "meta.least"))
|
||||
m.Option("cache.limit", m.Conf("input", "meta.limit"))
|
||||
m.Option("cache.fsize", m.Conf("input", "meta.fsize"))
|
||||
m.Assert(os.RemoveAll(m.Option("cache.store", path.Join(m.Conf("input", "meta.store"), lib))))
|
||||
m.Conf("input", lib, "")
|
||||
|
||||
if f, e := os.Open(arg[0]); m.Assert(e) {
|
||||
bio := bufio.NewScanner(f)
|
||||
// 加载词库
|
||||
lib := kit.Select(path.Base(arg[1]), arg, 2)
|
||||
m.Option("cache.fsize", m.Conf("input", "meta.fsize"))
|
||||
m.Option("cache.limit", m.Conf("input", "meta.limit"))
|
||||
m.Option("cache.least", m.Conf("input", "meta.least"))
|
||||
m.Assert(os.RemoveAll(m.Option("cache.store", path.Join(m.Conf("input", "meta.store"), lib))))
|
||||
m.Conf("input", lib, "")
|
||||
if f, e := os.Open(arg[1]); m.Assert(e) {
|
||||
bio := bufio.NewScanner(f)
|
||||
for bio.Scan() {
|
||||
if strings.HasPrefix(bio.Text(), "#") {
|
||||
continue
|
||||
}
|
||||
line := kit.Split(bio.Text(), " \t")
|
||||
if line[2] == "0" {
|
||||
continue
|
||||
}
|
||||
m.Grow("input", lib, kit.Dict(
|
||||
"text", line[0], "code", line[1], "weight", line[2],
|
||||
))
|
||||
for bio.Scan() {
|
||||
if strings.HasPrefix(bio.Text(), "#") {
|
||||
continue
|
||||
}
|
||||
m.Option("cache.limit", 0)
|
||||
m.Option("cache.least", 0)
|
||||
n := m.Grow("input", lib, kit.Dict(
|
||||
"text", "成功", "code", "z", "weight", "0",
|
||||
))
|
||||
m.Echo("%s: %d", lib, n)
|
||||
line := kit.Split(bio.Text(), " \t")
|
||||
if line[2] == "0" {
|
||||
continue
|
||||
}
|
||||
m.Grow("input", lib, kit.Dict("text", line[0], "code", line[1], "weight", line[2]))
|
||||
}
|
||||
case "push":
|
||||
// 添加词汇
|
||||
lib := kit.Select("person", arg, 3)
|
||||
m.Option("cache.limit", 0)
|
||||
// 保存词库
|
||||
m.Option("cache.least", 0)
|
||||
m.Option("cache.store", path.Join(m.Conf("input", "meta.store"), lib))
|
||||
n := m.Grow("input", lib, kit.Dict(
|
||||
"text", arg[1], "code", arg[2], "weight", kit.Select("99990000", arg, 4),
|
||||
))
|
||||
m.Echo("%s: %d", lib, n)
|
||||
case "list":
|
||||
// 词汇列表
|
||||
lib := kit.Select("person", arg, 1)
|
||||
m.Option("cache.offend", kit.Select("0", arg, 2))
|
||||
m.Option("cache.limit", kit.Select("10", arg, 3))
|
||||
m.Grows("input", lib, "", "", func(index int, value map[string]interface{}) {
|
||||
m.Push("", value, []string{"id", "code", "text", "weight"})
|
||||
})
|
||||
case "save":
|
||||
// 导出词库
|
||||
m.Option("cache.offend", 0)
|
||||
m.Option("cache.limit", 1000000)
|
||||
if f, p, e := kit.Create(kit.Select(arg[1], arg, 2)); m.Assert(e) {
|
||||
defer f.Close()
|
||||
n := 0
|
||||
m.Grows("input", arg[1], "", "", func(index int, value map[string]interface{}) {
|
||||
n++
|
||||
fmt.Fprintf(f, "%s %s %s\n", value["text"], value["code"], value["weight"])
|
||||
})
|
||||
m.Log(ice.LOG_EXPORT, "%s: %d", p, n)
|
||||
m.Echo("%s: %d", p, n)
|
||||
}
|
||||
m.Option("cache.limit", 0)
|
||||
m.Echo("%s: %d", lib, m.Grow("input", lib, kit.Dict("text", "成功", "code", "z", "weight", "0")))
|
||||
}
|
||||
}},
|
||||
"match": {Name: "match [word [method]]", Help: "五笔字码", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
"push": {Name: "push text code [weight [lib]]", Help: "添加词汇", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
lib := kit.Select("person", arg, 2)
|
||||
m.Option("cache.least", 0)
|
||||
m.Option("cache.limit", 0)
|
||||
m.Option("cache.store", path.Join(m.Conf("input", "meta.store"), lib))
|
||||
m.Echo("%s: %d", lib, m.Grow("input", lib, kit.Dict("text", arg[0], "code", arg[1], "weight", kit.Select("99990000", arg, 3))))
|
||||
}},
|
||||
"list": {Name: "list [lib [offend [limit]]]", Help: "查看词汇", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
lib := kit.Select("person", arg, 0)
|
||||
m.Option("cache.offend", kit.Select("0", arg, 1))
|
||||
m.Option("cache.limit", kit.Select("10", arg, 2))
|
||||
m.Grows("input", lib, "", "", func(index int, value map[string]interface{}) {
|
||||
m.Push("", value, []string{"id", "code", "text", "weight"})
|
||||
})
|
||||
}},
|
||||
"save": {Name: "save lib [filename]", Help: "导出词库", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
lib := kit.Select("person", arg, 0)
|
||||
m.Option("cache.limit", 1000000)
|
||||
m.Option("cache.offend", 0)
|
||||
if f, p, e := kit.Create(path.Join("usr", m.Conf("input", "meta.repos"), lib)); m.Assert(e) {
|
||||
defer f.Close()
|
||||
n := 0
|
||||
m.Grows("input", lib, "", "", func(index int, value map[string]interface{}) {
|
||||
n++
|
||||
fmt.Fprintf(f, "%s %s %s\n", value["text"], value["code"], value["weight"])
|
||||
})
|
||||
m.Log(ice.LOG_EXPORT, "%s: %d", p, n)
|
||||
m.Echo("%s: %d", p, n)
|
||||
}
|
||||
}},
|
||||
|
||||
"find": {Name: "find key [word|line [limit]]", Help: "五笔字码", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
// 收藏列表
|
||||
m.Cmdy(ice.WEB_FAVOR, "input.word")
|
||||
@ -117,7 +118,6 @@ var Index = &ice.Context{Name: "input", Help: "输入法",
|
||||
}
|
||||
|
||||
// 搜索词汇
|
||||
field := m.Confm("input", "meta.field")
|
||||
bio := csv.NewReader(bytes.NewBufferString(strings.Replace(m.Cmdx(ice.CLI_SYSTEM, "grep", "-rn", arg[0], m.Conf("input", "meta.store")), ":", ",", -1)))
|
||||
for i := 0; i < kit.Int(kit.Select("100", arg, 2)); i++ {
|
||||
if line, e := bio.Read(); e != nil {
|
||||
@ -126,16 +126,15 @@ var Index = &ice.Context{Name: "input", Help: "输入法",
|
||||
} else {
|
||||
if method == "word" && i == 0 {
|
||||
// 添加收藏
|
||||
m.Cmd(ice.WEB_FAVOR, "input.word", "input",
|
||||
line[kit.Int(field["code"])], line[kit.Int(field["text"])],
|
||||
"id", line[kit.Int(field["id"])], "weight", line[kit.Int(field["weight"])],
|
||||
)
|
||||
m.Cmd(ice.WEB_FAVOR, "input.word", "input", line[2], line[4], "id", line[3], "weight", line[6])
|
||||
}
|
||||
|
||||
// 输出词汇
|
||||
m.Push("file", path.Base(line[kit.Int(field["file"])]))
|
||||
for _, k := range []string{"id", "code", "text", "weight"} {
|
||||
m.Push(k, line[kit.Int(field[k])])
|
||||
}
|
||||
m.Push("file", path.Base(line[0]))
|
||||
m.Push("id", line[3])
|
||||
m.Push("code", line[2])
|
||||
m.Push("text", line[4])
|
||||
m.Push("weight", line[6])
|
||||
}
|
||||
}
|
||||
m.Sort("weight", "int_r")
|
||||
@ -143,4 +142,4 @@ var Index = &ice.Context{Name: "input", Help: "输入法",
|
||||
},
|
||||
}
|
||||
|
||||
func init() { cli.Index.Register(Index, nil) }
|
||||
func init() { code.Index.Register(Index, nil) }
|
||||
|
@ -2,7 +2,7 @@ package pi
|
||||
|
||||
import (
|
||||
"github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/cli"
|
||||
"github.com/shylinux/icebergs/core/chat"
|
||||
"github.com/shylinux/toolkits"
|
||||
"os"
|
||||
"path"
|
||||
@ -35,4 +35,4 @@ var Index = &ice.Context{Name: "pi", Help: "pi",
|
||||
},
|
||||
}
|
||||
|
||||
func init() { cli.Index.Register(Index, nil) }
|
||||
func init() { chat.Index.Register(Index, nil) }
|
||||
|
@ -2,7 +2,7 @@ package tmux
|
||||
|
||||
import (
|
||||
"github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/cli"
|
||||
"github.com/shylinux/icebergs/core/code"
|
||||
"github.com/shylinux/toolkits"
|
||||
"os"
|
||||
"path"
|
||||
@ -53,9 +53,9 @@ var Index = &ice.Context{Name: "tmux", Help: "终端管理",
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Watch(ice.SYSTEM_INIT, "cli.tmux.init")
|
||||
m.Watch(ice.DREAM_START, "cli.tmux.auto")
|
||||
m.Watch(ice.FAVOR_START, "cli.tmux.auto")
|
||||
m.Watch(ice.SYSTEM_INIT, "web.code.tmux.init")
|
||||
m.Watch(ice.DREAM_START, "web.code.tmux.auto")
|
||||
m.Watch(ice.FAVOR_START, "web.code.tmux.auto")
|
||||
}},
|
||||
ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
}},
|
||||
@ -240,7 +240,7 @@ var Index = &ice.Context{Name: "tmux", Help: "终端管理",
|
||||
"auto": {Name: "auto", Help: "终端", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
prefix := []string{"cli.system", "tmux"}
|
||||
if arg[0] == "" {
|
||||
m.Cmd("cli.tmux.session").Table(func(index int, value map[string]string, head []string) {
|
||||
m.Cmd("web.code.tmux.session").Table(func(index int, value map[string]string, head []string) {
|
||||
if value["tag"] == "1" {
|
||||
arg[0] = value["session"]
|
||||
}
|
||||
@ -273,4 +273,4 @@ var Index = &ice.Context{Name: "tmux", Help: "终端管理",
|
||||
},
|
||||
}
|
||||
|
||||
func init() { cli.Index.Register(Index, &Frame{}) }
|
||||
func init() { code.Index.Register(Index, &Frame{}) }
|
||||
|
@ -2,7 +2,7 @@ package wx
|
||||
|
||||
import (
|
||||
"github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/cli"
|
||||
"github.com/shylinux/icebergs/core/chat"
|
||||
"github.com/shylinux/toolkits"
|
||||
"regexp"
|
||||
)
|
||||
@ -53,4 +53,4 @@ var Index = &ice.Context{Name: "wx", Help: "wx",
|
||||
},
|
||||
}
|
||||
|
||||
func init() { cli.Index.Register(Index, nil) }
|
||||
func init() { chat.Index.Register(Index, nil) }
|
||||
|
63
type.go
63
type.go
@ -3,6 +3,7 @@ package ice
|
||||
import (
|
||||
"github.com/shylinux/toolkits"
|
||||
|
||||
"bytes"
|
||||
"encoding/csv"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
@ -113,6 +114,7 @@ func (c *Context) Spawn(m *Message, name string, help string, arg ...string) *Co
|
||||
func (c *Context) Begin(m *Message, arg ...string) *Context {
|
||||
c.Caches[CTX_STATUS] = &Cache{Name: CTX_STATUS, Value: ""}
|
||||
c.Caches[CTX_STREAM] = &Cache{Name: CTX_STREAM, Value: ""}
|
||||
c.Caches[CTX_FOLLOW] = &Cache{Name: CTX_FOLLOW, Value: ""}
|
||||
|
||||
m.Log(LOG_BEGIN, "%s", c.Name)
|
||||
if c.begin = m; c.server != nil {
|
||||
@ -120,6 +122,11 @@ func (c *Context) Begin(m *Message, arg ...string) *Context {
|
||||
c.server.Begin(m, arg...)
|
||||
})
|
||||
}
|
||||
if c.context == Index {
|
||||
c.Cap(CTX_FOLLOW, c.Name)
|
||||
} else if c.context != nil {
|
||||
c.Cap(CTX_FOLLOW, kit.Keys(c.context.Cap(CTX_FOLLOW), c.Name))
|
||||
}
|
||||
return c
|
||||
}
|
||||
func (c *Context) Start(m *Message, arg ...string) bool {
|
||||
@ -192,6 +199,9 @@ func (m *Message) Time(args ...interface{}) string {
|
||||
func (m *Message) Target() *Context {
|
||||
return m.target
|
||||
}
|
||||
func (m *Message) Source() *Context {
|
||||
return m.source
|
||||
}
|
||||
func (m *Message) Format(key interface{}) string {
|
||||
switch key := key.(type) {
|
||||
case string:
|
||||
@ -316,6 +326,21 @@ func (m *Message) Spawns(arg ...interface{}) *Message {
|
||||
return msg
|
||||
}
|
||||
|
||||
func (m *Message) CSV(text string) *Message {
|
||||
bio := bytes.NewBufferString(text)
|
||||
r := csv.NewReader(bio)
|
||||
heads, _ := r.Read()
|
||||
for {
|
||||
lines, e := r.Read()
|
||||
if e != nil {
|
||||
break
|
||||
}
|
||||
for i, k := range heads {
|
||||
m.Push(k, kit.Select("", lines, i))
|
||||
}
|
||||
}
|
||||
return m
|
||||
}
|
||||
func (m *Message) Add(key string, arg ...string) *Message {
|
||||
switch key {
|
||||
case MSG_DETAIL, MSG_RESULT:
|
||||
@ -352,17 +377,19 @@ func (m *Message) Copy(msg *Message) *Message {
|
||||
if msg == nil {
|
||||
return m
|
||||
}
|
||||
for _, k := range msg.meta[MSG_OPTION] {
|
||||
if kit.IndexOf(m.meta[MSG_OPTION], k) == -1 {
|
||||
m.meta[MSG_OPTION] = append(m.meta[MSG_OPTION], k)
|
||||
}
|
||||
m.meta[k] = append(m.meta[k], msg.meta[k]...)
|
||||
}
|
||||
for _, k := range msg.meta[MSG_APPEND] {
|
||||
if kit.IndexOf(m.meta[MSG_APPEND], k) == -1 {
|
||||
m.meta[MSG_APPEND] = append(m.meta[MSG_APPEND], k)
|
||||
}
|
||||
for _, v := range msg.meta[k] {
|
||||
m.meta[k] = append(m.meta[k], v)
|
||||
}
|
||||
}
|
||||
for _, v := range msg.meta[MSG_RESULT] {
|
||||
m.meta[MSG_RESULT] = append(m.meta[MSG_RESULT], v)
|
||||
m.meta[k] = append(m.meta[k], msg.meta[k]...)
|
||||
}
|
||||
m.meta[MSG_RESULT] = append(m.meta[MSG_RESULT], msg.meta[MSG_RESULT]...)
|
||||
return m
|
||||
}
|
||||
func (m *Message) Push(key string, value interface{}, arg ...interface{}) *Message {
|
||||
@ -868,14 +895,22 @@ func (m *Message) Search(key interface{}, cb interface{}) *Message {
|
||||
p := m.target.root
|
||||
if strings.Contains(key, ":") {
|
||||
|
||||
} else if key == "." {
|
||||
if m.target.context != nil {
|
||||
p = m.target.context
|
||||
}
|
||||
} else if strings.Contains(key, ".") {
|
||||
list := strings.Split(key, ".")
|
||||
|
||||
for _, v := range list[:len(list)-1] {
|
||||
if s, ok := p.contexts[v]; ok {
|
||||
p = s
|
||||
} else {
|
||||
p = nil
|
||||
for _, p = range []*Context{m.target.root, m.target, m.source} {
|
||||
for _, v := range list[:len(list)-1] {
|
||||
if s, ok := p.contexts[v]; ok {
|
||||
p = s
|
||||
} else {
|
||||
p = nil
|
||||
break
|
||||
}
|
||||
}
|
||||
if p != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
@ -1316,7 +1351,9 @@ func (m *Message) Capv(arg ...interface{}) interface{} {
|
||||
for _, s := range []*Context{m.target} {
|
||||
for c := s; c != nil; c = c.context {
|
||||
if caps, ok := c.Caches[key]; ok {
|
||||
caps.Value = kit.Format(arg[0])
|
||||
if len(arg) > 0 {
|
||||
caps.Value = kit.Format(arg[0])
|
||||
}
|
||||
return caps.Value
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user