forked from x/icebergs
opt some
This commit is contained in:
parent
028a6ba82b
commit
f57e198c7e
@ -16,12 +16,9 @@ import (
|
||||
)
|
||||
|
||||
func _runtime_init(m *ice.Message) {
|
||||
// 版本信息 make
|
||||
kit.Fetch(kit.UnMarshal(kit.Format(ice.Info.Make)), func(key string, value ice.Any) {
|
||||
m.Conf(RUNTIME, kit.Keys(MAKE, strings.ToLower(key)), value)
|
||||
})
|
||||
|
||||
// 主机信息 host
|
||||
m.Conf(RUNTIME, kit.Keys(HOST, GOARCH), runtime.GOARCH)
|
||||
m.Conf(RUNTIME, kit.Keys(HOST, GOOS), runtime.GOOS)
|
||||
m.Conf(RUNTIME, kit.Keys(HOST, PID), os.Getpid())
|
||||
@ -30,36 +27,16 @@ func _runtime_init(m *ice.Message) {
|
||||
m.Conf(RUNTIME, kit.Keys(HOST, MAXPROCS), runtime.GOMAXPROCS(0))
|
||||
m.Conf(RUNTIME, mdb.META, "")
|
||||
m.Conf(RUNTIME, mdb.HASH, "")
|
||||
|
||||
// 启动目录 boot
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, HOSTNAME), kit.Env("HOSTNAME"))
|
||||
if name, e := os.Hostname(); e == nil && name != "" {
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, HOSTNAME), name)
|
||||
}
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, PATHNAME), path.Base(kit.Env("PWD")))
|
||||
if name, e := os.Getwd(); e == nil && name != "" {
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, PATHNAME), path.Base(name))
|
||||
}
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, USERNAME), kit.Select(kit.UserName(), kit.Select(kit.Env("WORKSPACE_GIT_USERNAME"), kit.Env(CTX_USER))))
|
||||
ice.Info.HostName = m.Conf(RUNTIME, kit.Keys(BOOT, HOSTNAME))
|
||||
ice.Info.PathName = m.Conf(RUNTIME, kit.Keys(BOOT, PATHNAME))
|
||||
ice.Info.UserName = m.Conf(RUNTIME, kit.Keys(BOOT, USERNAME))
|
||||
m.Cmd(aaa.USER, mdb.CREATE, ice.Info.UserName, "", aaa.ROOT)
|
||||
aaa.UserRoot(ice.Pulse)
|
||||
|
||||
// 启动程序 boot
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, mdb.COUNT), kit.Int(m.Conf(RUNTIME, kit.Keys(BOOT, mdb.COUNT)))+1)
|
||||
bin := _system_find(m, os.Args[0])
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, ice.BIN), bin)
|
||||
if s, e := nfs.StatFile(m, bin); e == nil {
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, nfs.SIZE), kit.FmtSize(s.Size()))
|
||||
if f, e := nfs.OpenFile(m, bin); e == nil {
|
||||
defer f.Close()
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, mdb.HASH), kit.Hashs(f))
|
||||
osid := runtime.GOOS
|
||||
m.Cmd(nfs.CAT, "/etc/os-release", func(text string) {
|
||||
if ls := kit.Split(text, "="); len(ls) > 1 {
|
||||
switch ls[0] {
|
||||
case "ID", "ID_LIKE":
|
||||
osid = strings.TrimSpace(ls[1] + ice.SP + osid)
|
||||
}
|
||||
}
|
||||
|
||||
// 环境变量 conf
|
||||
})
|
||||
m.Conf(RUNTIME, kit.Keys(HOST, OSID), osid)
|
||||
for _, k := range ENV_LIST {
|
||||
switch m.Conf(RUNTIME, kit.Keys(CONF, k), kit.Env(k)); k {
|
||||
case CTX_PID:
|
||||
@ -71,25 +48,31 @@ func _runtime_init(m *ice.Message) {
|
||||
}
|
||||
}
|
||||
|
||||
// 系统版本 osid
|
||||
osid := runtime.GOOS
|
||||
m.Cmd(nfs.CAT, "/etc/os-release", func(text string) {
|
||||
if ls := kit.Split(text, "="); len(ls) > 1 {
|
||||
switch ls[0] {
|
||||
case "ID", "ID_LIKE":
|
||||
osid = strings.TrimSpace(ls[1] + ice.SP + osid)
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, HOSTNAME), kit.Env("HOSTNAME"))
|
||||
if name, e := os.Hostname(); e == nil && name != "" {
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, HOSTNAME), name)
|
||||
}
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, PATHNAME), path.Base(kit.Env("PWD")))
|
||||
if name, e := os.Getwd(); e == nil && name != "" {
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, PATHNAME), path.Base(name))
|
||||
}
|
||||
})
|
||||
m.Conf(RUNTIME, kit.Keys(HOST, OSID), osid)
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, USERNAME), kit.Select(kit.UserName(), kit.Env(CTX_USER)))
|
||||
ice.Info.HostName = m.Conf(RUNTIME, kit.Keys(BOOT, HOSTNAME))
|
||||
ice.Info.PathName = m.Conf(RUNTIME, kit.Keys(BOOT, PATHNAME))
|
||||
ice.Info.UserName = m.Conf(RUNTIME, kit.Keys(BOOT, USERNAME))
|
||||
m.Cmd(aaa.USER, mdb.CREATE, ice.Info.UserName, "", aaa.ROOT)
|
||||
aaa.UserRoot(ice.Pulse)
|
||||
|
||||
switch strings.Split(os.Getenv(TERM), "-")[0] {
|
||||
case "xterm", "screen":
|
||||
ice.Info.Colors = true
|
||||
default:
|
||||
ice.Info.Colors = false
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, mdb.COUNT), kit.Int(m.Conf(RUNTIME, kit.Keys(BOOT, mdb.COUNT)))+1)
|
||||
bin := _system_find(m, os.Args[0])
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, ice.BIN), bin)
|
||||
if s, e := nfs.StatFile(m, bin); e == nil {
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, nfs.SIZE), kit.FmtSize(s.Size()))
|
||||
if f, e := nfs.OpenFile(m, bin); e == nil {
|
||||
defer f.Close()
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, mdb.HASH), kit.Hashs(f))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
func _runtime_hostinfo(m *ice.Message) {
|
||||
m.Push("nCPU", strings.Count(m.Cmdx(nfs.CAT, "/proc/cpuinfo"), "processor"))
|
||||
@ -121,8 +104,8 @@ const (
|
||||
MAKE = "make"
|
||||
TEST = "test"
|
||||
HOST = "host"
|
||||
BOOT = "boot"
|
||||
CONF = "conf"
|
||||
BOOT = "boot"
|
||||
NODE = "node"
|
||||
)
|
||||
const (
|
||||
@ -147,6 +130,7 @@ const (
|
||||
)
|
||||
const (
|
||||
CTX_SHY = "ctx_shy"
|
||||
CTX_COM = "ctx_com"
|
||||
CTX_DEV = "ctx_dev"
|
||||
CTX_OPS = "ctx_ops"
|
||||
CTX_POD = "ctx_pod"
|
||||
@ -164,7 +148,7 @@ const (
|
||||
)
|
||||
|
||||
var ENV_LIST = []string{
|
||||
TERM, SHELL, CTX_SHY, CTX_DEV, CTX_OPS, CTX_ARG, CTX_PID, CTX_USER, CTX_SHARE, CTX_RIVER, CTX_DAEMON,
|
||||
TERM, SHELL, CTX_SHY, CTX_COM, CTX_DEV, CTX_OPS, CTX_ARG, CTX_PID, CTX_USER, CTX_SHARE, CTX_RIVER, CTX_DAEMON,
|
||||
}
|
||||
|
||||
const (
|
||||
@ -186,81 +170,61 @@ const RUNTIME = "runtime"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
RUNTIME: {Name: "runtime info=ifconfig,hostinfo,hostname,userinfo,procinfo,diskinfo,bootinfo,api,cli,cmd,env auto", Help: "运行环境", Actions: ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
cs := m.Target().Configs
|
||||
if _, ok := cs[RUNTIME]; !ok {
|
||||
cs[RUNTIME] = &ice.Config{Value: kit.Dict()}
|
||||
}
|
||||
_runtime_init(m)
|
||||
}},
|
||||
IFCONFIG: {Name: "ifconfig", Help: "网卡配置", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy("tcp.host")
|
||||
}},
|
||||
HOSTINFO: {Name: "hostinfo", Help: "主机信息", Hand: func(m *ice.Message, arg ...string) {
|
||||
_runtime_hostinfo(m)
|
||||
}},
|
||||
HOSTNAME: {Name: "hostname", Help: "主机域名", Hand: func(m *ice.Message, arg ...string) {
|
||||
RUNTIME: {Name: "runtime info=ifconfig,hostinfo,hostname,userinfo,procinfo,diskinfo,bootinfo,api,cli,cmd,env auto", Help: "运行环境", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { _runtime_init(m) }},
|
||||
IFCONFIG: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy("tcp.host") }},
|
||||
HOSTINFO: {Hand: func(m *ice.Message, arg ...string) { _runtime_hostinfo(m) }},
|
||||
HOSTNAME: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) > 0 {
|
||||
ice.Info.HostName = m.Conf(RUNTIME, kit.Keys(BOOT, HOSTNAME), m.Conf(RUNTIME, kit.Keys(NODE, mdb.NAME), arg[0]))
|
||||
}
|
||||
m.Echo(ice.Info.HostName)
|
||||
}},
|
||||
USERINFO: {Name: "userinfo", Help: "用户信息", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Split(m.Cmdx(SYSTEM, "who"), "user term time")
|
||||
}},
|
||||
PROCINFO: {Name: "procinfo", Help: "进程信息", Hand: func(m *ice.Message, arg ...string) {
|
||||
USERINFO: {Hand: func(m *ice.Message, arg ...string) { m.Split(m.Cmdx(SYSTEM, "who"), "user term time") }},
|
||||
PROCINFO: {Hand: func(m *ice.Message, arg ...string) {
|
||||
msg := m.Cmd("", HOSTINFO)
|
||||
m.Split(m.Cmdx(SYSTEM, "ps", "u")).PushAction(PROCKILL).SortIntR("RSS")
|
||||
m.StatusTimeCount("nCPU", msg.Append("nCPU"), "MemTotal", msg.Append("MemTotal"), "MemFree", msg.Append("MemFree"))
|
||||
}},
|
||||
PROCKILL: {Name: "prockill", Help: "结束进程", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(gdb.SIGNAL, gdb.STOP, m.Option("PID"))
|
||||
m.ProcessRefresh()
|
||||
}},
|
||||
DISKINFO: {Name: "diskinfo", Help: "磁盘信息", Hand: func(m *ice.Message, arg ...string) {
|
||||
_runtime_diskinfo(m)
|
||||
}},
|
||||
MAXPROCS: {Name: "maxprocs", Help: "最大并发", Hand: func(m *ice.Message, arg ...string) {
|
||||
PROCKILL: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(gdb.SIGNAL, gdb.STOP, m.Option("PID")).ProcessRefresh() }},
|
||||
MAXPROCS: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) > 0 {
|
||||
runtime.GOMAXPROCS(kit.Int(m.Conf(RUNTIME, kit.Keys(HOST, MAXPROCS), kit.Select("1", arg, 0))))
|
||||
runtime.GOMAXPROCS(kit.Int(m.Conf(RUNTIME, kit.Keys(HOST, MAXPROCS), arg[0])))
|
||||
}
|
||||
m.Echo("%d", runtime.GOMAXPROCS(0))
|
||||
}},
|
||||
API: {Name: "api", Help: "接口命令", Hand: func(m *ice.Message, arg ...string) {
|
||||
DISKINFO: {Hand: func(m *ice.Message, arg ...string) { _runtime_diskinfo(m) }},
|
||||
API: {Hand: func(m *ice.Message, arg ...string) {
|
||||
for k, v := range ice.Info.Route {
|
||||
m.Push(nfs.PATH, k)
|
||||
m.Push(nfs.FILE, v)
|
||||
m.Push(nfs.PATH, k).Push(nfs.FILE, v)
|
||||
}
|
||||
m.Sort(nfs.PATH).StatusTimeCount()
|
||||
}},
|
||||
CLI: {Name: "cli", Help: "文件模块", Hand: func(m *ice.Message, arg ...string) {
|
||||
CLI: {Hand: func(m *ice.Message, arg ...string) {
|
||||
for k, v := range ice.Info.File {
|
||||
m.Push(nfs.FILE, k)
|
||||
m.Push(mdb.NAME, v)
|
||||
m.Push(nfs.FILE, k).Push(mdb.NAME, v)
|
||||
}
|
||||
m.Sort(nfs.FILE).StatusTimeCount()
|
||||
}},
|
||||
CMD: {Name: "cmd", Help: "模块命令", Hand: func(m *ice.Message, arg ...string) {
|
||||
CMD: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.OptionFields(ctx.INDEX, mdb.NAME, mdb.HELP)
|
||||
m.Cmdy(ctx.COMMAND, mdb.SEARCH, ctx.COMMAND).StatusTimeCount()
|
||||
}},
|
||||
ENV: {Name: "env", Help: "环境变量", Hand: func(m *ice.Message, arg ...string) {
|
||||
ENV: {Hand: func(m *ice.Message, arg ...string) {
|
||||
for _, v := range os.Environ() {
|
||||
ls := strings.SplitN(v, "=", 2)
|
||||
m.Push(mdb.NAME, ls[0])
|
||||
m.Push(mdb.VALUE, ls[1])
|
||||
ls := strings.SplitN(v, ice.EQ, 2)
|
||||
m.Push(mdb.NAME, ls[0]).Push(mdb.VALUE, ls[1])
|
||||
}
|
||||
m.StatusTimeCount()
|
||||
}},
|
||||
MAKE_DOMAIN: {Name: "make.domain", Help: "编译主机", Hand: func(m *ice.Message, arg ...string) {
|
||||
MAKE_DOMAIN: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if os.Getenv(CTX_DEV) == "" || os.Getenv(CTX_POD) == "" {
|
||||
m.Echo(m.Conf(RUNTIME, MAKE_DOMAIN))
|
||||
} else {
|
||||
m.Echo(kit.MergePOD(os.Getenv(CTX_DEV), os.Getenv(CTX_POD)))
|
||||
}
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, arg ...string) {
|
||||
}, ctx.ConfAction("hi")), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) > 0 && arg[0] == BOOTINFO {
|
||||
arg = arg[1:]
|
||||
}
|
||||
|
@ -16,58 +16,48 @@ import (
|
||||
)
|
||||
|
||||
func _system_cmd(m *ice.Message, arg ...string) *exec.Cmd {
|
||||
bin := ""
|
||||
if text := kit.ReadFile(ice.ETC_PATH); len(text) > 0 {
|
||||
if file := _system_find(m, arg[0], strings.Split(text, ice.NL)...); file != "" {
|
||||
m.Logs(mdb.SELECT, "etc path cmd", file)
|
||||
bin = file // 配置目录
|
||||
}
|
||||
}
|
||||
|
||||
env := kit.Simple(m.Optionv(CMD_ENV))
|
||||
bin, env := "", kit.Simple(m.Optionv(CMD_ENV))
|
||||
for i := 0; i < len(env)-1; i += 2 {
|
||||
if env[i] == PATH {
|
||||
if file := _system_find(m, arg[0], strings.Split(env[i+1], ice.DF)...); file != "" {
|
||||
m.Logs(mdb.SELECT, "env path cmd", file)
|
||||
bin = file // 环境变量
|
||||
bin = file
|
||||
}
|
||||
}
|
||||
}
|
||||
if bin == "" {
|
||||
if text := kit.ReadFile(ice.ETC_PATH); len(text) > 0 {
|
||||
if file := _system_find(m, arg[0], strings.Split(text, ice.NL)...); file != "" {
|
||||
m.Logs(mdb.SELECT, "etc path cmd", file)
|
||||
bin = file
|
||||
}
|
||||
}
|
||||
}
|
||||
// if m.Option(CMD_DIR) != "" {
|
||||
// if file := _system_find(m, arg[0], m.Option(CMD_DIR)); file != "" {
|
||||
// m.Logs(mdb.SELECT, "dir path cmd", file)
|
||||
// bin = file // 当前目录
|
||||
// }
|
||||
// }
|
||||
if bin == "" {
|
||||
if file := _system_find(m, arg[0], ice.BIN, nfs.PWD); file != "" {
|
||||
m.Logs(mdb.SELECT, "mirrors cmd", file)
|
||||
bin = file // 当前目录
|
||||
m.Logs(mdb.SELECT, "contexts cmd", file)
|
||||
bin = file
|
||||
}
|
||||
}
|
||||
if bin == "" && !strings.Contains(arg[0], ice.PS) {
|
||||
if file := _system_find(m, arg[0]); file != "" {
|
||||
m.Logs(mdb.SELECT, "systems cmd", file)
|
||||
bin = file // 系统命令
|
||||
bin = file
|
||||
}
|
||||
}
|
||||
if bin == "" && !strings.Contains(arg[0], ice.PS) {
|
||||
m.Cmd(MIRRORS, CMD, arg[0])
|
||||
if file := _system_find(m, arg[0]); file != "" {
|
||||
m.Logs(mdb.SELECT, "mirrors cmd", file)
|
||||
bin = file // 软件镜像
|
||||
bin = file
|
||||
}
|
||||
}
|
||||
|
||||
cmd := exec.Command(bin, arg[1:]...)
|
||||
|
||||
// 运行目录
|
||||
if cmd.Dir = m.Option(CMD_DIR); len(cmd.Dir) > 0 {
|
||||
if m.Logs(mdb.EXPORT, CMD_DIR, cmd.Dir); !nfs.ExistsFile(m, cmd.Dir) {
|
||||
file.MkdirAll(cmd.Dir, ice.MOD_DIR)
|
||||
}
|
||||
}
|
||||
// 环境变量
|
||||
for i := 0; i < len(env)-1; i += 2 {
|
||||
cmd.Env = append(cmd.Env, kit.Format("%s=%s", env[i], env[i+1]))
|
||||
}
|
||||
@ -90,10 +80,10 @@ func _system_out(m *ice.Message, out string) io.Writer {
|
||||
}
|
||||
func _system_exec(m *ice.Message, cmd *exec.Cmd) {
|
||||
if r, ok := m.Optionv(CMD_INPUT).(io.Reader); ok {
|
||||
cmd.Stdin = r // 输入流
|
||||
cmd.Stdin = r
|
||||
}
|
||||
if w := _system_out(m, CMD_OUTPUT); w != nil {
|
||||
cmd.Stdout, cmd.Stderr = w, w // 输出流
|
||||
cmd.Stdout, cmd.Stderr = w, w
|
||||
if w := _system_out(m, CMD_ERRPUT); w != nil {
|
||||
cmd.Stderr = w
|
||||
}
|
||||
@ -110,8 +100,6 @@ func _system_exec(m *ice.Message, cmd *exec.Cmd) {
|
||||
m.Echo(strings.TrimRight(out.String(), ice.NL))
|
||||
}()
|
||||
}
|
||||
|
||||
// 执行命令
|
||||
if e := cmd.Run(); !m.Warn(e, ice.ErrNotFound, cmd.Args) {
|
||||
m.Cost(CODE, cmd.ProcessState.ExitCode(), ctx.ARGS, cmd.Args)
|
||||
}
|
||||
@ -157,10 +145,10 @@ const SYSTEM = "system"
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
SYSTEM: {Name: "system cmd run", Help: "系统命令", Actions: ice.Actions{
|
||||
nfs.FIND: {Name: "find", Help: "查找", Hand: func(m *ice.Message, arg ...string) {
|
||||
nfs.FIND: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Echo(_system_find(m, arg[0], arg[1:]...))
|
||||
}},
|
||||
nfs.PUSH: {Name: "push", Help: "查找", Hand: func(m *ice.Message, arg ...string) {
|
||||
nfs.PUSH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
for _, p := range arg {
|
||||
if !strings.Contains(m.Cmdx(nfs.CAT, ice.ETC_PATH), p) {
|
||||
m.Cmd(nfs.PUSH, ice.ETC_PATH, strings.TrimSpace(p)+ice.NL)
|
||||
@ -168,21 +156,18 @@ func init() {
|
||||
}
|
||||
m.Cmdy(nfs.CAT, ice.ETC_PATH)
|
||||
}},
|
||||
MAN: {Name: "man", Help: "文档", Hand: func(m *ice.Message, arg ...string) {
|
||||
MAN: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 1 {
|
||||
arg = append(arg, "")
|
||||
}
|
||||
m.Option(CMD_ENV, "COLUMNS", kit.Int(kit.Select("1920", m.Option("width")))/12)
|
||||
m.Option(CMD_ENV, "COLUMNS", kit.Int(kit.Select("1920", m.Option(ice.WIDTH)))/12)
|
||||
m.Echo(SystemCmds(m, "man %s %s|col -b", kit.Select("", arg[1], arg[1] != "1"), arg[0]))
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
return
|
||||
}
|
||||
if len(arg) == 1 {
|
||||
arg = kit.Split(arg[0])
|
||||
}
|
||||
if _system_exec(m, _system_cmd(m, arg...)); IsSuccess(m) && m.Append(CMD_ERR) == "" {
|
||||
if _system_exec(m, _system_cmd(m, kit.Simple(kit.Split(arg[0]), arg[1:])...)); IsSuccess(m) && m.Append(CMD_ERR) == "" {
|
||||
m.SetAppend()
|
||||
}
|
||||
}},
|
||||
|
@ -18,10 +18,8 @@ func _command_list(m *ice.Message, name string) {
|
||||
case nfs.JS:
|
||||
m.Push(DISPLAY, FileURI(name))
|
||||
name = kit.Select(CAN_PLUGIN, GetFileCmd(name))
|
||||
|
||||
case nfs.GO:
|
||||
name = GetFileCmd(name)
|
||||
|
||||
default:
|
||||
if msg := m.Cmd(mdb.RENDER, kit.Ext(name)); msg.Length() > 0 {
|
||||
m.Push(ARGS, kit.Format(kit.List(name)))
|
||||
@ -33,12 +31,11 @@ func _command_list(m *ice.Message, name string) {
|
||||
m.Push(mdb.INDEX, name)
|
||||
return
|
||||
}
|
||||
if name == "" { // 命令列表
|
||||
if name == "" {
|
||||
for k, v := range m.Source().Commands {
|
||||
if k[0] == '/' || k[0] == '_' {
|
||||
continue // 内部命令
|
||||
continue
|
||||
}
|
||||
|
||||
m.Push(mdb.KEY, k)
|
||||
m.Push(mdb.NAME, v.Name)
|
||||
m.Push(mdb.HELP, v.Help)
|
||||
@ -46,8 +43,6 @@ func _command_list(m *ice.Message, name string) {
|
||||
m.Sort(mdb.KEY)
|
||||
return
|
||||
}
|
||||
|
||||
// 命令详情
|
||||
m.Spawn(m.Source()).Search(name, func(p *ice.Context, s *ice.Context, key string, cmd *ice.Command) {
|
||||
m.Push(mdb.INDEX, kit.Keys(s.Cap(ice.CTX_FOLLOW), key))
|
||||
m.Push(mdb.NAME, kit.Format(cmd.Name))
|
||||
@ -59,17 +54,15 @@ func _command_list(m *ice.Message, name string) {
|
||||
func _command_search(m *ice.Message, kind, name, text string) {
|
||||
m.Travel(func(p *ice.Context, s *ice.Context, key string, cmd *ice.Command) {
|
||||
if key[0] == '/' || key[0] == '_' {
|
||||
return // 内部命令
|
||||
return
|
||||
}
|
||||
if name != "" && !strings.HasPrefix(key, name) && !strings.Contains(s.Name, name) {
|
||||
return
|
||||
}
|
||||
|
||||
m.PushSearch(ice.CTX, kit.PathName(1), ice.CMD, kit.FileName(1),
|
||||
kit.SimpleKV("", s.Cap(ice.CTX_FOLLOW), cmd.Name, cmd.Help),
|
||||
CONTEXT, s.Cap(ice.CTX_FOLLOW), COMMAND, key,
|
||||
CONTEXT, s.Cap(ice.CTX_FOLLOW), COMMAND, key, mdb.HELP, cmd.Help,
|
||||
INDEX, kit.Keys(s.Cap(ice.CTX_FOLLOW), key),
|
||||
mdb.HELP, cmd.Help,
|
||||
)
|
||||
})
|
||||
}
|
||||
@ -91,17 +84,17 @@ func init() {
|
||||
COMMAND: {Name: "command key auto", Help: "命令", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
TravelCmd(m, func(key, file, line string) {
|
||||
if strings.Contains(file, "icebergs") {
|
||||
if strings.Contains(file, ice.ICEBERGS) {
|
||||
AddFileCmd(file, key)
|
||||
}
|
||||
})
|
||||
}},
|
||||
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if arg[0] == m.CommandKey() || len(arg) > 1 && arg[1] != "" {
|
||||
_command_search(m, arg[0], kit.Select("", arg, 1), kit.Select("", arg, 2))
|
||||
}
|
||||
}},
|
||||
"tags": {Name: "tags", Help: "索引", Hand: func(m *ice.Message, arg ...string) {
|
||||
"tags": {Hand: func(m *ice.Message, arg ...string) {
|
||||
TravelCmd(m, func(key, file, line string) {
|
||||
m.Push("name", key)
|
||||
m.Push("file", file)
|
||||
@ -124,56 +117,60 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
var runChecker = []func(*ice.Message, string, string, ...string) bool{}
|
||||
|
||||
func AddRunChecker(cb func(*ice.Message, string, string, ...string) bool) {
|
||||
runChecker = append(runChecker, cb)
|
||||
}
|
||||
func init() {
|
||||
AddRunChecker(func(m *ice.Message, cmd, check string, arg ...string) bool {
|
||||
switch check {
|
||||
case mdb.REMOVE:
|
||||
m.Cmd(CONFIG, mdb.REMOVE, cmd)
|
||||
return true
|
||||
case mdb.SELECT:
|
||||
m.Cmdy(CONFIG, cmd)
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
})
|
||||
}
|
||||
func Run(m *ice.Message, arg ...string) {
|
||||
if len(arg) > 3 && arg[1] == ACTION && arg[2] == CONFIG {
|
||||
switch arg[3] {
|
||||
case "help":
|
||||
if file := strings.ReplaceAll(GetCmdFile(m, arg[0]), ".go", ".shy"); nfs.ExistsFile(m, file) {
|
||||
ProcessFloat(m, "web.wiki.word", file)
|
||||
}
|
||||
case "script":
|
||||
if file := strings.ReplaceAll(GetCmdFile(m, arg[0]), ".go", ".js"); nfs.ExistsFile(m, file) {
|
||||
ProcessFloat(m, "web.code.inner", file)
|
||||
}
|
||||
case "source":
|
||||
if file := GetCmdFile(m, arg[0]); nfs.ExistsFile(m, file) {
|
||||
ProcessFloat(m, "web.code.inner", file)
|
||||
}
|
||||
case "select":
|
||||
m.Cmdy(CONFIG, arg[0])
|
||||
case "reset":
|
||||
m.Cmd(CONFIG, "reset", arg[0])
|
||||
}
|
||||
for _, check := range runChecker {
|
||||
if check(m, arg[0], arg[3], arg...) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
if !PodCmd(m, arg) && aaa.Right(m, arg) {
|
||||
m.Cmdy(arg)
|
||||
}
|
||||
}
|
||||
func PodCmd(m *ice.Message, arg ...ice.Any) bool {
|
||||
if pod := m.Option(ice.POD); pod != "" {
|
||||
if m.Option(ice.POD, ""); len(kit.Simple(m.Optionv(ice.MSG_UPLOAD))) == 1 {
|
||||
m.Cmdy("cache", "upload").Option(ice.MSG_UPLOAD, m.Append(mdb.HASH), m.Append(mdb.NAME), m.Append(nfs.SIZE))
|
||||
}
|
||||
m.Cmdy(append(kit.List(ice.SPACE, pod), arg...))
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
func CmdHandler(args ...ice.Any) ice.Handler {
|
||||
return func(m *ice.Message, arg ...string) { m.Cmdy(args...) }
|
||||
}
|
||||
func CmdAction(args ...ice.Any) ice.Actions {
|
||||
return ice.Actions{ice.CTX_INIT: mdb.AutoConfig(args...),
|
||||
COMMAND: {Name: "command", Help: "命令", Hand: func(m *ice.Message, arg ...string) {
|
||||
COMMAND: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if !PodCmd(m, COMMAND, arg) {
|
||||
m.Cmdy(COMMAND, arg)
|
||||
}
|
||||
}},
|
||||
ice.RUN: {Name: "run", Help: "执行", Hand: Run},
|
||||
ice.RUN: {Hand: Run},
|
||||
}
|
||||
}
|
||||
func PodCmd(m *ice.Message, arg ...ice.Any) bool {
|
||||
if pod := m.Option(ice.POD); pod != "" {
|
||||
if m.Option(ice.POD, ""); m.Option(ice.MSG_UPLOAD) != "" {
|
||||
msg := m.Cmd("cache", "upload")
|
||||
m.Option(ice.MSG_UPLOAD, msg.Append(mdb.HASH), msg.Append(mdb.NAME), msg.Append(nfs.SIZE))
|
||||
}
|
||||
m.Cmdy(append(kit.List("space", pod), arg...))
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func FileURI(dir string) string {
|
||||
if strings.Contains(dir, "go/pkg/mod") {
|
||||
|
@ -112,7 +112,7 @@ func init() {
|
||||
}
|
||||
m.Confv(arg[0], arg[1], kit.List(list...))
|
||||
}},
|
||||
"reset": {Name: "reset key sub", Help: "重置", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.REMOVE: {Name: "remove key sub", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Conf(m.Option("key"), m.Option("sub"), "")
|
||||
m.Go(func() { m.Cmd(ice.EXIT, 1) })
|
||||
}},
|
||||
|
@ -156,6 +156,12 @@ func (f *Frame) scan(m *ice.Message, h, line string) *Frame {
|
||||
}
|
||||
|
||||
func (f *Frame) Begin(m *ice.Message, arg ...string) ice.Server {
|
||||
switch strings.Split(os.Getenv(cli.TERM), "-")[0] {
|
||||
case "xterm", "screen":
|
||||
ice.Info.Colors = true
|
||||
default:
|
||||
ice.Info.Colors = false
|
||||
}
|
||||
return f
|
||||
}
|
||||
func (f *Frame) Spawn(m *ice.Message, c *ice.Context, arg ...string) ice.Server {
|
||||
|
@ -19,15 +19,10 @@ import (
|
||||
)
|
||||
|
||||
func Upload(m *ice.Message) *ice.Message {
|
||||
if up := kit.Simple(m.Optionv(ice.MSG_UPLOAD)); len(up) == 0 {
|
||||
return m
|
||||
} else if len(up) < 2 {
|
||||
msg := m.Cmd(CACHE, UPLOAD)
|
||||
m.Option(ice.MSG_UPLOAD, msg.Append(mdb.HASH), msg.Append(mdb.NAME), msg.Append(nfs.SIZE))
|
||||
return msg
|
||||
} else {
|
||||
return m.Cmd(CACHE, up[0])
|
||||
if len(kit.Simple(m.Optionv(ice.MSG_UPLOAD))) == 1 {
|
||||
m.Cmdy(CACHE, UPLOAD).Option(ice.MSG_UPLOAD, m.Append(mdb.HASH), m.Append(mdb.NAME), m.Append(nfs.SIZE))
|
||||
}
|
||||
return m
|
||||
}
|
||||
func PushNotice(m *ice.Message, arg ...ice.Any) {
|
||||
if m.Option(ice.MSG_DAEMON) == "" {
|
||||
|
@ -120,6 +120,9 @@ const (
|
||||
SERVE_START = "serve.start"
|
||||
SERVE_STOP = "serve.stop"
|
||||
WEBSITE = "website"
|
||||
|
||||
CODE_INNER = "web.code.inner"
|
||||
WIKI_WORD = "web.wiki.word"
|
||||
)
|
||||
const WEB = "web"
|
||||
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
"shylinux.com/x/icebergs/base/lex"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/web"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
@ -160,6 +161,19 @@ func init() {
|
||||
ctx.DisplayLocal(m, "")
|
||||
}},
|
||||
})
|
||||
ctx.AddRunChecker(func(m *ice.Message, cmd, check string, arg ...string) bool {
|
||||
switch check {
|
||||
case nfs.SCRIPT:
|
||||
if file := kit.ExtChange(ctx.GetCmdFile(m, cmd), nfs.JS); nfs.ExistsFile(m, file) {
|
||||
ctx.ProcessFloat(m, web.CODE_INNER, file)
|
||||
}
|
||||
case nfs.SOURCE:
|
||||
if file := ctx.GetCmdFile(m, cmd); nfs.ExistsFile(m, file) {
|
||||
ctx.ProcessFloat(m, web.CODE_INNER, file)
|
||||
}
|
||||
}
|
||||
return false
|
||||
})
|
||||
}
|
||||
func PlugAction() ice.Actions {
|
||||
return ice.Actions{
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/ssh"
|
||||
"shylinux.com/x/icebergs/base/web"
|
||||
"shylinux.com/x/icebergs/misc/git"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
@ -50,6 +51,16 @@ func init() {
|
||||
}
|
||||
}},
|
||||
})
|
||||
ctx.AddRunChecker(func(m *ice.Message, cmd, check string, arg ...string) bool {
|
||||
switch check {
|
||||
case ice.HELP:
|
||||
if file := kit.ExtChange(ctx.GetCmdFile(m, cmd), nfs.SHY); nfs.ExistsFile(m, file) {
|
||||
ctx.ProcessFloat(m, web.WIKI_WORD, file)
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
}
|
||||
func WordAction(template string, arg ...ice.Any) ice.Actions {
|
||||
return ice.Actions{ice.CTX_INIT: mdb.AutoConfig(append([]ice.Any{nfs.TEMPLATE, template}, arg...)...)}
|
||||
|
Loading…
x
Reference in New Issue
Block a user