mirror of
https://shylinux.com/x/icebergs
synced 2025-04-26 01:24:05 +08:00
mix github
This commit is contained in:
commit
ead1f551cd
@ -131,12 +131,13 @@ func init() {
|
||||
})
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if len(arg) < 2 {
|
||||
if len(arg) < 2 { // 角色列表
|
||||
_role_list(m, kit.Select("", arg, 0))
|
||||
m.PushAction(mdb.REMOVE)
|
||||
return
|
||||
}
|
||||
|
||||
// 设置角色
|
||||
_role_user(m, arg[0], arg[1:]...)
|
||||
}},
|
||||
},
|
||||
|
@ -53,8 +53,6 @@ func SessIsCli(m *ice.Message) bool {
|
||||
const (
|
||||
IP = "ip"
|
||||
UA = "ua"
|
||||
|
||||
SESSID = "sessid"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -33,8 +33,7 @@ func _user_remove(m *ice.Message, name string) {
|
||||
}
|
||||
func _user_search(m *ice.Message, kind, name, text string) {
|
||||
m.Richs(USER, nil, kit.MDB_FOREACH, func(key string, value map[string]interface{}) {
|
||||
value = kit.GetMeta(value)
|
||||
if name != "" && name != value[USERNAME] {
|
||||
if value = kit.GetMeta(value); name != "" && name != value[USERNAME] {
|
||||
return
|
||||
}
|
||||
m.PushSearch(kit.SSH_CMD, USER, kit.MDB_TYPE, kit.Format(UserRole(m, value[USERNAME])),
|
||||
@ -144,7 +143,7 @@ func init() {
|
||||
m.Table(func(index int, value map[string]string, head []string) {
|
||||
m.Push(USERROLE, UserRole(m, value[USERNAME]))
|
||||
})
|
||||
m.PushAction(ROLE, mdb.REMOVE)
|
||||
m.PushAction(mdb.REMOVE)
|
||||
}},
|
||||
},
|
||||
})
|
||||
|
@ -1,15 +1,14 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
|
||||
"os"
|
||||
"os/user"
|
||||
"path"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
ice "github.com/shylinux/icebergs"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
)
|
||||
|
||||
func NodeInfo(m *ice.Message, kind, name string) {
|
||||
@ -26,13 +25,9 @@ var Index = &ice.Context{Name: "cli", Help: "命令模块",
|
||||
m.Load()
|
||||
|
||||
// 启动配置
|
||||
m.Conf(RUNTIME, "conf.ctx_self", os.Getenv("ctx_self"))
|
||||
m.Conf(RUNTIME, "conf.ctx_dev", os.Getenv("ctx_dev"))
|
||||
m.Conf(RUNTIME, "conf.ctx_shy", os.Getenv("ctx_shy"))
|
||||
m.Conf(RUNTIME, "conf.ctx_pid", os.Getenv("ctx_pid"))
|
||||
m.Conf(RUNTIME, "conf.ctx_user", os.Getenv("ctx_user"))
|
||||
m.Conf(RUNTIME, "conf.ctx_share", os.Getenv("ctx_share"))
|
||||
m.Conf(RUNTIME, "conf.ctx_river", os.Getenv("ctx_river"))
|
||||
for _, k := range []string{"ctx_self", "ctx_dev", "ctx_shy", "ctx_pid", "ctx_user", "ctx_share", "ctx_river"} {
|
||||
m.Conf(RUNTIME, kit.Keys("conf", k), os.Getenv(k))
|
||||
}
|
||||
|
||||
// 主机信息
|
||||
m.Conf(RUNTIME, "host.GOARCH", runtime.GOARCH)
|
||||
@ -63,7 +58,7 @@ var Index = &ice.Context{Name: "cli", Help: "命令模块",
|
||||
ice.Info.CtxShare = m.Conf(RUNTIME, "conf.ctx_share")
|
||||
ice.Info.CtxRiver = m.Conf(RUNTIME, "conf.ctx_river")
|
||||
|
||||
// 启动记录
|
||||
// 启动次数
|
||||
count := kit.Int(m.Conf(RUNTIME, "boot.count")) + 1
|
||||
m.Conf(RUNTIME, "boot.count", count)
|
||||
|
||||
@ -78,24 +73,13 @@ var Index = &ice.Context{Name: "cli", Help: "命令模块",
|
||||
|
||||
// 版本信息
|
||||
kit.Fetch(kit.UnMarshal(kit.Format(ice.Info.Build)), func(key string, value interface{}) {
|
||||
m.Conf(RUNTIME, kit.Keys("build", strings.ToLower(key)), value)
|
||||
m.Conf(RUNTIME, kit.Keys("make", strings.ToLower(key)), value)
|
||||
})
|
||||
}},
|
||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
list := []string{}
|
||||
m.Richs(DAEMON, "", kit.MDB_FOREACH, func(key string, value map[string]interface{}) {
|
||||
if value = kit.GetMeta(value); kit.Value(value, mdb.CACHE_CLEAR_ON_EXIT) == "true" {
|
||||
list = append(list, key)
|
||||
}
|
||||
})
|
||||
for _, k := range list {
|
||||
m.Conf(DAEMON, kit.Keys(kit.MDB_HASH, k), "")
|
||||
}
|
||||
m.Save()
|
||||
}},
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
ice.Index.Register(Index, nil, RUNTIME, SYSTEM, DAEMON, QRCODE, PYTHON, OUTPUT, PROGRESS)
|
||||
}
|
||||
func init() { ice.Index.Register(Index, nil, RUNTIME, SYSTEM, DAEMON, QRCODE) }
|
||||
|
@ -1,16 +1,7 @@
|
||||
chapter "cli"
|
||||
|
||||
field "脚本" python
|
||||
field "扫码" qrcode
|
||||
field "守护" daemon
|
||||
field "命令" system
|
||||
field "输出" output
|
||||
field "环境" runtime
|
||||
field "进程" cli.proc
|
||||
|
||||
section "python"
|
||||
refer `
|
||||
官网 https://www.python.org/
|
||||
源码 https://www.python.org/downloads/source/
|
||||
文档 https://docs.python.org/3/reference/index.html
|
||||
`
|
||||
|
||||
|
@ -2,47 +2,49 @@ package cli
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os/exec"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func _daemon_show(m *ice.Message, cmd *exec.Cmd, out, err string) {
|
||||
if w, ok := m.Optionv(CMD_STDOUT).(io.Writer); ok {
|
||||
if w, ok := m.Optionv(CMD_OUTPUT).(io.Writer); ok {
|
||||
cmd.Stdout = w
|
||||
cmd.Stderr = w
|
||||
} else if f, p, e := kit.Create(out); m.Assert(e) {
|
||||
m.Log_EXPORT(kit.MDB_META, DAEMON, CMD_STDOUT, p)
|
||||
m.Optionv(CMD_STDOUT, f)
|
||||
m.Log_EXPORT(kit.MDB_META, DAEMON, CMD_OUTPUT, p)
|
||||
m.Optionv(CMD_OUTPUT, f)
|
||||
cmd.Stdout = f
|
||||
cmd.Stderr = f
|
||||
}
|
||||
if w, ok := m.Optionv(CMD_STDERR).(io.Writer); ok {
|
||||
if w, ok := m.Optionv(CMD_ERRPUT).(io.Writer); ok {
|
||||
cmd.Stderr = w
|
||||
} else if f, p, e := kit.Create(err); m.Assert(e) {
|
||||
m.Log_EXPORT(kit.MDB_META, DAEMON, CMD_STDERR, p)
|
||||
m.Optionv(CMD_STDERR, f)
|
||||
m.Log_EXPORT(kit.MDB_META, DAEMON, CMD_ERRPUT, p)
|
||||
m.Optionv(CMD_ERRPUT, f)
|
||||
cmd.Stderr = f
|
||||
}
|
||||
|
||||
if e := cmd.Start(); m.Warn(e != nil, ErrStart, cmd.Args, " ", e) {
|
||||
// 启动进程
|
||||
if e := cmd.Start(); m.Warn(e != nil, cmd.Args, " ", e) {
|
||||
return
|
||||
}
|
||||
|
||||
h := m.Cmdx(mdb.INSERT, DAEMON, "", mdb.HASH,
|
||||
mdb.CACHE_CLEAR_ON_EXIT, m.Option(mdb.CACHE_CLEAR_ON_EXIT),
|
||||
kit.MDB_STATUS, Status.Start, kit.SSH_CMD, strings.Join(cmd.Args, " "),
|
||||
kit.SSH_DIR, cmd.Dir, kit.SSH_ENV, kit.Select("", cmd.Env), kit.SSH_PID, cmd.Process.Pid,
|
||||
CMD_STDOUT, out, CMD_STDERR, err,
|
||||
)
|
||||
m.Echo("%d", cmd.Process.Pid)
|
||||
|
||||
m.Go(func() {
|
||||
if e := cmd.Wait(); m.Warn(e != nil, ErrStart, cmd.Args, " ", e) {
|
||||
h := m.Cmdx(mdb.INSERT, DAEMON, "", mdb.HASH,
|
||||
kit.MDB_STATUS, Status.Start, kit.SSH_PID, cmd.Process.Pid,
|
||||
kit.SSH_CMD, strings.Join(cmd.Args, " "),
|
||||
kit.SSH_DIR, cmd.Dir, kit.SSH_ENV, kit.Select("", cmd.Env),
|
||||
mdb.CACHE_CLEAR_ON_EXIT, m.Option(mdb.CACHE_CLEAR_ON_EXIT),
|
||||
CMD_OUTPUT, out, CMD_ERRPUT, err,
|
||||
)
|
||||
|
||||
if e := cmd.Wait(); m.Warn(e != nil, cmd.Args, " ", e) {
|
||||
m.Cmd(mdb.MODIFY, DAEMON, "", mdb.HASH, kit.MDB_HASH, h,
|
||||
kit.MDB_STATUS, Status.Error, kit.MDB_ERROR, e)
|
||||
} else {
|
||||
@ -50,17 +52,16 @@ func _daemon_show(m *ice.Message, cmd *exec.Cmd, out, err string) {
|
||||
m.Cmd(mdb.MODIFY, DAEMON, "", mdb.HASH, kit.MDB_HASH, h,
|
||||
kit.MDB_STATUS, Status.Stop)
|
||||
}
|
||||
if w, ok := m.Optionv(CMD_STDOUT).(io.Closer); ok {
|
||||
|
||||
if w, ok := m.Optionv(CMD_OUTPUT).(io.Closer); ok {
|
||||
w.Close()
|
||||
}
|
||||
if w, ok := m.Optionv(CMD_STDERR).(io.Closer); ok {
|
||||
if w, ok := m.Optionv(CMD_ERRPUT).(io.Closer); ok {
|
||||
w.Close()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const ErrStart = "daemon start: "
|
||||
|
||||
var Status = struct{ Error, Start, Stop string }{
|
||||
Error: "error",
|
||||
Start: "start",
|
||||
@ -68,10 +69,10 @@ var Status = struct{ Error, Start, Stop string }{
|
||||
}
|
||||
|
||||
const (
|
||||
DIR = "dir"
|
||||
ENV = "env"
|
||||
CMD = "cmd"
|
||||
ARG = "arg"
|
||||
DIR = "dir"
|
||||
RUN = "run"
|
||||
RES = "res"
|
||||
ERR = "err"
|
||||
@ -87,9 +88,23 @@ const DAEMON = "daemon"
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{
|
||||
Configs: map[string]*ice.Config{
|
||||
DAEMON: {Name: DAEMON, Help: "守护进程", Value: kit.Data(kit.MDB_PATH, "usr/local/daemon")},
|
||||
DAEMON: {Name: DAEMON, Help: "守护进程", Value: kit.Data(kit.MDB_PATH, path.Join(ice.USR_LOCAL, DAEMON))},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
}},
|
||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
list := []string{}
|
||||
m.Richs(DAEMON, "", kit.MDB_FOREACH, func(key string, value map[string]interface{}) {
|
||||
if value = kit.GetMeta(value); kit.Value(value, mdb.CACHE_CLEAR_ON_EXIT) == ice.TRUE {
|
||||
list = append(list, key)
|
||||
}
|
||||
})
|
||||
for _, k := range list {
|
||||
m.Conf(DAEMON, kit.Keys(kit.MDB_HASH, k), "")
|
||||
}
|
||||
}},
|
||||
|
||||
DAEMON: {Name: "daemon hash auto start prunes", Help: "守护进程", Action: map[string]*ice.Action{
|
||||
RESTART: {Name: "restart", Help: "重启", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(DAEMON, STOP)
|
||||
@ -98,9 +113,9 @@ func init() {
|
||||
}},
|
||||
START: {Name: "start cmd env dir", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Option(CMD_TYPE, DAEMON)
|
||||
m.Option(CMD_DIR, m.Option("dir"))
|
||||
m.Option(CMD_ENV, kit.Split(m.Option("env"), " ="))
|
||||
m.Cmdy(SYSTEM, kit.Split(m.Option("cmd")))
|
||||
m.Option(CMD_DIR, m.Option(DIR))
|
||||
m.Option(CMD_ENV, kit.Split(m.Option(ENV), " ="))
|
||||
m.Cmdy(SYSTEM, kit.Split(m.Option(CMD)))
|
||||
}},
|
||||
STOP: {Name: "stop", Help: "停止", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Option(mdb.FIELDS, "time,hash,status,pid,cmd,dir,env")
|
||||
@ -118,8 +133,8 @@ func init() {
|
||||
m.Cmdy(mdb.PRUNES, DAEMON, "", mdb.HASH, kit.MDB_STATUS, Status.Stop)
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
m.Option(mdb.FIELDS, "time,hash,status,pid,cmd,dir,env")
|
||||
if len(arg) == 0 { // 进程列表
|
||||
m.Fields(len(arg) == 0, "time,hash,status,pid,cmd,dir,env")
|
||||
m.Cmdy(mdb.SELECT, DAEMON, "", mdb.HASH)
|
||||
m.Table(func(index int, value map[string]string, head []string) {
|
||||
switch value[kit.MDB_STATUS] {
|
||||
@ -130,11 +145,11 @@ func init() {
|
||||
}
|
||||
})
|
||||
|
||||
} else if m.Richs(DAEMON, "", arg[0], nil) != nil {
|
||||
} else if m.Richs(DAEMON, "", arg[0], nil) != nil { // 进程详情
|
||||
m.Option(mdb.FIELDS, mdb.DETAIL)
|
||||
m.Cmdy(mdb.SELECT, DAEMON, "", mdb.HASH, kit.MDB_HASH, arg)
|
||||
|
||||
} else {
|
||||
} else { // 启动进程
|
||||
m.Option(CMD_TYPE, DAEMON)
|
||||
m.Cmdy(SYSTEM, arg)
|
||||
}
|
||||
|
@ -1,125 +0,0 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
|
||||
"io"
|
||||
)
|
||||
|
||||
func _cli_progress(m *ice.Message, cb interface{}) {
|
||||
m.Option(mdb.FIELDS, "time,name,step,count,total")
|
||||
if m.Option(ice.MSG_PROCESS, "_progress"); m.Option("_progress") != "" {
|
||||
m.Cmdy(mdb.SELECT, PROGRESS, "", mdb.HASH, kit.MDB_HASH, m.Option("_progress"))
|
||||
if len(m.Appendv(kit.MDB_TIME)) > 0 {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
h := m.Cmdx(mdb.INSERT, PROGRESS, "", mdb.HASH, "step", 0, "count", 0, "total", 1)
|
||||
m.Cmdy(mdb.SELECT, PROGRESS, "", mdb.HASH, kit.MDB_HASH, m.Option("_progress", h))
|
||||
|
||||
m.Go(func() {
|
||||
switch cb := cb.(type) {
|
||||
case func(cb func(name string, count, total int)):
|
||||
cb(func(name string, count, total int) {
|
||||
m.Debug("what %v", name)
|
||||
m.Cmd(mdb.MODIFY, PROGRESS, "", mdb.HASH, kit.MDB_HASH, h, "name", name,
|
||||
"step", count*100/total, "count", count, "total", total)
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
func Follow(m *ice.Message, action string, cb func()) bool {
|
||||
m.Option(ice.MSG_PROCESS, "_follow")
|
||||
if m.Option(mdb.CACHE_ACTION, action); m.Option(mdb.CACHE_HASH) != "" {
|
||||
m.Cmdy(OUTPUT, m.Option(mdb.CACHE_HASH))
|
||||
m.Sort(kit.MDB_ID).Table(func(index int, value map[string]string, head []string) {
|
||||
m.Option(mdb.CACHE_BEGIN, value[kit.MDB_ID])
|
||||
m.Echo(value[kit.SSH_RES])
|
||||
})
|
||||
|
||||
if len(m.Resultv()) == 0 && m.Conf(OUTPUT, kit.Keys(kit.MDB_HASH, m.Option(mdb.CACHE_HASH), kit.MDB_META, kit.MDB_STATUS)) == STOP {
|
||||
m.Option(mdb.CACHE_STATUS, STOP)
|
||||
}
|
||||
return true
|
||||
}
|
||||
m.Cmdy(OUTPUT, mdb.CREATE, kit.MDB_NAME, m.Option(kit.MDB_LINK))
|
||||
m.Option(mdb.CACHE_HASH, m.Result())
|
||||
m.Option(mdb.CACHE_BEGIN, 1)
|
||||
m.Set(ice.MSG_RESULT)
|
||||
m.Go(cb)
|
||||
return false
|
||||
}
|
||||
|
||||
const (
|
||||
PROGRESS_CB = "progress.cb"
|
||||
)
|
||||
|
||||
const PROGRESS = "progress"
|
||||
|
||||
const OUTPUT = "output"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{
|
||||
Configs: map[string]*ice.Config{
|
||||
OUTPUT: {Name: OUTPUT, Help: "输出", Value: kit.Data()},
|
||||
PROGRESS: {Name: PROGRESS, Help: "进度", Value: kit.Data()},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
PROGRESS: {Name: "progress hash auto", Help: "进度", Action: map[string]*ice.Action{
|
||||
mdb.CREATE: {Name: "create", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||
_cli_progress(m, m.Optionv(PROGRESS_CB))
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Option(mdb.FIELDS, kit.Select("time,name,step,count,total", mdb.DETAIL, len(arg) > 0))
|
||||
m.Cmdy(mdb.SELECT, PROGRESS, "", mdb.HASH, kit.MDB_HASH, arg)
|
||||
m.SortInt("step")
|
||||
}},
|
||||
|
||||
OUTPUT: {Name: "output hash id auto", Help: "输出", Action: map[string]*ice.Action{
|
||||
mdb.CREATE: {Name: "create cmd", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||
h := m.Cmdx(mdb.INSERT, OUTPUT, "", mdb.HASH, kit.MDB_STATUS, Status.Start, arg)
|
||||
r, w := io.Pipe()
|
||||
m.Go(func() {
|
||||
buf := make([]byte, 1024)
|
||||
for {
|
||||
if n, e := r.Read(buf); e != nil || n == 0 {
|
||||
break
|
||||
} else {
|
||||
m.Grow(OUTPUT, kit.Keys(kit.MDB_HASH, h), kit.Dict(
|
||||
kit.SSH_RES, string(buf[:n]),
|
||||
))
|
||||
}
|
||||
}
|
||||
m.Cmd(mdb.MODIFY, OUTPUT, "", mdb.HASH, kit.MDB_HASH, h, kit.MDB_STATUS, Status.Stop)
|
||||
})
|
||||
m.Option(OUTPUT, w)
|
||||
m.Echo(h)
|
||||
}},
|
||||
mdb.MODIFY: {Name: "modify", Help: "编辑", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(mdb.MODIFY, OUTPUT, "", mdb.HASH, kit.MDB_HASH, m.Option(kit.MDB_HASH), arg)
|
||||
}},
|
||||
mdb.REMOVE: {Name: "remove", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(mdb.DELETE, OUTPUT, "", mdb.HASH, kit.MDB_HASH, m.Option(kit.MDB_HASH))
|
||||
}},
|
||||
mdb.PRUNES: {Name: "prunes", Help: "清理", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(mdb.PRUNES, OUTPUT, "", mdb.HASH, kit.MDB_STATUS, Status.Stop)
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
m.Option(mdb.FIELDS, "time,hash,status,name")
|
||||
m.Cmdy(mdb.SELECT, OUTPUT, "", mdb.HASH)
|
||||
m.PushAction(mdb.REMOVE)
|
||||
return
|
||||
}
|
||||
|
||||
m.Option(ice.MSG_CONTROL, "_page")
|
||||
m.Option(mdb.FIELDS, kit.Select("time,id,res", mdb.DETAIL, len(arg) > 1))
|
||||
m.Cmdy(mdb.SELECT, OUTPUT, kit.Keys(kit.MDB_HASH, arg[0]), mdb.LIST, kit.MDB_ID, arg[1:])
|
||||
m.Sort(kit.MDB_ID)
|
||||
}},
|
||||
},
|
||||
})
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
ice "github.com/shylinux/icebergs"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{
|
||||
Commands: map[string]*ice.Command{
|
||||
"proc": {Name: "proc name=ice.bin PID auto", Help: "进程管理", Action: map[string]*ice.Action{
|
||||
"kill": {Name: "kill", Help: "结束", Hand: func(m *ice.Message, arg ...string) {
|
||||
if p, e := os.FindProcess(kit.Int(m.Option("PID"))); m.Assert(e) {
|
||||
m.Assert(p.Kill())
|
||||
}
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
msg := m.Spawn()
|
||||
msg.Split(m.Cmdx(SYSTEM, "ps", "ux"), "", " ", "\n")
|
||||
msg.Table(func(index int, value map[string]string, head []string) {
|
||||
if m.Appendv(ice.MSG_APPEND, "action", head); len(arg) > 1 && value["PID"] != arg[1] {
|
||||
return
|
||||
}
|
||||
if len(arg) > 0 && !strings.Contains(value["COMMAND"], arg[0]) {
|
||||
return
|
||||
}
|
||||
m.PushButton("kill")
|
||||
m.Push("", value)
|
||||
})
|
||||
}},
|
||||
},
|
||||
})
|
||||
}
|
@ -1,48 +1,95 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
qrcodeTerminal "github.com/Baozisoftware/qrcode-terminal-go"
|
||||
"github.com/skip2/go-qrcode"
|
||||
"image/color"
|
||||
"math/rand"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/aaa"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
)
|
||||
|
||||
func _qrcode_cli(m *ice.Message, arg ...string) {
|
||||
fg := qrcodeTerminal.ConsoleColors.BrightBlue
|
||||
bg := qrcodeTerminal.ConsoleColors.BrightWhite
|
||||
switch m.Option("fg") {
|
||||
case "black":
|
||||
fg = qrcodeTerminal.ConsoleColors.BrightBlack
|
||||
case "red":
|
||||
fg = qrcodeTerminal.ConsoleColors.BrightRed
|
||||
case "green":
|
||||
fg = qrcodeTerminal.ConsoleColors.BrightGreen
|
||||
case "yellow":
|
||||
fg = qrcodeTerminal.ConsoleColors.BrightYellow
|
||||
case "blue":
|
||||
fg = qrcodeTerminal.ConsoleColors.BrightBlue
|
||||
case "cyan":
|
||||
fg = qrcodeTerminal.ConsoleColors.BrightCyan
|
||||
case "magenta":
|
||||
fg = qrcodeTerminal.ConsoleColors.BrightMagenta
|
||||
case "white":
|
||||
fg = qrcodeTerminal.ConsoleColors.BrightWhite
|
||||
}
|
||||
obj := qrcodeTerminal.New2(fg, bg, qrcodeTerminal.QRCodeRecoveryLevels.Medium)
|
||||
m.Echo("%s", *obj.Get(arg[0]))
|
||||
var _trans_web = map[string]color.Color{
|
||||
"black": color.RGBA{0, 0, 0, 255},
|
||||
"red": color.RGBA{255, 0, 0, 255},
|
||||
"green": color.RGBA{0, 255, 0, 255},
|
||||
"yellow": color.RGBA{255, 255, 0, 255},
|
||||
"blue": color.RGBA{0, 0, 255, 255},
|
||||
"magenta": color.RGBA{255, 0, 255, 255},
|
||||
"cyan": color.RGBA{0, 255, 255, 255},
|
||||
"white": color.RGBA{255, 255, 255, 255},
|
||||
}
|
||||
func _qrcode_web(m *ice.Message, arg ...string) {
|
||||
buf := bytes.NewBuffer(make([]byte, 0, ice.MOD_BUFS))
|
||||
if qr, e := qrcode.New(arg[0], qrcode.Medium); m.Assert(e) {
|
||||
m.Assert(qr.Write(kit.Int(kit.Select("240", arg, 1)), buf))
|
||||
|
||||
func _parse_color(str string) color.Color {
|
||||
if str == "random" {
|
||||
list := []string{}
|
||||
for k := range _trans_web {
|
||||
list = append(list, k)
|
||||
}
|
||||
str = list[rand.Intn(len(list))]
|
||||
}
|
||||
if strings.HasPrefix(str, "#") {
|
||||
if len(str) == 7 {
|
||||
str += "ff"
|
||||
}
|
||||
if u, e := strconv.ParseUint(str[1:], 16, 64); e == nil {
|
||||
return color.RGBA{
|
||||
uint8((u & 0xFF000000) >> 24),
|
||||
uint8((u & 0x00FF0000) >> 16),
|
||||
uint8((u & 0x0000FF00) >> 8),
|
||||
uint8((u & 0x000000FF) >> 0),
|
||||
}
|
||||
}
|
||||
}
|
||||
return _trans_web[str]
|
||||
}
|
||||
func _trans_cli(str string) string {
|
||||
res := 0
|
||||
r, g, b, _ := _parse_color(str).RGBA()
|
||||
if r > 128 {
|
||||
res += 1
|
||||
}
|
||||
if g > 128 {
|
||||
res += 2
|
||||
}
|
||||
if b > 128 {
|
||||
res += 4
|
||||
}
|
||||
return kit.Format(res)
|
||||
}
|
||||
|
||||
func _qrcode_cli(m *ice.Message, text string, arg ...string) {
|
||||
qr, _ := qrcode.New(text, qrcode.Medium)
|
||||
fg := _trans_cli(m.Option("fg"))
|
||||
bg := _trans_cli(m.Option("bg"))
|
||||
|
||||
data := qr.Bitmap()
|
||||
for i, row := range data {
|
||||
if n := len(data); i < 3 || i >= n-3 {
|
||||
continue
|
||||
}
|
||||
for i, col := range row {
|
||||
if n := len(row); i < 3 || i >= n-3 {
|
||||
continue
|
||||
}
|
||||
|
||||
m.Echo("\033[4%sm \033[0m", kit.Select(bg, fg, col))
|
||||
}
|
||||
m.Echo("\n")
|
||||
}
|
||||
}
|
||||
func _qrcode_web(m *ice.Message, text string, arg ...string) {
|
||||
qr, _ := qrcode.New(text, qrcode.Medium)
|
||||
qr.ForegroundColor = _parse_color(m.Option("fg"))
|
||||
qr.BackgroundColor = _parse_color(m.Option("bg"))
|
||||
|
||||
if data, err := qr.PNG(kit.Int(m.Option("size"))); m.Assert(err) {
|
||||
m.Echo(`<img src="data:image/png;base64,%s" title='%s'>`, base64.StdEncoding.EncodeToString(data), text)
|
||||
}
|
||||
m.Option("byte", buf.Bytes())
|
||||
data := base64.StdEncoding.EncodeToString(buf.Bytes())
|
||||
m.Echo(`<img src="data:image/png;base64,%s" title='%s' height=%s>`, data, arg[0], kit.Select("240", arg, 1))
|
||||
}
|
||||
|
||||
const QRCODE = "qrcode"
|
||||
@ -53,12 +100,16 @@ func init() {
|
||||
QRCODE: {Name: "qrcode", Help: "二维码", Value: kit.Data()},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
QRCODE: {Name: "qrcode text auto", Help: "二维码", Action: map[string]*ice.Action{}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
QRCODE: {Name: "qrcode text fg bg size auto", Help: "二维码", Action: map[string]*ice.Action{}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Option("fg", kit.Select("blue", arg, 1))
|
||||
m.Option("bg", kit.Select("white", arg, 2))
|
||||
m.Option("size", kit.Select("240", arg, 3))
|
||||
|
||||
if aaa.SessIsCli(m) {
|
||||
_qrcode_cli(m, arg...)
|
||||
return
|
||||
_qrcode_cli(m, arg[0])
|
||||
} else {
|
||||
_qrcode_web(m, arg[0])
|
||||
}
|
||||
_qrcode_web(m, arg...)
|
||||
}},
|
||||
},
|
||||
})
|
||||
|
@ -1,16 +1,25 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/ctx"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/ctx"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
)
|
||||
|
||||
const (
|
||||
DISKINFO = "diskinfo"
|
||||
IFCONFIG = "ifconfig"
|
||||
HOSTNAME = "hostname"
|
||||
HOSTINFO = "hostinfo"
|
||||
USERINFO = "userinfo"
|
||||
PROCINFO = "procinfo"
|
||||
BOOTINFO = "bootinfo"
|
||||
)
|
||||
const RUNTIME = "runtime"
|
||||
|
||||
func init() {
|
||||
@ -19,11 +28,26 @@ func init() {
|
||||
RUNTIME: {Name: RUNTIME, Help: "运行环境", Value: kit.Dict()},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
RUNTIME: {Name: "runtime info=procinfo,hostinfo,diskinfo,ifconfig,hostname,userinfo,bootinfo auto", Help: "运行环境", Action: map[string]*ice.Action{
|
||||
"procinfo": {Name: "procinfo", Help: "procinfo", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Split(m.Cmdx(SYSTEM, "ps", "u"), "", " ", "\n")
|
||||
RUNTIME: {Name: "runtime info=diskinfo,ifconfig,hostname,hostinfo,userinfo,procinfo,bootinfo auto", Help: "运行环境", Action: map[string]*ice.Action{
|
||||
DISKINFO: {Name: "diskinfo", Help: "磁盘信息", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Spawn().Split(m.Cmdx(SYSTEM, "df", "-h"), "", " ", "\n").Table(func(index int, value map[string]string, head []string) {
|
||||
if strings.HasPrefix(value["Filesystem"], "/dev") {
|
||||
m.Push("", value, head)
|
||||
}
|
||||
})
|
||||
}},
|
||||
"hostinfo": {Name: "hostinfo", Help: "hostinfo", Hand: func(m *ice.Message, arg ...string) {
|
||||
IFCONFIG: {Name: "ifconfig", Help: "网卡配置", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy("tcp.host")
|
||||
}},
|
||||
HOSTNAME: {Name: "hostname", Help: "主机域名", Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) > 0 {
|
||||
m.Conf(RUNTIME, "boot.hostname", arg[0])
|
||||
m.Conf(RUNTIME, "node.name", arg[0])
|
||||
ice.Info.HostName = arg[0]
|
||||
}
|
||||
m.Echo(ice.Info.HostName)
|
||||
}},
|
||||
HOSTINFO: {Name: "hostinfo", Help: "主机信息", Hand: func(m *ice.Message, arg ...string) {
|
||||
if f, e := os.Open("/proc/cpuinfo"); e == nil {
|
||||
defer f.Close()
|
||||
if b, e := ioutil.ReadAll(f); e == nil {
|
||||
@ -44,29 +68,14 @@ func init() {
|
||||
}
|
||||
m.Push("uptime", kit.Split(m.Cmdx(SYSTEM, "uptime"), ",")[0])
|
||||
}},
|
||||
"diskinfo": {Name: "diskinfo", Help: "diskinfo", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Spawn().Split(m.Cmdx(SYSTEM, "df", "-h"), "", " ", "\n").Table(func(index int, value map[string]string, head []string) {
|
||||
if strings.HasPrefix(value["Filesystem"], "/dev") {
|
||||
m.Push("", value, head)
|
||||
}
|
||||
})
|
||||
}},
|
||||
"ifconfig": {Name: "ifconfig", Help: "ifconfig", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy("tcp.host")
|
||||
}},
|
||||
"hostname": {Name: "hostname", Help: "hostname", Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) > 0 {
|
||||
m.Conf(RUNTIME, "boot.hostname", arg[0])
|
||||
m.Conf(RUNTIME, "node.name", arg[0])
|
||||
ice.Info.HostName = arg[0]
|
||||
}
|
||||
m.Echo(ice.Info.HostName)
|
||||
}},
|
||||
"userinfo": {Name: "userinfo", Help: "userinfo", Hand: func(m *ice.Message, arg ...string) {
|
||||
USERINFO: {Name: "userinfo", Help: "用户信息", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Split(m.Cmdx(SYSTEM, "who"), "user term time", " ", "\n")
|
||||
}},
|
||||
PROCINFO: {Name: "procinfo", Help: "进程信息", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Split(m.Cmdx(SYSTEM, "ps", "u"), "", " ", "\n")
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if len(arg) > 0 && arg[0] == "bootinfo" {
|
||||
if len(arg) > 0 && arg[0] == BOOTINFO {
|
||||
arg = arg[1:]
|
||||
}
|
||||
m.Cmdy(ctx.CONFIG, RUNTIME, arg)
|
||||
|
@ -1 +0,0 @@
|
||||
package cli
|
@ -6,72 +6,59 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
)
|
||||
|
||||
func _system_show(m *ice.Message, cmd *exec.Cmd) {
|
||||
// 输入流
|
||||
if r, ok := m.Optionv(CMD_INPUT).(io.Reader); ok {
|
||||
cmd.Stdin = r
|
||||
}
|
||||
|
||||
if w, ok := m.Optionv(CMD_OUTPUT).(io.WriteCloser); ok {
|
||||
cmd.Stdout = w
|
||||
cmd.Stderr = w
|
||||
if w, ok := m.Optionv(CMD_ERRPUT).(io.WriteCloser); ok {
|
||||
// 输出流
|
||||
if w, ok := m.Optionv(CMD_OUTPUT).(io.Writer); ok {
|
||||
cmd.Stdout, cmd.Stderr = w, w
|
||||
if w, ok := m.Optionv(CMD_ERRPUT).(io.Writer); ok {
|
||||
cmd.Stderr = w
|
||||
}
|
||||
|
||||
if e := cmd.Run(); e != nil {
|
||||
m.Warn(e != nil, ErrRun, strings.Join(cmd.Args, " "), "\n", e.Error())
|
||||
m.Push(CMD_ERR, e.Error())
|
||||
} else {
|
||||
m.Cost("args", cmd.Args, "code", cmd.ProcessState.ExitCode())
|
||||
}
|
||||
} else {
|
||||
out := bytes.NewBuffer(make([]byte, 0, 1024))
|
||||
err := bytes.NewBuffer(make([]byte, 0, 1024))
|
||||
defer func() {
|
||||
m.Push(CMD_ERR, err.String())
|
||||
m.Push(CMD_OUT, out.String())
|
||||
m.Echo(kit.Select(err.String(), out.String()))
|
||||
m.Echo(kit.Select(out.String(), err.String()))
|
||||
}()
|
||||
|
||||
cmd.Stdout = out
|
||||
cmd.Stderr = err
|
||||
cmd.Stdout, cmd.Stderr = out, err
|
||||
}
|
||||
|
||||
if e := cmd.Run(); e != nil {
|
||||
m.Warn(e != nil, ErrRun, strings.Join(cmd.Args, " "), "\n", kit.Select(e.Error(), err.String()))
|
||||
fmt.Fprintf(err, e.Error())
|
||||
} else {
|
||||
m.Cost("args", cmd.Args, "code", cmd.ProcessState.ExitCode(), "err", err.Len(), "out", out.Len())
|
||||
}
|
||||
// 执行命令
|
||||
if e := cmd.Run(); e != nil {
|
||||
m.Warn(e != nil, cmd.Args, " ", e.Error())
|
||||
} else {
|
||||
m.Cost("code", cmd.ProcessState.ExitCode(), "args", cmd.Args)
|
||||
}
|
||||
|
||||
m.Push(kit.MDB_TIME, m.Time())
|
||||
m.Push(CMD_CODE, int(cmd.ProcessState.ExitCode()))
|
||||
}
|
||||
|
||||
const ErrRun = "cli run err: "
|
||||
|
||||
const (
|
||||
CMD_DIR = "cmd_dir"
|
||||
CMD_ENV = "cmd_env"
|
||||
CMD_TYPE = "cmd_type"
|
||||
|
||||
CMD_INPUT = "cmd_input"
|
||||
CMD_OUTPUT = "cmd_output"
|
||||
CMD_ERRPUT = "cmd_errput"
|
||||
|
||||
CMD_STDERR = "cmd_stderr"
|
||||
CMD_STDOUT = "cmd_stdout"
|
||||
|
||||
CMD_TYPE = "cmd_type"
|
||||
CMD_DIR = "cmd_dir"
|
||||
CMD_ENV = "cmd_env"
|
||||
|
||||
CMD_OUT = "cmd_out"
|
||||
CMD_ERR = "cmd_err"
|
||||
CMD_CODE = "cmd_code"
|
||||
CMD_ERR = "cmd_err"
|
||||
CMD_OUT = "cmd_out"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -90,15 +77,7 @@ func init() {
|
||||
SYSTEM: {Name: SYSTEM, Help: "系统命令", Value: kit.Data()},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
SYSTEM: {Name: "system id auto", Help: "系统命令", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
|
||||
|
||||
if len(arg) == 0 || kit.Int(arg[0]) > 0 {
|
||||
m.Option("_control", "_page")
|
||||
m.Option(mdb.FIELDS, kit.Select("time,id,cmd,dir,env", mdb.DETAIL, len(arg) > 0))
|
||||
m.Cmdy(mdb.SELECT, SYSTEM, "", mdb.LIST, kit.MDB_ID, arg)
|
||||
return
|
||||
}
|
||||
|
||||
SYSTEM: {Name: "system cmd= 执行:button", Help: "系统命令", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
|
||||
if len(arg) == 1 {
|
||||
arg = kit.Split(arg[0])
|
||||
}
|
||||
@ -123,7 +102,7 @@ func init() {
|
||||
|
||||
switch m.Option(CMD_TYPE) {
|
||||
case DAEMON:
|
||||
_daemon_show(m, cmd, m.Option(CMD_STDOUT), m.Option(CMD_STDERR))
|
||||
_daemon_show(m, cmd, m.Option(CMD_OUTPUT), m.Option(CMD_ERRPUT))
|
||||
default:
|
||||
_system_show(m, cmd)
|
||||
}
|
||||
|
@ -39,8 +39,8 @@ func _command_search(m *ice.Message, kind, name, text string) {
|
||||
return
|
||||
}
|
||||
|
||||
m.PushSearch(kit.SSH_CMD, COMMAND, CONTEXT, s.Cap(ice.CTX_FOLLOW), COMMAND, key,
|
||||
kit.MDB_TYPE, kind, kit.MDB_NAME, key, kit.MDB_TEXT, s.Cap(ice.CTX_FOLLOW),
|
||||
m.PushSearch(kit.SSH_CMD, COMMAND, CONTEXT, m.Prefix(), COMMAND, key,
|
||||
kit.MDB_TYPE, kind, kit.MDB_NAME, key, kit.MDB_TEXT, m.Prefix(),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
package log
|
||||
|
||||
import (
|
||||
ice "github.com/shylinux/icebergs"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
|
||||
"bufio"
|
||||
"path"
|
||||
|
||||
ice "github.com/shylinux/icebergs"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
)
|
||||
|
||||
type Log struct {
|
||||
@ -35,19 +35,19 @@ func (f *Frame) Start(m *ice.Message, arg ...string) bool {
|
||||
break
|
||||
}
|
||||
|
||||
file := kit.Select("bench", m.Conf("show", kit.Keys(l.l, "file")))
|
||||
view := m.Confm("view", m.Conf("show", kit.Keys(l.l, "view")))
|
||||
bio := m.Confv("file", file+".file").(*bufio.Writer)
|
||||
file := kit.Select(BENCH, m.Conf(SHOW, kit.Keys(l.l, FILE)))
|
||||
view := m.Confm(VIEW, m.Conf(SHOW, kit.Keys(l.l, VIEW)))
|
||||
bio := m.Confv(FILE, kit.Keys(file, FILE)).(*bufio.Writer)
|
||||
|
||||
bio.WriteString(l.p)
|
||||
bio.WriteString(" ")
|
||||
if p, ok := view["prefix"].(string); ok {
|
||||
if p, ok := view[PREFIX].(string); ok {
|
||||
bio.WriteString(p)
|
||||
}
|
||||
bio.WriteString(l.l)
|
||||
bio.WriteString(" ")
|
||||
bio.WriteString(l.s)
|
||||
if p, ok := view["suffix"].(string); ok {
|
||||
if p, ok := view[SUFFIX].(string); ok {
|
||||
bio.WriteString(p)
|
||||
}
|
||||
bio.WriteString("\n")
|
||||
@ -60,50 +60,71 @@ func (f *Frame) Close(m *ice.Message, arg ...string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
const (
|
||||
PREFIX = "prefix"
|
||||
SUFFIX = "suffix"
|
||||
)
|
||||
const (
|
||||
GREEN = "green"
|
||||
YELLOW = "yellow"
|
||||
RED = "red"
|
||||
)
|
||||
const (
|
||||
WATCH = "watch"
|
||||
BENCH = "bench"
|
||||
ERROR = "error"
|
||||
TRACE = "trace"
|
||||
)
|
||||
const (
|
||||
FILE = "file"
|
||||
VIEW = "view"
|
||||
SHOW = "show"
|
||||
)
|
||||
|
||||
var Index = &ice.Context{Name: "log", Help: "日志模块",
|
||||
Configs: map[string]*ice.Config{
|
||||
"file": {Name: "file", Help: "日志文件", Value: kit.Dict(
|
||||
"watch", kit.Dict("path", "var/log/watch.log", "list", []string{
|
||||
FILE: {Name: FILE, Help: "日志文件", Value: kit.Dict(
|
||||
WATCH, kit.Dict(kit.MDB_PATH, path.Join(ice.VAR_LOG, "watch.log"), kit.MDB_LIST, []string{
|
||||
ice.LOG_CREATE, ice.LOG_REMOVE,
|
||||
ice.LOG_INSERT, ice.LOG_DELETE,
|
||||
ice.LOG_SELECT, ice.LOG_MODIFY,
|
||||
ice.LOG_EXPORT, ice.LOG_IMPORT,
|
||||
}),
|
||||
"bench", kit.Dict("path", "var/log/bench.log", "list", []string{}),
|
||||
"error", kit.Dict("path", "var/log/error.log", "list", []string{
|
||||
BENCH, kit.Dict(kit.MDB_PATH, path.Join(ice.VAR_LOG, "bench.log"), kit.MDB_LIST, []string{}),
|
||||
ERROR, kit.Dict(kit.MDB_PATH, path.Join(ice.VAR_LOG, "error.log"), kit.MDB_LIST, []string{
|
||||
ice.LOG_WARN, ice.LOG_ERROR,
|
||||
}),
|
||||
"trace", kit.Dict("path", "var/log/trace.log", "list", []string{}),
|
||||
TRACE, kit.Dict(kit.MDB_PATH, path.Join(ice.VAR_LOG, "trace.log"), kit.MDB_LIST, []string{}),
|
||||
)},
|
||||
"view": {Name: "view", Help: "日志格式", Value: kit.Dict(
|
||||
"green", kit.Dict("prefix", "\033[32m", "suffix", "\033[0m", "list", []string{
|
||||
VIEW: {Name: VIEW, Help: "日志格式", Value: kit.Dict(
|
||||
GREEN, kit.Dict(PREFIX, "\033[32m", SUFFIX, "\033[0m", kit.MDB_LIST, []string{
|
||||
ice.LOG_START, ice.LOG_SERVE,
|
||||
ice.LOG_CMDS,
|
||||
}),
|
||||
"yellow", kit.Dict("prefix", "\033[33m", "suffix", "\033[0m", "list", []string{
|
||||
YELLOW, kit.Dict(PREFIX, "\033[33m", SUFFIX, "\033[0m", kit.MDB_LIST, []string{
|
||||
ice.LOG_AUTH, ice.LOG_COST,
|
||||
}),
|
||||
"red", kit.Dict("prefix", "\033[31m", "suffix", "\033[0m", "list", []string{
|
||||
RED, kit.Dict(PREFIX, "\033[31m", SUFFIX, "\033[0m", kit.MDB_LIST, []string{
|
||||
ice.LOG_WARN, ice.LOG_CLOSE,
|
||||
}),
|
||||
)},
|
||||
"show": {Name: "show", Help: "日志分流", Value: kit.Dict()},
|
||||
SHOW: {Name: SHOW, Help: "日志分流", Value: kit.Dict()},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Confm("view", nil, func(key string, value map[string]interface{}) {
|
||||
kit.Fetch(value["list"], func(index int, k string) {
|
||||
m.Conf("show", kit.Keys(k, "view"), key)
|
||||
m.Confm(VIEW, nil, func(key string, value map[string]interface{}) {
|
||||
kit.Fetch(value[kit.MDB_LIST], func(index int, k string) {
|
||||
m.Conf(SHOW, kit.Keys(k, VIEW), key)
|
||||
})
|
||||
})
|
||||
m.Confm("file", nil, func(key string, value map[string]interface{}) {
|
||||
kit.Fetch(value["list"], func(index int, k string) {
|
||||
m.Conf("show", kit.Keys(k, "file"), key)
|
||||
m.Confm(FILE, nil, func(key string, value map[string]interface{}) {
|
||||
kit.Fetch(value[kit.MDB_LIST], func(index int, k string) {
|
||||
m.Conf(SHOW, kit.Keys(k, FILE), key)
|
||||
})
|
||||
// 日志文件
|
||||
if f, p, e := kit.Create(kit.Format(value["path"])); m.Assert(e) {
|
||||
if f, p, e := kit.Create(kit.Format(value[kit.MDB_PATH])); m.Assert(e) {
|
||||
m.Cap(ice.CTX_STREAM, path.Base(p))
|
||||
value["file"] = bufio.NewWriter(f)
|
||||
value[FILE] = bufio.NewWriter(f)
|
||||
m.Log_CREATE(kit.MDB_FILE, p)
|
||||
}
|
||||
})
|
||||
|
@ -1,16 +1,16 @@
|
||||
package nfs
|
||||
|
||||
import (
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/aaa"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
|
||||
"bufio"
|
||||
"bytes"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/aaa"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
)
|
||||
|
||||
func _cat_ext(name string) string {
|
||||
|
@ -155,8 +155,8 @@ func Dir(m *ice.Message, sort string) {
|
||||
|
||||
const (
|
||||
TYPE_ALL = "all"
|
||||
TYPE_DIR = "dir"
|
||||
TYPE_CAT = "cat"
|
||||
TYPE_DIR = "dir"
|
||||
TYPE_BOTH = "both"
|
||||
)
|
||||
const (
|
||||
@ -185,9 +185,9 @@ func init() {
|
||||
mdb.UPLOAD: {Name: "upload", Help: "上传", Hand: func(m *ice.Message, arg ...string) {
|
||||
up := kit.Simple(m.Optionv(ice.MSG_UPLOAD))
|
||||
if p := path.Join(m.Option(kit.MDB_PATH), up[1]); m.Option(ice.MSG_USERPOD) == "" {
|
||||
m.Cmdy("cache", "watch", up[0], p)
|
||||
m.Cmdy("web.cache", "watch", up[0], p)
|
||||
} else {
|
||||
m.Cmdy("spide", "dev", "save", p, "GET", kit.MergeURL2(m.Option(ice.MSG_USERWEB), "/share/cache/"+up[0]))
|
||||
m.Cmdy("web.spide", "dev", "save", p, "GET", kit.MergeURL2(m.Option(ice.MSG_USERWEB), "/share/cache/"+up[0]))
|
||||
}
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
|
@ -1,13 +1,13 @@
|
||||
package nfs
|
||||
|
||||
import (
|
||||
ice "github.com/shylinux/icebergs"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
|
||||
"io"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
ice "github.com/shylinux/icebergs"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
)
|
||||
|
||||
func _save_file(m *ice.Message, name string, text ...string) {
|
||||
|
@ -1,13 +1,13 @@
|
||||
package nfs
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"io"
|
||||
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/cli"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
|
||||
"bufio"
|
||||
"io"
|
||||
)
|
||||
|
||||
func _tail_create(m *ice.Message, arg ...string) {
|
||||
@ -26,8 +26,8 @@ func _tail_create(m *ice.Message, arg ...string) {
|
||||
}
|
||||
})
|
||||
|
||||
m.Option(cli.CMD_STDOUT, w)
|
||||
m.Option(cli.CMD_STDERR, w)
|
||||
m.Option(cli.CMD_OUTPUT, w)
|
||||
m.Option(cli.CMD_ERRPUT, w)
|
||||
m.Option(mdb.CACHE_CLEAR_ON_EXIT, "true")
|
||||
m.Cmd(cli.DAEMON, TAIL, "-n", "0", "-f", file)
|
||||
})
|
||||
@ -38,23 +38,41 @@ const TAIL = "tail"
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{
|
||||
Configs: map[string]*ice.Config{
|
||||
TAIL: {Name: TAIL, Help: "跟踪", Value: kit.Data()},
|
||||
TAIL: {Name: TAIL, Help: "日志流", Value: kit.Data()},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
TAIL: {Name: "tail hash id auto create", Help: "跟踪", Action: map[string]*ice.Action{
|
||||
TAIL: {Name: "tail hash id limit offend auto prev next create", Help: "日志流", Action: map[string]*ice.Action{
|
||||
mdb.CREATE: {Name: "create file name", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||
_tail_create(m, arg...)
|
||||
}},
|
||||
mdb.REMOVE: {Name: "remove", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(mdb.DELETE, TAIL, "", mdb.HASH, kit.MDB_HASH, m.Option(kit.MDB_HASH))
|
||||
}},
|
||||
"prev": {Name: "prev", Help: "上一页", Hand: func(m *ice.Message, arg ...string) {
|
||||
offend := kit.Int(kit.Select("0", arg, 3)) + kit.Int(kit.Select("10", arg, 2))
|
||||
total := kit.Int(m.Conf(TAIL, kit.Keys(kit.MDB_HASH, arg[0], kit.MDB_META, kit.MDB_COUNT)))
|
||||
if offend >= total {
|
||||
offend = total - kit.Int(kit.Select("10", arg, 2))
|
||||
m.Toast("已经是最后一页啦!")
|
||||
}
|
||||
|
||||
m.Process("_rewrite", "offend", offend)
|
||||
}},
|
||||
"next": {Name: "next", Help: "下一页", Hand: func(m *ice.Message, arg ...string) {
|
||||
offend := kit.Int(kit.Select("0", arg, 3)) - kit.Int(kit.Select("10", arg, 2))
|
||||
if offend < 0 {
|
||||
offend = 0
|
||||
m.Toast("已经是第一页啦!")
|
||||
}
|
||||
m.Process("_rewrite", "offend", offend)
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Option(mdb.FIELDS, kit.Select("time,hash,count,name,file", kit.Select("time,id,file,text", mdb.DETAIL, len(arg) > 1), len(arg) > 0))
|
||||
m.Option(mdb.FIELDS, kit.Select("time,hash,count,name,file", kit.Select("time,id,file,text", mdb.DETAIL, len(arg) > 1 && arg[1] != ""), len(arg) > 0))
|
||||
m.Option("cache.limit", kit.Select("10", arg, 2))
|
||||
m.Option("cache.offend", kit.Select("0", arg, 3))
|
||||
|
||||
if m.Cmdy(mdb.SELECT, TAIL, "", mdb.ZONE, arg); len(arg) == 0 {
|
||||
m.PushAction(mdb.REMOVE)
|
||||
} else if len(arg) == 1 {
|
||||
m.Option(ice.MSG_CONTROL, ice.CONTROL_PAGE)
|
||||
}
|
||||
}},
|
||||
},
|
||||
|
@ -1,13 +1,13 @@
|
||||
package nfs
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path"
|
||||
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/cli"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
|
||||
"os"
|
||||
"path"
|
||||
)
|
||||
|
||||
func _trash_create(m *ice.Message, name string) {
|
||||
@ -25,7 +25,7 @@ func _trash_create(m *ice.Message, name string) {
|
||||
p := path.Join(m.Conf(TRASH, kit.META_PATH), h[:2], h)
|
||||
os.MkdirAll(path.Dir(p), ice.MOD_DIR)
|
||||
os.Rename(name, p)
|
||||
m.Cmdy(mdb.INSERT, TRASH, "", mdb.LIST, kit.MDB_FILE, p, kit.MDB_FROM, name)
|
||||
m.Cmdy(mdb.INSERT, TRASH, "", mdb.HASH, kit.MDB_FILE, p, kit.MDB_FROM, name)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -35,17 +35,20 @@ const TRASH = "trash"
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{
|
||||
Configs: map[string]*ice.Config{
|
||||
TRASH: {Name: TRASH, Help: "删除", Value: kit.Data(kit.MDB_PATH, "var/trash")},
|
||||
TRASH: {Name: TRASH, Help: "回收站", Value: kit.Data(
|
||||
kit.MDB_SHORT, kit.MDB_FROM, kit.MDB_PATH, ice.VAR_TRASH,
|
||||
)},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
TRASH: {Name: "trash file auto", Help: "删除", Action: map[string]*ice.Action{
|
||||
TRASH: {Name: "trash file auto", Help: "回收站", Action: map[string]*ice.Action{
|
||||
"recover": {Name: "recover", Help: "恢复", Hand: func(m *ice.Message, arg ...string) {
|
||||
os.Rename(m.Option(kit.MDB_FILE), m.Option(kit.MDB_FROM))
|
||||
m.Cmd(mdb.DELETE, TRASH, "", mdb.HASH, kit.MDB_HASH, m.Option(kit.MDB_HASH))
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
m.Option(mdb.FIELDS, "time,id,file,from")
|
||||
m.Cmdy(mdb.SELECT, TRASH, "", mdb.LIST)
|
||||
m.Option(mdb.FIELDS, "time,hash,file,from")
|
||||
m.Cmdy(mdb.SELECT, TRASH, "", mdb.HASH)
|
||||
m.PushAction("recover")
|
||||
return
|
||||
}
|
||||
|
@ -1,17 +1,17 @@
|
||||
package ssh
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/aaa"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
"github.com/shylinux/icebergs/base/tcp"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
"golang.org/x/crypto/ssh"
|
||||
|
||||
"io"
|
||||
"net"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Winsize struct{ Height, Width, x, y uint16 }
|
||||
|
@ -1,16 +1,6 @@
|
||||
package ssh
|
||||
|
||||
import (
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/aaa"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
"github.com/shylinux/icebergs/base/nfs"
|
||||
"github.com/shylinux/icebergs/base/tcp"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
|
||||
"golang.org/x/crypto/ssh"
|
||||
"golang.org/x/crypto/ssh/terminal"
|
||||
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
@ -19,6 +9,15 @@ import (
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/aaa"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
"github.com/shylinux/icebergs/base/nfs"
|
||||
"github.com/shylinux/icebergs/base/tcp"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
"golang.org/x/crypto/ssh"
|
||||
"golang.org/x/crypto/ssh/terminal"
|
||||
)
|
||||
|
||||
func _ssh_tick(m *ice.Message, pw io.Writer) {
|
||||
|
@ -1,14 +1,6 @@
|
||||
package ssh
|
||||
|
||||
import (
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/aaa"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
"github.com/shylinux/icebergs/base/nfs"
|
||||
"github.com/shylinux/icebergs/base/tcp"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
"golang.org/x/crypto/ssh"
|
||||
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
@ -17,6 +9,14 @@ import (
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/aaa"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
"github.com/shylinux/icebergs/base/nfs"
|
||||
"github.com/shylinux/icebergs/base/tcp"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
"golang.org/x/crypto/ssh"
|
||||
)
|
||||
|
||||
func _ssh_meta(conn ssh.ConnMetadata) map[string]string {
|
||||
|
@ -1,6 +1,8 @@
|
||||
package ssh
|
||||
|
||||
import (
|
||||
"golang.org/x/crypto/ssh"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
ice "github.com/shylinux/icebergs"
|
||||
@ -8,10 +10,6 @@ import (
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
"github.com/shylinux/icebergs/base/tcp"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
|
||||
"io"
|
||||
|
||||
"golang.org/x/crypto/ssh"
|
||||
)
|
||||
|
||||
func _ssh_sess(m *ice.Message, h string, client *ssh.Client) (*ssh.Session, error) {
|
||||
@ -87,8 +85,7 @@ func init() {
|
||||
m.Debug("%v %v", n, e)
|
||||
}
|
||||
})
|
||||
m.Sleep("300ms")
|
||||
m.Cmdy(SESSION, m.Option(kit.MDB_HASH))
|
||||
m.ProcessRefresh("300ms")
|
||||
}},
|
||||
"bind": {Name: "bind", Help: "绑定", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Richs(SESSION, "", m.Option(kit.MDB_HASH), func(key string, value map[string]interface{}) {
|
||||
|
@ -13,14 +13,16 @@ var Index = &ice.Context{Name: SSH, Help: "终端模块", Commands: map[string]*
|
||||
m.Load()
|
||||
m.Conf(SOURCE, kit.Keys(kit.MDB_HASH, STDIO, kit.MDB_META, kit.MDB_NAME), STDIO)
|
||||
m.Conf(SOURCE, kit.Keys(kit.MDB_HASH, STDIO, kit.MDB_META, kit.MDB_TIME), m.Time())
|
||||
|
||||
m.Richs(SERVICE, "", kit.MDB_FOREACH, func(key string, value map[string]interface{}) {
|
||||
value = kit.GetMeta(value)
|
||||
m.Cmd(SERVICE, tcp.LISTEN, tcp.PORT, value[tcp.PORT], value)
|
||||
})
|
||||
}},
|
||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if _, ok := m.Target().Server().(*Frame); ok {
|
||||
m.Done(true)
|
||||
}
|
||||
m.Richs(SERVICE, "", kit.MDB_FOREACH, func(key string, value map[string]interface{}) {
|
||||
kit.Value(value, "meta.status", tcp.CLOSE)
|
||||
})
|
||||
m.Richs(CHANNEL, "", kit.MDB_FOREACH, func(key string, value map[string]interface{}) {
|
||||
kit.Value(value, "meta.status", tcp.CLOSE)
|
||||
})
|
||||
|
@ -5,9 +5,10 @@ refer `
|
||||
源码 https://github.com/openssh/openssh-portable
|
||||
`
|
||||
|
||||
field "脚本" ssh.source
|
||||
|
||||
field "服务" ssh.service
|
||||
field "通道" ssh.channel
|
||||
|
||||
field "连接" ssh.connect
|
||||
field "会话" ssh.session
|
||||
field "脚本" ssh.source
|
||||
|
||||
|
@ -81,7 +81,7 @@ func _dream_show(m *ice.Message, name string) {
|
||||
// 启动任务
|
||||
kit.Path(os.Args[0])
|
||||
|
||||
m.Optionv(cli.CMD_STDERR, path.Join(p, m.Conf(DREAM, kit.Keym(kit.SSH_ENV, "ctx_log"))))
|
||||
m.Optionv(cli.CMD_ERRPUT, path.Join(p, m.Conf(DREAM, kit.Keym(kit.SSH_ENV, "ctx_log"))))
|
||||
m.Cmd(cli.DAEMON, m.Confv(DREAM, kit.Keym(kit.SSH_CMD)), SPIDE_DEV, SPIDE_DEV, kit.MDB_NAME, name)
|
||||
m.Event(DREAM_CREATE, kit.MDB_TYPE, m.Option(kit.MDB_TYPE), kit.MDB_NAME, name)
|
||||
m.Sleep(ice.MOD_TICK)
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/aaa"
|
||||
"github.com/shylinux/icebergs/base/cli"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
)
|
||||
|
||||
@ -46,12 +45,6 @@ func Render(msg *ice.Message, cmd string, args ...interface{}) {
|
||||
http.ServeFile(msg.W, msg.R, kit.Path(arg[0]))
|
||||
}
|
||||
|
||||
case ice.RENDER_QRCODE: // text [size]
|
||||
if data, ok := msg.Cmd(cli.QRCODE, arg).Optionv("byte").([]byte); ok {
|
||||
msg.W.Header().Set(ContentType, ContentPNG)
|
||||
msg.W.Write(data)
|
||||
}
|
||||
|
||||
case ice.RENDER_RESULT:
|
||||
if len(arg) > 0 { // [str [arg...]]
|
||||
msg.W.Write([]byte(kit.Format(arg[0], args[1:]...)))
|
||||
|
@ -158,20 +158,10 @@ func init() {
|
||||
|
||||
switch msg.Append(kit.MDB_TYPE) {
|
||||
case LOGIN, RIVER:
|
||||
switch kit.Select("", arg, 1) {
|
||||
case SHARE:
|
||||
m.Render(ice.RENDER_QRCODE, kit.MergeURL2(m.Option(ice.MSG_USERWEB), "/", list))
|
||||
default:
|
||||
m.Render(REDIRECT, "/", list)
|
||||
}
|
||||
m.Render(REDIRECT, "/", list)
|
||||
|
||||
case STORM:
|
||||
switch kit.Select("", arg, 1) {
|
||||
case SHARE:
|
||||
m.Render(ice.RENDER_QRCODE, kit.MergeURL2(m.Option(ice.MSG_USERWEB), "/page/share.html", list))
|
||||
default:
|
||||
m.Render(REDIRECT, "/page/share.html", SHARE, m.Option(SHARE))
|
||||
}
|
||||
m.Render(REDIRECT, "/page/share.html", SHARE, m.Option(SHARE))
|
||||
}
|
||||
}},
|
||||
|
||||
|
3
conf.go
3
conf.go
@ -22,6 +22,7 @@ const ( // REPOS
|
||||
|
||||
SUCCESS = "success"
|
||||
FAILURE = "failure"
|
||||
TRUE = "true"
|
||||
)
|
||||
const ( // DIR
|
||||
USR_VOLCANOS = "usr/volcanos"
|
||||
@ -33,7 +34,9 @@ const ( // DIR
|
||||
PROTO_JS = "proto.js"
|
||||
FRAME_JS = "frame.js"
|
||||
|
||||
VAR_LOG = "var/log"
|
||||
VAR_CONF = "var/conf"
|
||||
VAR_TRASH = "var/trash"
|
||||
ETC_MISS = "etc/miss.sh"
|
||||
ETC_INIT = "etc/init.shy"
|
||||
ETC_EXIT = "etc/exit.shy"
|
||||
|
@ -102,10 +102,10 @@ func init() {
|
||||
|
||||
"test": {Name: "test path func auto run case", Help: "测试用例", Action: map[string]*ice.Action{
|
||||
"run": {Name: "run", Help: "运行", Hand: func(m *ice.Message, arg ...string) {
|
||||
cli.Follow(m, "run", func() {
|
||||
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])
|
||||
})
|
||||
// cli.Follow(m, "run", func() {
|
||||
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])
|
||||
// })
|
||||
}},
|
||||
"case": {Name: "case", Help: "用例", Hand: func(m *ice.Message, arg ...string) {
|
||||
msg := m.Spawn()
|
||||
|
@ -47,3 +47,11 @@ code.go
|
||||
code.shy
|
||||
csdn.go
|
||||
github.go
|
||||
|
||||
section "python"
|
||||
refer `
|
||||
官网 https://www.python.org/
|
||||
源码 https://www.python.org/downloads/source/
|
||||
文档 https://docs.python.org/3/reference/index.html
|
||||
`
|
||||
|
||||
|
@ -1,10 +1,11 @@
|
||||
package cli
|
||||
package code
|
||||
|
||||
import (
|
||||
ice "github.com/shylinux/icebergs"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
|
||||
"path"
|
||||
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/cli"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
)
|
||||
|
||||
const PYTHON = "python"
|
||||
@ -13,8 +14,7 @@ func init() {
|
||||
Index.Merge(&ice.Context{
|
||||
Configs: map[string]*ice.Config{
|
||||
PYTHON: {Name: "python", Help: "脚本命令", Value: kit.Data(
|
||||
"python", "python",
|
||||
"source", "http://mirrors.sohu.com/python/3.5.2/Python-3.5.2.tar.xz",
|
||||
PYTHON, "python", cli.SOURCE, "http://mirrors.sohu.com/python/3.5.2/Python-3.5.2.tar.xz",
|
||||
)},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
@ -30,10 +30,10 @@ func init() {
|
||||
}},
|
||||
|
||||
"pip": {Name: "pip", Help: "安装", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(SYSTEM, m.Conf(PYTHON, "meta.pip"), "install", arg)
|
||||
m.Cmdy(cli.SYSTEM, m.Conf(PYTHON, "meta.pip"), "install", arg)
|
||||
}},
|
||||
"run": {Name: "run", Help: "运行", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(SYSTEM, m.Conf(PYTHON, "meta.python"), arg)
|
||||
m.Cmdy(cli.SYSTEM, m.Conf(PYTHON, "meta.python"), arg)
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Cmdy("web.code.install", path.Base(m.Conf(PYTHON, kit.META_SOURCE)), arg)
|
Loading…
x
Reference in New Issue
Block a user