forked from x/icebergs
opt vim
This commit is contained in:
parent
6fa699411e
commit
4bd3e6064c
@ -1,8 +1,8 @@
|
|||||||
package cli
|
package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/shylinux/icebergs"
|
ice "github.com/shylinux/icebergs"
|
||||||
"github.com/shylinux/toolkits"
|
kit "github.com/shylinux/toolkits"
|
||||||
|
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -19,7 +19,7 @@ var Index = &ice.Context{Name: "cli", Help: "命令模块",
|
|||||||
Configs: map[string]*ice.Config{
|
Configs: map[string]*ice.Config{
|
||||||
ice.CLI_RUNTIME: {Name: "runtime", Help: "运行环境", Value: kit.Dict()},
|
ice.CLI_RUNTIME: {Name: "runtime", Help: "运行环境", Value: kit.Dict()},
|
||||||
ice.CLI_SYSTEM: {Name: "system", Help: "系统命令", Value: kit.Data()},
|
ice.CLI_SYSTEM: {Name: "system", Help: "系统命令", Value: kit.Data()},
|
||||||
"daemon": {Name: "daemon", Help: "守护进程", Value: kit.Data(kit.MDB_SHORT, "name")},
|
ice.CLI_DAEMON: {Name: "daemon", Help: "守护进程", Value: kit.Data(kit.MDB_SHORT, "name")},
|
||||||
"python": {Name: "python", Help: "系统命令", Value: kit.Data("python", "python", "pip", "pip")},
|
"python": {Name: "python", Help: "系统命令", Value: kit.Data("python", "python", "pip", "pip")},
|
||||||
},
|
},
|
||||||
Commands: map[string]*ice.Command{
|
Commands: map[string]*ice.Command{
|
||||||
@ -142,7 +142,7 @@ var Index = &ice.Context{Name: "cli", Help: "命令模块",
|
|||||||
m.Echo(out.String())
|
m.Echo(out.String())
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
"daemon": {Name: "daemon", Help: "守护进程", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
ice.CLI_DAEMON: {Name: "daemon", Help: "守护进程", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
m.Option("cmd_type", "daemon")
|
m.Option("cmd_type", "daemon")
|
||||||
m.Cmdy(ice.CLI_SYSTEM, arg)
|
m.Cmdy(ice.CLI_SYSTEM, arg)
|
||||||
}},
|
}},
|
||||||
|
@ -186,6 +186,11 @@ var Index = &ice.Context{Name: "nfs", Help: "存储模块",
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
|
"link": {Name: "link path file", Help: "链接", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
m.Cmd("nfs.trash", arg[0])
|
||||||
|
os.MkdirAll(path.Dir(arg[0]), 0777)
|
||||||
|
os.Link(arg[1], arg[0])
|
||||||
|
}},
|
||||||
|
|
||||||
"trash": {Name: "trash file", Help: "保存", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
"trash": {Name: "trash file", Help: "保存", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
if s, e := os.Stat(arg[0]); e == nil {
|
if s, e := os.Stat(arg[0]); e == nil {
|
||||||
|
@ -2,8 +2,8 @@ package web
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/shylinux/icebergs"
|
ice "github.com/shylinux/icebergs"
|
||||||
"github.com/shylinux/toolkits"
|
kit "github.com/shylinux/toolkits"
|
||||||
"github.com/skip2/go-qrcode"
|
"github.com/skip2/go-qrcode"
|
||||||
|
|
||||||
"bytes"
|
"bytes"
|
||||||
@ -1618,6 +1618,12 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
|
|||||||
}
|
}
|
||||||
m.Echo(list)
|
m.Echo(list)
|
||||||
|
|
||||||
|
// 分发数据
|
||||||
|
if p := kit.Select(m.Conf(ice.WEB_FAVOR, "meta.proxy"), m.Option("you")); p != "" {
|
||||||
|
m.Option("you", "")
|
||||||
|
m.Cmd(ice.WEB_PROXY, p, ice.WEB_STORY, ice.STORY_PULL, arg[2], "dev", arg[2])
|
||||||
|
}
|
||||||
|
|
||||||
case ice.STORY_INDEX:
|
case ice.STORY_INDEX:
|
||||||
m.Richs(ice.WEB_STORY, "head", arg[1], func(key string, value map[string]interface{}) {
|
m.Richs(ice.WEB_STORY, "head", arg[1], func(key string, value map[string]interface{}) {
|
||||||
// 查询索引
|
// 查询索引
|
||||||
@ -1815,6 +1821,12 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
|
|||||||
})
|
})
|
||||||
}},
|
}},
|
||||||
ice.WEB_PROXY: {Name: "proxy", Help: "代理", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
ice.WEB_PROXY: {Name: "proxy", Help: "代理", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
if arg[0] == "" {
|
||||||
|
// 本机命令
|
||||||
|
m.Cmdy(arg[1:])
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
m.Richs(ice.WEB_SPACE, nil, kit.Select(m.Conf(ice.WEB_FAVOR, "meta.proxy"), arg[0]), func(key string, value map[string]interface{}) {
|
m.Richs(ice.WEB_SPACE, nil, kit.Select(m.Conf(ice.WEB_FAVOR, "meta.proxy"), arg[0]), func(key string, value map[string]interface{}) {
|
||||||
if value[kit.MDB_TYPE] == ice.WEB_BETTER {
|
if value[kit.MDB_TYPE] == ice.WEB_BETTER {
|
||||||
switch value[kit.MDB_NAME] {
|
switch value[kit.MDB_NAME] {
|
||||||
|
1
conf.go
1
conf.go
@ -190,6 +190,7 @@ const ( // TYPE
|
|||||||
const ( // CODE
|
const ( // CODE
|
||||||
CODE_INSTALL = "_install"
|
CODE_INSTALL = "_install"
|
||||||
CODE_PREPARE = "_prepare"
|
CODE_PREPARE = "_prepare"
|
||||||
|
CODE_PROJECT = "_project"
|
||||||
)
|
)
|
||||||
const ( // CHAT
|
const ( // CHAT
|
||||||
CHAT_RIVER = "river"
|
CHAT_RIVER = "river"
|
||||||
|
@ -17,10 +17,10 @@ var Index = &ice.Context{Name: "code", Help: "编程中心",
|
|||||||
Caches: map[string]*ice.Cache{},
|
Caches: map[string]*ice.Cache{},
|
||||||
Configs: map[string]*ice.Config{
|
Configs: map[string]*ice.Config{
|
||||||
"install": {Name: "install", Help: "安装", Value: kit.Data("path", "usr/install",
|
"install": {Name: "install", Help: "安装", Value: kit.Data("path", "usr/install",
|
||||||
"source", "https://dl.google.com/go/go1.14.2.src.tar.gz",
|
"source", "https://dl.google.com/go/go1.14.2.src.tar.gz", "target", "usr/local",
|
||||||
)},
|
)},
|
||||||
"prepare": {Name: "prepare", Help: "准备", Value: kit.Data("path", "usr/prepare")},
|
"prepare": {Name: "prepare", Help: "配置", Value: kit.Data("path", "usr/prepare")},
|
||||||
"project": {Name: "project", Help: "项目", Value: kit.Data("path", "usr/prepare")},
|
"project": {Name: "project", Help: "项目", Value: kit.Data("path", "usr/project")},
|
||||||
|
|
||||||
"compile": {Name: "compile", Help: "编译", Value: kit.Data("path", "usr/publish")},
|
"compile": {Name: "compile", Help: "编译", Value: kit.Data("path", "usr/publish")},
|
||||||
"publish": {Name: "publish", Help: "发布", Value: kit.Data("path", "usr/publish")},
|
"publish": {Name: "publish", Help: "发布", Value: kit.Data("path", "usr/publish")},
|
||||||
@ -31,23 +31,12 @@ var Index = &ice.Context{Name: "code", Help: "编程中心",
|
|||||||
)),
|
)),
|
||||||
))},
|
))},
|
||||||
|
|
||||||
|
"login": {Name: "login", Help: "终端接入", Value: kit.Data()},
|
||||||
"pprof": {Name: "pprof", Help: "性能分析", Value: kit.Data(kit.MDB_SHORT, kit.MDB_NAME,
|
"pprof": {Name: "pprof", Help: "性能分析", Value: kit.Data(kit.MDB_SHORT, kit.MDB_NAME,
|
||||||
"stop", "ps aux|grep pprof|grep -v grep|cut -d' ' -f2|xargs -n1 kill",
|
"stop", "ps aux|grep pprof|grep -v grep|cut -d' ' -f2|xargs -n1 kill",
|
||||||
)},
|
)},
|
||||||
"login": {Name: "login", Help: "终端接入", Value: kit.Data()},
|
|
||||||
},
|
},
|
||||||
Commands: map[string]*ice.Command{
|
Commands: map[string]*ice.Command{
|
||||||
ice.CODE_INSTALL: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
|
||||||
p := path.Join(m.Conf("install", "meta.path"), "go")
|
|
||||||
if _, e := os.Stat(p); e != nil {
|
|
||||||
m.Option("cmd_dir", m.Conf("install", "meta.path"))
|
|
||||||
m.Cmd(ice.CLI_SYSTEM, "wget", "-O", "go.tar.gz", m.Conf("install", "meta.source"))
|
|
||||||
m.Cmd(ice.CLI_SYSTEM, "tar", "xvf", "go.tar.gz")
|
|
||||||
}
|
|
||||||
}},
|
|
||||||
ice.CODE_PREPARE: {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_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
m.Load()
|
m.Load()
|
||||||
}},
|
}},
|
||||||
@ -55,42 +44,139 @@ var Index = &ice.Context{Name: "code", Help: "编程中心",
|
|||||||
m.Save("login")
|
m.Save("login")
|
||||||
}},
|
}},
|
||||||
|
|
||||||
|
ice.CODE_INSTALL: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
p := path.Join(m.Conf("install", "meta.path"), "go")
|
||||||
|
if _, e := os.Stat(p); e != nil {
|
||||||
|
// 下载源码
|
||||||
|
m.Option("cmd_dir", m.Conf("install", "meta.path"))
|
||||||
|
m.Cmd(ice.CLI_SYSTEM, "wget", "-O", "go.tar.gz", m.Conf("install", "meta.source"))
|
||||||
|
m.Cmd(ice.CLI_SYSTEM, "tar", "xvf", "go.tar.gz")
|
||||||
|
}
|
||||||
|
}},
|
||||||
|
ice.CODE_PREPARE: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
}},
|
||||||
|
ice.CODE_PROJECT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
}},
|
||||||
|
|
||||||
|
"install": {Name: "install", Help: "安装", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
}},
|
||||||
|
"prepare": {Name: "prepare", Help: "配置", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
}},
|
||||||
|
"project": {Name: "project", Help: "项目", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
}},
|
||||||
|
|
||||||
|
"compile": {Name: "compile [os [arch [main]]]", Help: "编译", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
if len(arg) == 0 {
|
||||||
|
// 目录列表
|
||||||
|
m.Cmdy("nfs.dir", m.Conf(cmd, "meta.path"), "time size path")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 编译目标
|
||||||
|
main := kit.Select("src/main.go", arg, 2)
|
||||||
|
arch := kit.Select(m.Conf(ice.CLI_RUNTIME, "host.GOARCH"), arg, 1)
|
||||||
|
goos := kit.Select(m.Conf(ice.CLI_RUNTIME, "host.GOOS"), arg, 0)
|
||||||
|
file := path.Join(m.Conf(cmd, "meta.path"), kit.Keys("ice", goos, arch))
|
||||||
|
|
||||||
|
// 编译参数
|
||||||
|
m.Optionv("cmd_env", "GOCACHE", os.Getenv("GOCACHE"), "HOME", os.Getenv("HOME"),
|
||||||
|
"GOARCH", arch, "GOOS", goos, "CGO_ENABLED", "0")
|
||||||
|
m.Cmd(ice.CLI_SYSTEM, "go", "build", "-o", file, main)
|
||||||
|
|
||||||
|
// 编译记录
|
||||||
|
m.Cmdy(ice.WEB_STORY, ice.STORY_CATCH, "bin", file)
|
||||||
|
m.Logs(ice.LOG_EXPORT, "source", main, "target", file)
|
||||||
|
}},
|
||||||
|
"publish": {Name: "publish [source]", Help: "发布", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
if len(arg) == 0 {
|
||||||
|
// 目录列表
|
||||||
|
m.Cmdy("nfs.dir", m.Conf(cmd, "meta.path"), "time size path")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if s, e := os.Stat(arg[0]); m.Assert(e) && s.IsDir() {
|
||||||
|
// 发布目录
|
||||||
|
p := path.Base(arg[0]) + ".tar.gz"
|
||||||
|
m.Cmd(ice.CLI_SYSTEM, "tar", "-zcf", p, arg[0])
|
||||||
|
defer func() { os.Remove(p) }()
|
||||||
|
arg[0] = p
|
||||||
|
}
|
||||||
|
|
||||||
|
// 发布文件
|
||||||
|
target := path.Join(m.Conf(cmd, "meta.path"), path.Base(arg[0]))
|
||||||
|
os.Remove(target)
|
||||||
|
os.MkdirAll(path.Dir(target), 0777)
|
||||||
|
os.Link(arg[0], target)
|
||||||
|
|
||||||
|
// 发布记录
|
||||||
|
m.Cmdy(ice.WEB_STORY, ice.STORY_CATCH, "bin", target)
|
||||||
|
m.Logs(ice.LOG_EXPORT, "source", arg[0], "target", target)
|
||||||
|
}},
|
||||||
|
"upgrade": {Name: "upgrade which", Help: "升级", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
exit := false
|
||||||
|
m.Grows(cmd, kit.Keys(kit.MDB_HASH, kit.Select("system", arg, 0)), "", "", func(index int, value map[string]interface{}) {
|
||||||
|
if value["file"] == "ice.bin" {
|
||||||
|
// 程序文件
|
||||||
|
value["file"] = kit.Keys("ice", m.Conf(ice.CLI_RUNTIME, "host.GOOS"), m.Conf(ice.CLI_RUNTIME, "host.GOARCH"))
|
||||||
|
exit = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// 下载文件
|
||||||
|
h := m.Cmdx(ice.WEB_SPIDE, "dev", "cache", "GET", "/publish/"+kit.Format(value["file"]))
|
||||||
|
if h == "" {
|
||||||
|
exit = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 升级记录
|
||||||
|
m.Cmd(ice.WEB_STORY, "add", "bin", value["path"], h)
|
||||||
|
m.Cmd(ice.WEB_STORY, ice.STORY_WATCH, h, value["path"])
|
||||||
|
os.Chmod(kit.Format(value["path"]), 0777)
|
||||||
|
})
|
||||||
|
if exit {
|
||||||
|
m.Sleep("1s").Gos(m, func(m *ice.Message) { m.Cmd("exit") })
|
||||||
|
}
|
||||||
|
}},
|
||||||
|
|
||||||
"login": {Name: "login", Help: "登录", Meta: kit.Dict(
|
"login": {Name: "login", Help: "登录", Meta: kit.Dict(
|
||||||
"detail", []string{"编辑", "清理", "清空", "删除"},
|
"detail", []string{"编辑", "删除", "清理", "清空"},
|
||||||
), List: ice.ListLook("key"), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
), List: ice.ListLook("key"), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
if len(arg) > 0 && arg[0] == "action" {
|
if len(arg) > 0 && arg[0] == "action" {
|
||||||
switch arg[1] {
|
switch arg[1] {
|
||||||
case "prune", "清理":
|
|
||||||
m.Cmdy("login", "prune")
|
|
||||||
case "clear", "清空":
|
|
||||||
|
|
||||||
case "modify", "编辑":
|
case "modify", "编辑":
|
||||||
m.Richs("login", nil, m.Option("key"), func(key string, value map[string]interface{}) {
|
m.Richs(cmd, nil, m.Option("key"), func(key string, value map[string]interface{}) {
|
||||||
m.Log(ice.LOG_MODIFY, "%s %s %v->%s", key, arg[2], value[arg[2]], arg[3])
|
m.Logs(ice.LOG_MODIFY, cmd, key, "field", arg[2], "value", kit.Value(value, arg[2]), "->", arg[3])
|
||||||
value[arg[2]] = arg[3]
|
kit.Value(value, arg[2], arg[3])
|
||||||
})
|
})
|
||||||
|
|
||||||
case "delete", "删除":
|
case "delete", "删除":
|
||||||
m.Log(ice.LOG_DELETE, "%s %s", m.Option("key"), m.Conf("login", kit.Keys("hash", m.Option("key"))))
|
m.Logs(ice.LOG_DELETE, cmd, m.Option("key"), "value", m.Conf(cmd, kit.Keys(kit.MDB_HASH, m.Option("key"))))
|
||||||
m.Conf("login", kit.Keys("hash", m.Option("key")), "")
|
m.Conf(cmd, kit.Keys(kit.MDB_HASH, m.Option("key")), "")
|
||||||
|
|
||||||
|
case "prune", "清理":
|
||||||
|
m.Cmdy(cmd, "prune")
|
||||||
|
|
||||||
|
case "clear", "清空":
|
||||||
|
m.Cmdy(cmd, "prune", "all")
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
switch kit.Select("list", arg, 0) {
|
switch kit.Select("list", arg, 0) {
|
||||||
case "init":
|
case "init":
|
||||||
if m.Option("sid") != "" && m.Confs("login", []string{"hash", m.Option("sid"), "status"}) {
|
if m.Option("sid") != "" && m.Conf(cmd, []string{kit.MDB_HASH, m.Option("sid"), "status"}) != "" {
|
||||||
// 复用会话
|
// 复用会话
|
||||||
m.Conf("login", []string{"hash", m.Option("sid"), "status"}, "login")
|
m.Conf(cmd, []string{kit.MDB_HASH, m.Option("sid"), "status"}, "login")
|
||||||
m.Log(ice.LOG_LOGIN, "sid: %s", m.Option("sid"))
|
m.Logs(ice.LOG_LOGIN, "sid", m.Option("sid"))
|
||||||
m.Echo(m.Option("sid"))
|
m.Echo(m.Option("sid"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
you := m.Conf(ice.WEB_SHARE, kit.Keys("hash", m.Option("share"), "name"))
|
you := m.Conf(ice.WEB_SHARE, kit.Keys(kit.MDB_HASH, m.Option("share"), "name"))
|
||||||
// 添加会话
|
// 添加会话
|
||||||
h := m.Rich("login", nil, kit.Dict(
|
h := m.Rich(cmd, nil, kit.Dict(
|
||||||
"status", "login",
|
|
||||||
"type", kit.Select("zsh", arg, 1),
|
"type", kit.Select("zsh", arg, 1),
|
||||||
|
"status", "login",
|
||||||
"you", you,
|
"you", you,
|
||||||
"pwd", m.Option("pwd"),
|
"pwd", m.Option("pwd"),
|
||||||
"pid", m.Option("pid"),
|
"pid", m.Option("pid"),
|
||||||
@ -98,9 +184,32 @@ var Index = &ice.Context{Name: "code", Help: "编程中心",
|
|||||||
"hostname", m.Option("hostname"),
|
"hostname", m.Option("hostname"),
|
||||||
"username", m.Option("username"),
|
"username", m.Option("username"),
|
||||||
))
|
))
|
||||||
m.Log(ice.LOG_LOGIN, "sid: %s you: %s", h, you)
|
m.Logs(ice.LOG_LOGIN, "sid", h, "you", you)
|
||||||
m.Echo(h)
|
m.Echo(h)
|
||||||
|
|
||||||
|
case "exit":
|
||||||
|
// 退出会话
|
||||||
|
m.Richs(cmd, nil, m.Option("sid"), func(key string, value map[string]interface{}) {
|
||||||
|
m.Logs(ice.LOG_LOGOUT, "sid", m.Option("sid"))
|
||||||
|
value["status"] = "logout"
|
||||||
|
m.Echo(key)
|
||||||
|
})
|
||||||
|
|
||||||
|
case "prune":
|
||||||
|
list := []string{}
|
||||||
|
m.Richs(cmd, nil, "*", func(key string, value map[string]interface{}) {
|
||||||
|
if len(arg) > 1 && arg[1] == "all" || value["status"] == "logout" {
|
||||||
|
list = append(list, key)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// 清理会话
|
||||||
|
kit.Fetch(list, func(index int, value string) {
|
||||||
|
m.Logs(ice.LOG_DELETE, "login", value, "value", m.Conf(cmd, kit.Keys(kit.MDB_HASH, value)))
|
||||||
|
m.Conf(cmd, kit.Keys(kit.MDB_HASH, value), "")
|
||||||
|
})
|
||||||
|
m.Echo("%d", len(list))
|
||||||
|
|
||||||
case "list":
|
case "list":
|
||||||
// 会话列表
|
// 会话列表
|
||||||
m.Richs("login", nil, "*", func(key string, value map[string]interface{}) {
|
m.Richs("login", nil, "*", func(key string, value map[string]interface{}) {
|
||||||
@ -114,113 +223,13 @@ var Index = &ice.Context{Name: "code", Help: "编程中心",
|
|||||||
m.Push(key, value, []string{"pid", "pane", "hostname", "username"})
|
m.Push(key, value, []string{"pid", "pane", "hostname", "username"})
|
||||||
})
|
})
|
||||||
|
|
||||||
case "prune":
|
|
||||||
list := []string{}
|
|
||||||
m.Richs("login", nil, "*", func(key string, value map[string]interface{}) {
|
|
||||||
if len(arg) > 1 && arg[1] == "all" || value["status"] == "logout" {
|
|
||||||
list = append(list, key)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// 清理会话
|
|
||||||
kit.Fetch(list, func(index int, value string) {
|
|
||||||
m.Log(ice.LOG_DELETE, "%s: %s", value, m.Conf("login", kit.Keys("hash", value)))
|
|
||||||
m.Conf("login", kit.Keys("hash", value), "")
|
|
||||||
})
|
|
||||||
m.Echo("%d", len(list))
|
|
||||||
|
|
||||||
case "exit":
|
|
||||||
// 退出会话
|
|
||||||
m.Richs("login", nil, m.Option("sid"), func(key string, value map[string]interface{}) {
|
|
||||||
m.Log(ice.LOG_LOGOUT, "sid: %s", m.Option("sid"))
|
|
||||||
value["status"] = "logout"
|
|
||||||
})
|
|
||||||
default:
|
default:
|
||||||
// 会话详情
|
// 会话详情
|
||||||
m.Richs("login", nil, arg[0], func(key string, value map[string]interface{}) {
|
m.Richs(cmd, nil, arg[0], func(key string, value map[string]interface{}) {
|
||||||
m.Push("detail", value)
|
m.Push("detail", value)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
|
|
||||||
"prepare": {Name: "prepare", Help: "准备", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
|
||||||
|
|
||||||
}},
|
|
||||||
|
|
||||||
"compile": {Name: "compile [os [arch]]", Help: "编译", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
|
||||||
if len(arg) == 0 {
|
|
||||||
// 目录列表
|
|
||||||
m.Cmdy("nfs.dir", m.Conf("publish", "meta.path"), "time size path")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 编译目标
|
|
||||||
main := kit.Select("src/main.go", arg, 2)
|
|
||||||
arch := kit.Select(m.Conf(ice.CLI_RUNTIME, "host.GOARCH"), arg, 1)
|
|
||||||
goos := kit.Select(m.Conf(ice.CLI_RUNTIME, "host.GOOS"), arg, 0)
|
|
||||||
file := path.Join(m.Conf("compile", "meta.path"), kit.Keys("ice", goos, arch))
|
|
||||||
|
|
||||||
// 编译参数
|
|
||||||
m.Optionv("cmd_env", "GOCACHE", os.Getenv("GOCACHE"), "HOME", os.Getenv("HOME"),
|
|
||||||
"GOARCH", arch, "GOOS", goos, "CGO_ENABLED", "0")
|
|
||||||
m.Cmd(ice.CLI_SYSTEM, "go", "build", "-o", file, main)
|
|
||||||
|
|
||||||
// 编译记录
|
|
||||||
m.Cmdy(ice.WEB_STORY, ice.STORY_CATCH, "bin", file)
|
|
||||||
m.Log(ice.LOG_EXPORT, "%s: %s", main, file)
|
|
||||||
}},
|
|
||||||
"publish": {Name: "publish", Help: "发布", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
|
||||||
if len(arg) == 0 {
|
|
||||||
// 目录列表
|
|
||||||
m.Cmdy("nfs.dir", m.Conf("publish", "meta.path"), "time size path")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
p := arg[0]
|
|
||||||
if s, e := os.Stat(arg[0]); m.Assert(e) && s.IsDir() {
|
|
||||||
// 发布目录
|
|
||||||
p = path.Base(arg[0]) + ".tar.gz"
|
|
||||||
m.Cmd(ice.CLI_SYSTEM, "tar", "-zcf", p, arg[0])
|
|
||||||
defer func() { os.Remove(p) }()
|
|
||||||
arg[0] = p
|
|
||||||
}
|
|
||||||
|
|
||||||
// 发布文件
|
|
||||||
target := path.Join(m.Conf("publish", "meta.path"), path.Base(arg[0]))
|
|
||||||
os.Remove(target)
|
|
||||||
os.MkdirAll(path.Dir(target), 0777)
|
|
||||||
os.Link(arg[0], target)
|
|
||||||
|
|
||||||
// 发布记录
|
|
||||||
m.Cmdy(ice.WEB_STORY, ice.STORY_CATCH, "bin", p)
|
|
||||||
m.Log(ice.LOG_EXPORT, "%s: %s", arg[0], target)
|
|
||||||
}},
|
|
||||||
"upgrade": {Name: "upgrade", Help: "升级", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
|
||||||
exit := true
|
|
||||||
m.Grows("upgrade", "hash.system", "", "", func(index int, value map[string]interface{}) {
|
|
||||||
if value["file"] == "ice.bin" {
|
|
||||||
value["file"] = kit.Keys("ice", m.Conf(ice.CLI_RUNTIME, "host.GOOS"), m.Conf(ice.CLI_RUNTIME, "host.GOARCH"))
|
|
||||||
}
|
|
||||||
|
|
||||||
h := m.Cmdx(ice.WEB_SPIDE, "dev", "cache", "GET", "/publish/"+kit.Format(value["file"]))
|
|
||||||
if h == "" {
|
|
||||||
exit = false
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
m.Cmd(ice.WEB_STORY, "add", "bin", value["path"], h)
|
|
||||||
m.Cmd(ice.WEB_STORY, ice.STORY_WATCH, h, value["path"])
|
|
||||||
os.Chmod(kit.Format(value["path"]), 777)
|
|
||||||
})
|
|
||||||
|
|
||||||
if exit {
|
|
||||||
m.Cmd("exit")
|
|
||||||
}
|
|
||||||
}},
|
|
||||||
|
|
||||||
"test": {Name: "test src", Help: "功能测试", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
|
||||||
m.Cmdy(ice.CLI_SYSTEM, "go", "test", kit.Select("./", arg, 0))
|
|
||||||
}},
|
|
||||||
"pprof": {Name: "pprof run name time", Help: "性能分析", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
"pprof": {Name: "pprof run name time", Help: "性能分析", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
if m.Show(cmd, arg...) {
|
if m.Show(cmd, arg...) {
|
||||||
return
|
return
|
||||||
@ -231,10 +240,12 @@ var Index = &ice.Context{Name: "code", Help: "编程中心",
|
|||||||
m.Richs(cmd, nil, arg[1], func(key string, value map[string]interface{}) {
|
m.Richs(cmd, nil, arg[1], func(key string, value map[string]interface{}) {
|
||||||
m.Gos(m.Spawn(), func(msg *ice.Message) {
|
m.Gos(m.Spawn(), func(msg *ice.Message) {
|
||||||
m.Sleep("1s").Grows(cmd, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) {
|
m.Sleep("1s").Grows(cmd, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) {
|
||||||
m.Cmd(ice.WEB_FAVOR, "pprof", "shell", value["text"], m.Cmdx(kit.Split(kit.Format(value["text"]))))
|
// 压测命令
|
||||||
|
m.Cmd(ice.WEB_FAVOR, "pprof", "shell", value[kit.MDB_TEXT], m.Cmdx(kit.Split(kit.Format(value[kit.MDB_TEXT]))))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 启动监控
|
||||||
name := arg[1] + ".pd.gz"
|
name := arg[1] + ".pd.gz"
|
||||||
value = value["meta"].(map[string]interface{})
|
value = value["meta"].(map[string]interface{})
|
||||||
msg := m.Cmd(ice.WEB_SPIDE, "self", "cache", "GET", kit.Select("/code/pprof/profile", value["remote"]), "seconds", kit.Select("5", arg, 2))
|
msg := m.Cmd(ice.WEB_SPIDE, "self", "cache", "GET", kit.Select("/code/pprof/profile", value["remote"]), "seconds", kit.Select("5", arg, 2))
|
||||||
@ -246,6 +257,7 @@ var Index = &ice.Context{Name: "code", Help: "编程中心",
|
|||||||
|
|
||||||
fallthrough
|
fallthrough
|
||||||
case "web":
|
case "web":
|
||||||
|
// 展示结果
|
||||||
p := kit.Format("%s:%s", m.Conf(ice.WEB_SHARE, "meta.host"), m.Cmdx("tcp.getport"))
|
p := kit.Format("%s:%s", m.Conf(ice.WEB_SHARE, "meta.host"), m.Cmdx("tcp.getport"))
|
||||||
m.Cmd(ice.CLI_DAEMON, "go", "tool", "pprof", "-http="+p, arg[1:])
|
m.Cmd(ice.CLI_DAEMON, "go", "tool", "pprof", "-http="+p, arg[1:])
|
||||||
m.Cmd(ice.WEB_FAVOR, "pprof", "bin", arg[1], m.Cmd(ice.WEB_CACHE, "catch", "bin", arg[1]).Append("data"))
|
m.Cmd(ice.WEB_FAVOR, "pprof", "bin", arg[1], m.Cmd(ice.WEB_CACHE, "catch", "bin", arg[1]).Append("data"))
|
||||||
@ -259,6 +271,7 @@ var Index = &ice.Context{Name: "code", Help: "编程中心",
|
|||||||
key := m.Rich(cmd, nil, kit.Data(
|
key := m.Rich(cmd, nil, kit.Data(
|
||||||
kit.MDB_NAME, arg[1], kit.MDB_TEXT, arg[2], "remote", arg[3],
|
kit.MDB_NAME, arg[1], kit.MDB_TEXT, arg[2], "remote", arg[3],
|
||||||
))
|
))
|
||||||
|
|
||||||
for i := 4; i < len(arg)-1; i += 2 {
|
for i := 4; i < len(arg)-1; i += 2 {
|
||||||
m.Grow(cmd, kit.Keys(kit.MDB_HASH, key), kit.Dict(
|
m.Grow(cmd, kit.Keys(kit.MDB_HASH, key), kit.Dict(
|
||||||
kit.MDB_NAME, arg[i], kit.MDB_TEXT, arg[i+1],
|
kit.MDB_NAME, arg[i], kit.MDB_TEXT, arg[i+1],
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
package vim
|
package vim
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
"path"
|
|
||||||
|
|
||||||
ice "github.com/shylinux/icebergs"
|
ice "github.com/shylinux/icebergs"
|
||||||
"github.com/shylinux/icebergs/base/web"
|
"github.com/shylinux/icebergs/base/web"
|
||||||
"github.com/shylinux/icebergs/core/code"
|
"github.com/shylinux/icebergs/core/code"
|
||||||
kit "github.com/shylinux/toolkits"
|
kit "github.com/shylinux/toolkits"
|
||||||
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -18,50 +17,64 @@ var Index = &ice.Context{Name: "vim", Help: "编辑器",
|
|||||||
Configs: map[string]*ice.Config{
|
Configs: map[string]*ice.Config{
|
||||||
"vim": {Name: "vim", Help: "编辑器", Value: kit.Data(
|
"vim": {Name: "vim", Help: "编辑器", Value: kit.Data(
|
||||||
"source", "ftp://ftp.vim.org/pub/vim/unix/vim-8.1.tar.bz2",
|
"source", "ftp://ftp.vim.org/pub/vim/unix/vim-8.1.tar.bz2",
|
||||||
"version", "vim81",
|
"target", "usr/local", "version", "vim81", "config", []interface{}{
|
||||||
|
"--enable-pythoninterp=yes",
|
||||||
kit.MDB_SHORT, "name", "history", "vim.history",
|
"--enable-luainterp=yes",
|
||||||
"script", "",
|
"--enable-cscope=yes",
|
||||||
|
}, "history", "vim.history",
|
||||||
)},
|
)},
|
||||||
},
|
},
|
||||||
Commands: map[string]*ice.Command{
|
Commands: map[string]*ice.Command{
|
||||||
ice.CODE_INSTALL: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
ice.CODE_INSTALL: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
p := path.Join(m.Conf("install", "meta.path"), m.Conf("vim", "meta.version"))
|
p := path.Join(m.Conf("install", "meta.path"), m.Conf("vim", "meta.version"))
|
||||||
if _, e := os.Stat(p); e != nil {
|
if _, e := os.Stat(p); e != nil {
|
||||||
|
// 下载源码
|
||||||
m.Option("cmd_dir", m.Conf("install", "meta.path"))
|
m.Option("cmd_dir", m.Conf("install", "meta.path"))
|
||||||
m.Cmd(ice.CLI_SYSTEM, "wget", "-O", "vim.tar.gz", m.Conf("vim", "meta.source"))
|
m.Cmd(ice.CLI_SYSTEM, "wget", "-O", "vim.tar.gz", m.Conf("vim", "meta.source"))
|
||||||
m.Cmd(ice.CLI_SYSTEM, "tar", "xvf", "vim.tar.gz")
|
m.Cmd(ice.CLI_SYSTEM, "tar", "xvf", "vim.tar.gz")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 配置选项
|
||||||
m.Option("cmd_dir", p)
|
m.Option("cmd_dir", p)
|
||||||
m.Cmd(ice.CLI_SYSTEM, "./configure", "--enable-multibyte=yes",
|
m.Cmdy(ice.CLI_SYSTEM, "./configure", "--prefix="+kit.Path(m.Conf("vim", "meta.target")),
|
||||||
"--prefix="+kit.Path("usr/local"), "--enable-cscope=yes",
|
"--enable-multibyte=yes", m.Confv("vim", "meta.config"))
|
||||||
"--enable-luainterp=yes", "--enable-pythoninterp=yes",
|
|
||||||
)
|
|
||||||
|
|
||||||
m.Cmd(ice.CLI_SYSTEM, "make", "-j4")
|
// 编译安装
|
||||||
m.Cmd(ice.CLI_SYSTEM, "make", "install")
|
m.Cmdy(ice.CLI_SYSTEM, "make", "-j4")
|
||||||
|
m.Cmdy(ice.CLI_SYSTEM, "make", "install")
|
||||||
}},
|
}},
|
||||||
ice.CODE_PREPARE: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
ice.CODE_PREPARE: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
// 语法脚本
|
||||||
|
for _, s := range []string{"go.vim", "shy.vim", "javascript.vim"} {
|
||||||
|
m.Cmd("nfs.link", path.Join(os.Getenv("HOME"), ".vim/syntax/"+s), "etc/conf/"+s)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 启动脚本
|
||||||
|
m.Cmd("nfs.link", path.Join(os.Getenv("HOME"), ".vim/autoload/plug.vim"), "etc/conf/plug.vim")
|
||||||
|
m.Cmd("nfs.link", path.Join(os.Getenv("HOME"), ".vimrc"), "etc/conf/vimrc")
|
||||||
|
|
||||||
|
// 安装插件
|
||||||
|
m.Echo("vim -c PlugInstall\n")
|
||||||
|
m.Echo("vim -c GoInstallBinaries\n")
|
||||||
|
}},
|
||||||
|
ice.CODE_PROJECT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
}},
|
}},
|
||||||
|
|
||||||
ice.WEB_LOGIN: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
ice.WEB_LOGIN: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
if f, _, e := m.R.FormFile("sub"); e == nil {
|
if f, _, e := m.R.FormFile("sub"); e == nil {
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
// 文件参数
|
||||||
if b, e := ioutil.ReadAll(f); e == nil {
|
if b, e := ioutil.ReadAll(f); e == nil {
|
||||||
// 加载参数
|
|
||||||
m.Option("sub", string(b))
|
m.Option("sub", string(b))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m.Option("you", "tmux")
|
|
||||||
m.Richs("login", nil, m.Option("sid"), func(key string, value map[string]interface{}) {
|
m.Richs("login", nil, m.Option("sid"), func(key string, value map[string]interface{}) {
|
||||||
// 查找空间
|
// 查找空间
|
||||||
m.Option("you", value["you"])
|
m.Option("you", value["you"])
|
||||||
})
|
})
|
||||||
|
|
||||||
m.Info("%s %s cmd: %v sub: %v", m.Option("you"), m.Option(ice.MSG_USERURL), m.Optionv("cmds"), m.Optionv("sub"))
|
m.Logs(ice.LOG_LOGIN, "you", m.Option("you"), "url", m.Option(ice.MSG_USERURL), "cmd", m.Optionv("cmds"), "sub", m.Optionv("sub"))
|
||||||
m.Option(ice.MSG_OUTPUT, ice.RENDER_RESULT)
|
m.Option(ice.MSG_OUTPUT, ice.RENDER_RESULT)
|
||||||
}},
|
}},
|
||||||
"/help": {Name: "/help", Help: "帮助", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
"/help": {Name: "/help", Help: "帮助", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
@ -77,11 +90,9 @@ var Index = &ice.Context{Name: "vim", Help: "编辑器",
|
|||||||
"/sync": {Name: "/sync", Help: "同步", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
"/sync": {Name: "/sync", Help: "同步", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
switch arg[0] {
|
switch arg[0] {
|
||||||
case "read", "write", "exec", "insert":
|
case "read", "write", "exec", "insert":
|
||||||
cmds := []string{ice.WEB_FAVOR, m.Conf("vim", "meta.history"), "vimrc", arg[0], kit.Select(m.Option("arg"), m.Option("sub")),
|
m.Cmd(ice.WEB_FAVOR, m.Conf("vim", "meta.history"), ice.TYPE_VIMRC, arg[0], kit.Select(m.Option("arg"), m.Option("sub")),
|
||||||
"sid", m.Option("sid"), "pwd", m.Option("pwd"), "buf", m.Option("buf"), "row", m.Option("row"), "col", m.Option("col")}
|
"sid", m.Option("sid"), "pwd", m.Option("pwd"), "buf", m.Option("buf"), "row", m.Option("row"), "col", m.Option("col"))
|
||||||
if m.Cmd(cmds); m.Option("you") != "" {
|
|
||||||
m.Cmd(ice.WEB_PROXY, m.Option("you"), cmds)
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
m.Richs("login", nil, m.Option("sid"), func(key string, value map[string]interface{}) {
|
m.Richs("login", nil, m.Option("sid"), func(key string, value map[string]interface{}) {
|
||||||
kit.Value(value, kit.Keys("sync", arg[0]), kit.Dict(
|
kit.Value(value, kit.Keys("sync", arg[0]), kit.Dict(
|
||||||
@ -101,8 +112,7 @@ var Index = &ice.Context{Name: "vim", Help: "编辑器",
|
|||||||
arg[0] = list[4]
|
arg[0] = list[4]
|
||||||
default:
|
default:
|
||||||
// 执行命令
|
// 执行命令
|
||||||
m.Set("append")
|
if m.Cmdy(list[1:]); m.Result() == "" {
|
||||||
if m.Cmdy(arg); m.Result() == "" {
|
|
||||||
m.Table()
|
m.Table()
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@ -113,12 +123,12 @@ var Index = &ice.Context{Name: "vim", Help: "编辑器",
|
|||||||
m.Cmd("web.code.input.find", arg[0]).Table(func(index int, value map[string]string, head []string) {
|
m.Cmd("web.code.input.find", arg[0]).Table(func(index int, value map[string]string, head []string) {
|
||||||
m.Echo("%s\n", value["text"])
|
m.Echo("%s\n", value["text"])
|
||||||
})
|
})
|
||||||
m.Info("input %v", m.Result())
|
|
||||||
}},
|
}},
|
||||||
"/favor": {Name: "/favor", Help: "收藏", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
"/favor": {Name: "/favor", Help: "收藏", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
if m.Options("arg") {
|
if m.Options("arg") {
|
||||||
// 添加收藏
|
// 添加收藏
|
||||||
m.Cmdy(ice.WEB_FAVOR, m.Option("tab"), "vimrc", m.Option("note"), m.Option("arg"),
|
m.Cmdy(ice.WEB_FAVOR, kit.Select(m.Conf("vim", "meta.history"), m.Option("tab")),
|
||||||
|
ice.TYPE_VIMRC, m.Option("note"), m.Option("arg"),
|
||||||
"pwd", m.Option("pwd"), "buf", m.Option("buf"), "row", m.Option("row"), "col", m.Option("col"))
|
"pwd", m.Option("pwd"), "buf", m.Option("buf"), "row", m.Option("row"), "col", m.Option("col"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package zsh
|
package zsh
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/shylinux/icebergs"
|
ice "github.com/shylinux/icebergs"
|
||||||
"github.com/shylinux/icebergs/base/web"
|
"github.com/shylinux/icebergs/base/web"
|
||||||
"github.com/shylinux/icebergs/core/code"
|
"github.com/shylinux/icebergs/core/code"
|
||||||
"github.com/shylinux/toolkits"
|
kit "github.com/shylinux/toolkits"
|
||||||
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"strings"
|
"strings"
|
||||||
@ -14,24 +14,24 @@ import (
|
|||||||
var Index = &ice.Context{Name: "zsh", Help: "命令行",
|
var Index = &ice.Context{Name: "zsh", Help: "命令行",
|
||||||
Caches: map[string]*ice.Cache{},
|
Caches: map[string]*ice.Cache{},
|
||||||
Configs: map[string]*ice.Config{
|
Configs: map[string]*ice.Config{
|
||||||
"zsh": {Name: "zsh", Help: "命令行", Value: kit.Data(kit.MDB_SHORT, "name", "history", "zsh.history")},
|
"zsh": {Name: "zsh", Help: "命令行", Value: kit.Data("history", "zsh.history")},
|
||||||
},
|
},
|
||||||
Commands: map[string]*ice.Command{
|
Commands: map[string]*ice.Command{
|
||||||
ice.WEB_LOGIN: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
ice.WEB_LOGIN: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
if f, _, e := m.R.FormFile("sub"); e == nil {
|
if f, _, e := m.R.FormFile("sub"); e == nil {
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
// 文件参数
|
||||||
if b, e := ioutil.ReadAll(f); e == nil {
|
if b, e := ioutil.ReadAll(f); e == nil {
|
||||||
// 加载参数
|
|
||||||
m.Option("sub", string(b))
|
m.Option("sub", string(b))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找空间
|
|
||||||
m.Richs("login", nil, m.Option("sid"), func(key string, value map[string]interface{}) {
|
m.Richs("login", nil, m.Option("sid"), func(key string, value map[string]interface{}) {
|
||||||
m.Option("you", kit.Select("tmux", value["you"]))
|
// 查找空间
|
||||||
|
m.Option("you", value["you"])
|
||||||
})
|
})
|
||||||
|
|
||||||
m.Info("%s %s cmd: %v sub: %v", m.Option("you"), m.Option(ice.MSG_USERURL), m.Optionv("cmds"), m.Optionv("sub"))
|
m.Logs(ice.LOG_LOGIN, "you", m.Option("you"), "url", m.Option(ice.MSG_USERURL), "cmd", m.Optionv("cmds"), "sub", m.Optionv("sub"))
|
||||||
m.Option(ice.MSG_OUTPUT, ice.RENDER_RESULT)
|
m.Option(ice.MSG_OUTPUT, ice.RENDER_RESULT)
|
||||||
}},
|
}},
|
||||||
|
|
||||||
@ -50,16 +50,11 @@ var Index = &ice.Context{Name: "zsh", Help: "命令行",
|
|||||||
case "history":
|
case "history":
|
||||||
vs := strings.SplitN(strings.TrimSpace(m.Option("arg")), " ", 4)
|
vs := strings.SplitN(strings.TrimSpace(m.Option("arg")), " ", 4)
|
||||||
if strings.Contains(m.Option("SHELL"), "zsh") {
|
if strings.Contains(m.Option("SHELL"), "zsh") {
|
||||||
vs = []string{vs[0], "", "", strings.Join(vs[1:], " ")}
|
vs = []string{vs[0], m.Time("2006-01-02"), m.Time("15:04:05"), strings.Join(vs[1:], " ")}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
m.Cmd(ice.WEB_FAVOR, m.Conf("zsh", "meta.history"), ice.TYPE_SHELL, vs[0], kit.Select("", vs, 3),
|
||||||
|
"sid", m.Option("sid"), "pwd", m.Option("pwd"), "time", vs[1]+" "+vs[2])
|
||||||
|
|
||||||
cmds := []string{ice.WEB_FAVOR, m.Conf("zsh", "meta.history"), ice.TYPE_SHELL, vs[0], kit.Select("", vs, 3),
|
|
||||||
"sid", m.Option("sid"), "pwd", m.Option("pwd"), "time", vs[1] + " " + vs[2]}
|
|
||||||
|
|
||||||
if m.Cmd(cmds); m.Option("you") != "" {
|
|
||||||
m.Cmd(ice.WEB_PROXY, m.Option("you"), cmds)
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
m.Richs("login", nil, m.Option("sid"), func(key string, value map[string]interface{}) {
|
m.Richs("login", nil, m.Option("sid"), func(key string, value map[string]interface{}) {
|
||||||
kit.Value(value, kit.Keys("sync", arg[0]), kit.Dict(
|
kit.Value(value, kit.Keys("sync", arg[0]), kit.Dict(
|
||||||
@ -159,14 +154,14 @@ var Index = &ice.Context{Name: "zsh", Help: "命令行",
|
|||||||
"/favor": {Name: "/favor", Help: "收藏", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
"/favor": {Name: "/favor", Help: "收藏", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
if len(arg) > 0 && arg[0] != "sh" {
|
if len(arg) > 0 && arg[0] != "sh" {
|
||||||
// 添加收藏
|
// 添加收藏
|
||||||
m.Cmdy(ice.WEB_FAVOR, kit.Select("zsh.history", m.Option("tab")), kit.Select(ice.TYPE_SHELL, m.Option("type")), m.Option("note"), arg[0])
|
m.Cmdy(ice.WEB_FAVOR, kit.Select(m.Conf("zsh", "meta.history"), m.Option("tab")),
|
||||||
|
kit.Select(ice.TYPE_SHELL, m.Option("type")), m.Option("note"), arg[0])
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if m.Option("tab") == "" {
|
if m.Option("tab") == "" {
|
||||||
// 收藏列表
|
// 收藏列表
|
||||||
m.Cmdy(ice.WEB_PROXY, m.Option("you"), ice.WEB_FAVOR)
|
m.Cmdy(ice.WEB_FAVOR).Table()
|
||||||
m.Table()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,8 +180,7 @@ var Index = &ice.Context{Name: "zsh", Help: "命令行",
|
|||||||
"/download": {Name: "/download", Help: "下载", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
"/download": {Name: "/download", Help: "下载", 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(ice.WEB_PROXY, m.Option("you"), ice.WEB_STORY)
|
m.Cmdy(ice.WEB_PROXY, m.Option("you"), ice.WEB_STORY).Table()
|
||||||
m.Table()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,11 +202,6 @@ var Index = &ice.Context{Name: "zsh", Help: "命令行",
|
|||||||
m.Echo("type: %s\n", msg.Append("type"))
|
m.Echo("type: %s\n", msg.Append("type"))
|
||||||
m.Echo("name: %s\n", msg.Append("name"))
|
m.Echo("name: %s\n", msg.Append("name"))
|
||||||
m.Echo("size: %s\n", msg.Append("size"))
|
m.Echo("size: %s\n", msg.Append("size"))
|
||||||
|
|
||||||
if m.Option("you") != "" {
|
|
||||||
// 下发文件
|
|
||||||
m.Cmd(ice.WEB_PROXY, m.Option("you"), ice.WEB_STORY, ice.STORY_PULL, msg.Append("name"), "dev", msg.Append("name"))
|
|
||||||
}
|
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
4
type.go
4
type.go
@ -1,7 +1,7 @@
|
|||||||
package ice
|
package ice
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/shylinux/toolkits"
|
kit "github.com/shylinux/toolkits"
|
||||||
|
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/csv"
|
"encoding/csv"
|
||||||
@ -795,7 +795,7 @@ func (m *Message) Result(arg ...interface{}) string {
|
|||||||
|
|
||||||
func (m *Message) Logs(level string, arg ...interface{}) *Message {
|
func (m *Message) Logs(level string, arg ...interface{}) *Message {
|
||||||
list := []string{}
|
list := []string{}
|
||||||
for i := 0; i < len(arg)-1; i++ {
|
for i := 0; i < len(arg)-1; i += 2 {
|
||||||
list = append(list, fmt.Sprintf("%v: %v", arg[i], arg[i+1]))
|
list = append(list, fmt.Sprintf("%v: %v", arg[i], arg[i+1]))
|
||||||
}
|
}
|
||||||
m.Log(level, strings.Join(list, " "))
|
m.Log(level, strings.Join(list, " "))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user