forked from x/icebergs
opt cli
This commit is contained in:
parent
f57e198c7e
commit
b187f2c65b
@ -56,14 +56,16 @@ func _role_list(m *ice.Message, userrole string) *ice.Message {
|
||||
m.Push(ROLE, kit.Value(value, mdb.NAME))
|
||||
m.Push(mdb.ZONE, BLACK)
|
||||
m.Push(mdb.KEY, k)
|
||||
m.Push(mdb.VALUE, v)
|
||||
})
|
||||
kit.Fetch(value[WHITE], func(k string, v ice.Any) {
|
||||
m.Push(ROLE, kit.Value(value, mdb.NAME))
|
||||
m.Push(mdb.ZONE, WHITE)
|
||||
m.Push(mdb.KEY, k)
|
||||
m.Push(mdb.VALUE, v)
|
||||
})
|
||||
})
|
||||
return m
|
||||
return m.Sort(mdb.KEY).StatusTimeCount()
|
||||
}
|
||||
|
||||
const (
|
||||
|
@ -8,14 +8,6 @@ import (
|
||||
"shylinux.com/x/toolkits/logs"
|
||||
)
|
||||
|
||||
func _sess_check(m *ice.Message, sessid string) {
|
||||
m.Assert(sessid != "")
|
||||
mdb.HashSelectDetail(m, sessid, func(value ice.Map) {
|
||||
if !m.WarnTimeNotValid(value[mdb.TIME], sessid) {
|
||||
SessAuth(m, value)
|
||||
}
|
||||
})
|
||||
}
|
||||
func _sess_create(m *ice.Message, username string) (h string) {
|
||||
m.Assert(username != "")
|
||||
if msg := m.Cmd(USER, username); msg.Length() > 0 {
|
||||
@ -26,6 +18,21 @@ func _sess_create(m *ice.Message, username string) (h string) {
|
||||
gdb.Event(m, SESS_CREATE, SESS, h, USERNAME, username)
|
||||
return h
|
||||
}
|
||||
func _sess_check(m *ice.Message, sessid string) {
|
||||
m.Assert(sessid != "")
|
||||
|
||||
val := kit.Dict()
|
||||
mdb.HashSelectDetail(m, sessid, func(value ice.Map) {
|
||||
if !m.WarnTimeNotValid(value[mdb.TIME], sessid) {
|
||||
for k, v := range value {
|
||||
val[k] = v
|
||||
}
|
||||
}
|
||||
})
|
||||
if len(val) > 0 {
|
||||
SessAuth(m, val)
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
IP = "ip"
|
||||
@ -63,6 +70,7 @@ func SessCreate(m *ice.Message, username string) string {
|
||||
return m.Option(ice.MSG_SESSID, m.Cmdx(SESS, mdb.CREATE, username))
|
||||
}
|
||||
func SessCheck(m *ice.Message, sessid string) bool {
|
||||
m.Option("log.caller", logs.FileLine(2))
|
||||
m.Option(ice.MSG_USERROLE, VOID)
|
||||
m.Option(ice.MSG_USERNAME, "")
|
||||
m.Option(ice.MSG_USERNICK, "")
|
||||
@ -73,7 +81,7 @@ func SessAuth(m *ice.Message, value ice.Map, arg ...string) {
|
||||
USERROLE, m.Option(ice.MSG_USERROLE, value[USERROLE]),
|
||||
USERNAME, m.Option(ice.MSG_USERNAME, value[USERNAME]),
|
||||
USERNICK, m.Option(ice.MSG_USERNICK, value[USERNICK]),
|
||||
arg, logs.FileLineMeta(logs.FileLine(-1)),
|
||||
arg, logs.FileLineMeta(kit.Select(logs.FileLine(-1), m.Option("log.caller"))),
|
||||
)
|
||||
}
|
||||
func SessLogout(m *ice.Message, arg ...string) {
|
||||
|
@ -66,12 +66,13 @@ func init() {
|
||||
m.Push(mdb.TIME, m.Time())
|
||||
m.Push(mdb.NAME, value[mdb.NAME])
|
||||
period := kit.Int64(value[PERIOD])
|
||||
m.Push("rest", period-time.Now().Unix()%period)
|
||||
m.Push("code", _totp_get(value[SECRET], kit.Int(value[NUMBER]), period))
|
||||
m.Push(mdb.EXPIRE, period-time.Now().Unix()%period)
|
||||
m.Push(mdb.VALUE, _totp_get(value[SECRET], kit.Int(value[NUMBER]), period))
|
||||
if len(arg) > 0 {
|
||||
m.PushQRCode(mdb.SCAN, kit.Format(m.Config(mdb.LINK), value[mdb.NAME], value[SECRET]))
|
||||
m.Echo(_totp_get(value[SECRET], kit.Int(value[NUMBER]), kit.Int64(value[PERIOD])))
|
||||
}
|
||||
m.StatusTimeCount()
|
||||
})
|
||||
}},
|
||||
})
|
||||
|
@ -33,7 +33,6 @@ func _daemon_exec(m *ice.Message, cmd *exec.Cmd) {
|
||||
}
|
||||
mdb.HashSelectUpdate(m, h, func(value ice.Map) { value[PID] = cmd.Process.Pid })
|
||||
m.Echo("%d", cmd.Process.Pid)
|
||||
|
||||
m.Go(func() {
|
||||
if e := cmd.Wait(); !m.Warn(e, ice.ErrNotStart, cmd.Args) && cmd.ProcessState.ExitCode() == 0 {
|
||||
m.Cost(CODE, cmd.ProcessState.ExitCode(), ctx.ARGS, cmd.Args)
|
||||
@ -105,7 +104,7 @@ const DAEMON = "daemon"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
DAEMON: {Name: "daemon hash auto start prunes", Help: "守护进程", Actions: ice.MergeActions(ice.Actions{
|
||||
DAEMON: {Name: "daemon hash auto", Help: "守护进程", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashPrunesValue(m, mdb.CACHE_CLEAR_ON_EXIT, ice.TRUE)
|
||||
}},
|
||||
@ -134,17 +133,16 @@ func init() {
|
||||
case START:
|
||||
m.PushButton(RESTART, STOP)
|
||||
default:
|
||||
m.PushButton(mdb.REMOVE)
|
||||
m.PushButton(START, mdb.REMOVE)
|
||||
}
|
||||
}); len(arg) == 0 || m.Length() > 0 {
|
||||
if len(arg) == 0 {
|
||||
m.Action(START, mdb.PRUNES)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if len(arg) == 1 {
|
||||
arg = kit.Split(arg[0])
|
||||
}
|
||||
if _daemon_exec(m, _system_cmd(m, arg...)); IsSuccess(m) && m.Append(CMD_ERR) == "" {
|
||||
if _daemon_exec(m, _system_cmd(m, kit.Simple(kit.Split(arg[0]), arg[1:])...)); IsSuccess(m) && m.Append(CMD_ERR) == "" {
|
||||
m.SetAppend()
|
||||
}
|
||||
}},
|
||||
|
@ -48,14 +48,14 @@ func init() {
|
||||
}
|
||||
}},
|
||||
RESTART: {Hand: func(m *ice.Message, arg ...string) { m.Cmd(gdb.SIGNAL, gdb.RESTART) }},
|
||||
STOP: {Hand: func(m *ice.Message, arg ...string) { m.Cmd(gdb.SIGNAL, gdb.STOP) }},
|
||||
STOP: {Hand: func(m *ice.Message, arg ...string) { m.Cmd(gdb.SIGNAL, gdb.STOP) }},
|
||||
}, Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
m.Cmdy(RUNTIME, BOOTINFO)
|
||||
return
|
||||
}
|
||||
for {
|
||||
if logs.Println("run %s", kit.Join(arg, ice.SP)); IsSuccess(m.Sleep("1s", SYSTEM, arg)) {
|
||||
if logs.Println("run %s", kit.Join(arg, ice.SP)); IsSuccess(m.Cmd(SYSTEM, arg)) {
|
||||
logs.Println(ice.EXIT)
|
||||
break
|
||||
}
|
||||
|
@ -25,20 +25,9 @@ const MIRRORS = "mirrors"
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
MIRRORS: {Name: "mirrors cli auto", Help: "软件镜像", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Conf(m.PrefixKey(), kit.Keys(mdb.HASH), "")
|
||||
IsAlpine(m, "curl")
|
||||
IsAlpine(m, "make")
|
||||
IsAlpine(m, "gcc")
|
||||
IsAlpine(m, "vim")
|
||||
IsAlpine(m, "tmux")
|
||||
if IsAlpine(m, "git"); !IsAlpine(m, "go", "go git") {
|
||||
mdb.ZoneInsert(m, CLI, "go", CMD, kit.Format("install download https://golang.google.cn/dl/go1.15.5.%s-%s.tar.gz usr/local", runtime.GOOS, runtime.GOARCH))
|
||||
}
|
||||
}},
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { m.Conf(m.PrefixKey(), kit.Keys(mdb.HASH), "") }},
|
||||
mdb.INSERT: {Name: "insert cli osid cmd"},
|
||||
ALPINE: {Name: "alpine cli cmd", Hand: func(m *ice.Message, arg ...string) { IsAlpine(m, arg...) }},
|
||||
CMD: {Name: "cmd cli osid", Help: "安装", Hand: func(m *ice.Message, arg ...string) {
|
||||
CMD: {Name: "cmd cli osid", Hand: func(m *ice.Message, arg ...string) {
|
||||
osid := kit.Select(m.Conf(RUNTIME, kit.Keys(HOST, OSID)), m.Option(OSID))
|
||||
mdb.ZoneSelectCB(m, m.Option(CLI), func(value ice.Map) {
|
||||
if osid != "" && strings.Contains(osid, kit.Format(value[OSID])) {
|
||||
@ -46,14 +35,14 @@ func init() {
|
||||
}
|
||||
})
|
||||
}},
|
||||
ALPINE: {Name: "alpine cli cmd", Hand: func(m *ice.Message, arg ...string) { IsAlpine(m, arg...) }},
|
||||
}, mdb.ZoneAction(mdb.SHORT, CLI, mdb.FIELD, "time,id,osid,cmd"))},
|
||||
})
|
||||
}
|
||||
|
||||
func osid(m *ice.Message, sys string) bool {
|
||||
func release(m *ice.Message) string {
|
||||
osid := runtime.GOOS
|
||||
m.Option(ice.MSG_USERROLE, aaa.ROOT)
|
||||
m.Cmd(nfs.CAT, "/etc/os-release", func(text string) {
|
||||
m.Cmd(nfs.CAT, "/etc/os-release", kit.Dict(ice.MSG_USERROLE, aaa.ROOT), func(text string) {
|
||||
if ls := kit.Split(text, ice.EQ); len(ls) > 1 {
|
||||
switch ls[0] {
|
||||
case "ID", "ID_LIKE":
|
||||
@ -61,20 +50,20 @@ func osid(m *ice.Message, sys string) bool {
|
||||
}
|
||||
}
|
||||
})
|
||||
if strings.Contains(osid, sys) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
return osid
|
||||
}
|
||||
func insert(m *ice.Message, cmd string, arg ...string) bool {
|
||||
func insert(m *ice.Message, sys, cmd string, arg ...string) bool {
|
||||
if !strings.Contains(release(m), sys) {
|
||||
return false
|
||||
}
|
||||
if len(arg) > 0 {
|
||||
m.Go(func() {
|
||||
m.Sleep300ms()
|
||||
m.Cmd(mdb.INSERT, kit.Keys(CLI, MIRRORS), "", mdb.ZONE, arg[0], OSID, ALPINE, CMD, cmd+ice.SP+kit.Select(arg[0], arg, 1))
|
||||
m.Cmd(mdb.INSERT, kit.Keys(CLI, MIRRORS), "", mdb.ZONE, arg[0], OSID, sys, CMD, cmd+ice.SP+kit.Select(arg[0], arg, 1))
|
||||
})
|
||||
}
|
||||
return true
|
||||
}
|
||||
func IsAlpine(m *ice.Message, arg ...string) bool { return osid(m, ALPINE) && insert(m, "system apk add", arg...) }
|
||||
func IsCentos(m *ice.Message, arg ...string) bool { return osid(m, CENTOS) && insert(m, "yum install -y", arg...) }
|
||||
func IsUbuntu(m *ice.Message, arg ...string) bool { return osid(m, UBUNTU) && insert(m, "apt get -y", arg...) }
|
||||
func IsAlpine(m *ice.Message, arg ...string) bool { return insert(m, ALPINE, "system apk add", arg...) }
|
||||
func IsCentos(m *ice.Message, arg ...string) bool { return insert(m, CENTOS, "yum install -y", arg...) }
|
||||
func IsUbuntu(m *ice.Message, arg ...string) bool { return insert(m, UBUNTU, "apt get -y", arg...) }
|
||||
|
@ -14,7 +14,7 @@ import (
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
var _trans_web = map[string]color.Color{
|
||||
var _color_map = map[string]color.Color{
|
||||
BLACK: color.RGBA{0, 0, 0, DARK},
|
||||
RED: color.RGBA{DARK, 0, 0, DARK},
|
||||
GREEN: color.RGBA{0, DARK, 0, DARK},
|
||||
@ -27,11 +27,7 @@ var _trans_web = map[string]color.Color{
|
||||
|
||||
func _parse_color(str string) color.Color {
|
||||
if str == RANDOM {
|
||||
list := []string{}
|
||||
for k := range _trans_web {
|
||||
list = append(list, k)
|
||||
}
|
||||
kit.Sort(list)
|
||||
list := kit.SortedKey(_color_map)
|
||||
str = list[rand.Intn(len(list))]
|
||||
}
|
||||
if strings.HasPrefix(str, "#") {
|
||||
@ -47,7 +43,7 @@ func _parse_color(str string) color.Color {
|
||||
}
|
||||
}
|
||||
}
|
||||
return _trans_web[str]
|
||||
return _color_map[str]
|
||||
}
|
||||
func _parse_cli_color(str string) string {
|
||||
res := 0
|
||||
@ -67,7 +63,6 @@ func _qrcode_cli(m *ice.Message, text string) {
|
||||
qr, _ := qrcode.New(text, qrcode.Medium)
|
||||
fg := _parse_cli_color(m.Option(FG))
|
||||
bg := _parse_cli_color(m.Option(BG))
|
||||
|
||||
data := qr.Bitmap()
|
||||
for i, row := range data {
|
||||
if n := len(data); i < 3 || i >= n-3 {
|
||||
@ -77,7 +72,6 @@ func _qrcode_cli(m *ice.Message, text string) {
|
||||
if n := len(row); i < 3 || i >= n-3 {
|
||||
continue
|
||||
}
|
||||
|
||||
m.Echo("\033[4%sm \033[0m", kit.Select(bg, fg, col))
|
||||
}
|
||||
m.Echo(ice.NL)
|
||||
@ -88,7 +82,6 @@ func _qrcode_web(m *ice.Message, text 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)
|
||||
}
|
||||
@ -119,27 +112,26 @@ const QRCODE = "qrcode"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
QRCODE: {Name: "qrcode text@key fg@key bg@key size auto", Help: "二维码", Actions: ice.Actions{
|
||||
QRCODE: {Name: "qrcode text fg@key bg@key size auto", Help: "二维码", Actions: ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
ice.AddRender(ice.RENDER_QRCODE, func(m *ice.Message, cmd string, args ...ice.Any) string {
|
||||
ice.AddRender(ice.RENDER_QRCODE, func(m *ice.Message, args ...ice.Any) string {
|
||||
return m.Cmd(QRCODE, kit.Simple(args...)).Result()
|
||||
})
|
||||
}},
|
||||
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) {
|
||||
switch arg[0] {
|
||||
case mdb.TEXT:
|
||||
m.Push(arg[0], "hi", "hello", "world")
|
||||
case FG, BG:
|
||||
m.Push(arg[0], RED, GREEN, BLUE)
|
||||
}
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Option(SIZE, kit.Select("240", arg, 3))
|
||||
m.Option(BG, kit.Select(kit.Select(WHITE, BLACK, m.Option("topic") == BLACK), arg, 2))
|
||||
m.Option(FG, kit.Select(kit.Select(BLUE, CYAN, m.Option("topic") == BLACK), arg, 1))
|
||||
m.Option(FG, kit.Select(kit.Select(BLUE, CYAN, m.Option(ice.TOPIC) == BLACK), arg, 1))
|
||||
m.Option(BG, kit.Select(kit.Select(WHITE, BLACK, m.Option(ice.TOPIC) == BLACK), arg, 2))
|
||||
if m.IsCliUA() {
|
||||
_qrcode_cli(m, kit.Select(kit.Select(ice.Info.Make.Domain, ice.Info.Domain), arg, 0))
|
||||
} else {
|
||||
m.Option(SIZE, kit.Select(kit.Format(kit.Min(480, kit.Int(m.Option(ice.HEIGHT)), kit.Int(m.Option(ice.WIDTH)))), arg, 3))
|
||||
m.Debug("what %v", m.Option(SIZE))
|
||||
_qrcode_web(m, kit.Select(m.Option(ice.MSG_USERWEB), arg, 0))
|
||||
m.StatusTime(mdb.LINK, kit.Select(m.Option(ice.MSG_USERWEB), arg, 0))
|
||||
}
|
||||
|
@ -21,22 +21,13 @@ func _runtime_init(m *ice.Message) {
|
||||
})
|
||||
m.Conf(RUNTIME, kit.Keys(HOST, GOARCH), runtime.GOARCH)
|
||||
m.Conf(RUNTIME, kit.Keys(HOST, GOOS), runtime.GOOS)
|
||||
m.Conf(RUNTIME, kit.Keys(HOST, OSID), release(m))
|
||||
m.Conf(RUNTIME, kit.Keys(HOST, PID), os.Getpid())
|
||||
m.Conf(RUNTIME, kit.Keys(HOST, PWD), kit.Path(""))
|
||||
m.Conf(RUNTIME, kit.Keys(HOST, HOME), kit.Env(HOME))
|
||||
m.Conf(RUNTIME, kit.Keys(HOST, MAXPROCS), runtime.GOMAXPROCS(0))
|
||||
m.Conf(RUNTIME, mdb.META, "")
|
||||
m.Conf(RUNTIME, mdb.HASH, "")
|
||||
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(HOST, OSID), osid)
|
||||
for _, k := range ENV_LIST {
|
||||
switch m.Conf(RUNTIME, kit.Keys(CONF, k), kit.Env(k)); k {
|
||||
case CTX_PID:
|
||||
@ -47,7 +38,6 @@ func _runtime_init(m *ice.Message) {
|
||||
ice.Info.CtxRiver = kit.Env(k)
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
@ -60,10 +50,7 @@ func _runtime_init(m *ice.Message) {
|
||||
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)
|
||||
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, mdb.COUNT), kit.Int(m.Conf(RUNTIME, kit.Keys(BOOT, mdb.COUNT)))+1)
|
||||
aaa.UserRoot(ice.Pulse, ice.Info.UserName)
|
||||
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 {
|
||||
@ -73,6 +60,7 @@ func _runtime_init(m *ice.Message) {
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, mdb.HASH), kit.Hashs(f))
|
||||
}
|
||||
}
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, mdb.COUNT), kit.Int(m.Conf(RUNTIME, kit.Keys(BOOT, mdb.COUNT)))+1)
|
||||
}
|
||||
func _runtime_hostinfo(m *ice.Message) {
|
||||
m.Push("nCPU", strings.Count(m.Cmdx(nfs.CAT, "/proc/cpuinfo"), "processor"))
|
||||
@ -94,12 +82,6 @@ func _runtime_diskinfo(m *ice.Message) {
|
||||
ctx.DisplayStory(m, "pie.js?field=Size")
|
||||
}
|
||||
|
||||
func NodeInfo(m *ice.Message, kind, name string) {
|
||||
m.Conf(RUNTIME, kit.Keys(NODE, mdb.TIME), m.Time())
|
||||
ice.Info.NodeType = m.Conf(RUNTIME, kit.Keys(NODE, mdb.TYPE), kind)
|
||||
ice.Info.NodeName = m.Conf(RUNTIME, kit.Keys(NODE, mdb.NAME), strings.ReplaceAll(name, ice.PT, "_"))
|
||||
}
|
||||
|
||||
const (
|
||||
MAKE = "make"
|
||||
TEST = "test"
|
||||
@ -207,7 +189,7 @@ func init() {
|
||||
m.Sort(nfs.FILE).StatusTimeCount()
|
||||
}},
|
||||
CMD: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.OptionFields(ctx.INDEX, mdb.NAME, mdb.HELP)
|
||||
m.OptionFields(ctx.INDEX, mdb.NAME, mdb.HELP, nfs.FILE)
|
||||
m.Cmdy(ctx.COMMAND, mdb.SEARCH, ctx.COMMAND).StatusTimeCount()
|
||||
}},
|
||||
ENV: {Hand: func(m *ice.Message, arg ...string) {
|
||||
@ -233,3 +215,8 @@ func init() {
|
||||
}},
|
||||
})
|
||||
}
|
||||
func NodeInfo(m *ice.Message, kind, name string) {
|
||||
m.Conf(RUNTIME, kit.Keys(NODE, mdb.TIME), m.Time())
|
||||
ice.Info.NodeType = m.Conf(RUNTIME, kit.Keys(NODE, mdb.TYPE), kind)
|
||||
ice.Info.NodeName = m.Conf(RUNTIME, kit.Keys(NODE, mdb.NAME), strings.ReplaceAll(name, ice.PT, "_"))
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ func _system_cmd(m *ice.Message, arg ...string) *exec.Cmd {
|
||||
}
|
||||
}
|
||||
cmd := exec.Command(bin, arg[1:]...)
|
||||
if cmd.Dir = m.Option(CMD_DIR); len(cmd.Dir) > 0 {
|
||||
if cmd.Dir = kit.TrimPath(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)
|
||||
}
|
||||
|
@ -63,6 +63,7 @@ func _command_search(m *ice.Message, kind, name, text string) {
|
||||
kit.SimpleKV("", s.Cap(ice.CTX_FOLLOW), cmd.Name, cmd.Help),
|
||||
CONTEXT, s.Cap(ice.CTX_FOLLOW), COMMAND, key, mdb.HELP, cmd.Help,
|
||||
INDEX, kit.Keys(s.Cap(ice.CTX_FOLLOW), key),
|
||||
nfs.FILE, FileURI(cmd.GetFileLine()),
|
||||
)
|
||||
})
|
||||
}
|
||||
@ -123,8 +124,8 @@ 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 {
|
||||
AddRunChecker(func(m *ice.Message, cmd, sub string, arg ...string) bool {
|
||||
switch sub {
|
||||
case mdb.REMOVE:
|
||||
m.Cmd(CONFIG, mdb.REMOVE, cmd)
|
||||
return true
|
||||
@ -173,8 +174,11 @@ func CmdAction(args ...ice.Any) ice.Actions {
|
||||
}
|
||||
|
||||
func FileURI(dir string) string {
|
||||
if strings.Contains(dir, "go/pkg/mod") {
|
||||
return path.Join("/require", strings.Split(dir, "go/pkg/mod")[1])
|
||||
if dir == "" {
|
||||
return ""
|
||||
}
|
||||
if strings.Contains(dir, "/go/pkg/mod/") {
|
||||
return path.Join("/require", strings.Split(dir, "/go/pkg/mod/")[1])
|
||||
}
|
||||
if ice.Info.Make.Path != "" && strings.HasPrefix(dir, ice.Info.Make.Path+ice.PS) {
|
||||
dir = strings.TrimPrefix(dir, ice.Info.Make.Path+ice.PS)
|
||||
@ -194,27 +198,19 @@ func FileURI(dir string) string {
|
||||
return dir
|
||||
}
|
||||
func FileCmd(dir string) string {
|
||||
dir = strings.Split(dir, ice.DF)[0]
|
||||
dir = strings.ReplaceAll(dir, ".js", ".go")
|
||||
dir = strings.ReplaceAll(dir, ".sh", ".go")
|
||||
return FileURI(dir)
|
||||
return FileURI(kit.ExtChange(strings.Split(dir, ice.DF)[0], nfs.GO))
|
||||
}
|
||||
func AddFileCmd(dir, key string) {
|
||||
ice.Info.File[FileCmd(dir)] = key
|
||||
}
|
||||
func GetFileCmd(dir string) string {
|
||||
if strings.HasPrefix(dir, "usr/") {
|
||||
// p := ice.Pulse.Cmdx("cli.system", "git", "config", "remote.origin.url", kit.Dict("cmd_dir", path.Dir(dir)))
|
||||
// p = strings.Replace(strings.TrimSpace(p), "https://", "/require/", 1)
|
||||
// dir = path.Join(p, strings.Join(strings.Split(dir, "/")[2:], "/"))
|
||||
}
|
||||
if strings.HasPrefix(dir, ".ish/pluged/") {
|
||||
dir = strings.Replace(dir, ".ish/pluged/", "/require/", 1)
|
||||
if strings.HasPrefix(dir, ice.ISH_PLUGED) {
|
||||
dir = path.Join("/require", strings.TrimPrefix(dir, ice.ISH_PLUGED))
|
||||
}
|
||||
if strings.HasPrefix(dir, "require/") {
|
||||
dir = "/" + dir
|
||||
dir = ice.PS + dir
|
||||
}
|
||||
for _, dir := range []string{dir, path.Join("/require/", ice.Info.Make.Module, dir), path.Join("/require/", ice.Info.Make.Module, ice.SRC, dir)} {
|
||||
for _, dir := range []string{dir, path.Join("/require", ice.Info.Make.Module, dir), path.Join("/require", ice.Info.Make.Module, ice.SRC, dir)} {
|
||||
if cmd, ok := ice.Info.File[FileCmd(dir)]; ok {
|
||||
return cmd
|
||||
}
|
||||
@ -228,11 +224,12 @@ func GetFileCmd(dir string) string {
|
||||
func GetCmdFile(m *ice.Message, cmds string) (file string) {
|
||||
m.Search(cmds, func(key string, cmd *ice.Command) {
|
||||
if cmd.RawHand == nil {
|
||||
file = kit.Split(logs.FileLines(cmd.Hand), ":")[0]
|
||||
file = kit.Split(logs.FileLines(cmd.Hand), ice.DF)[0]
|
||||
} else {
|
||||
for k, v := range ice.Info.File {
|
||||
if v == cmds {
|
||||
file = strings.Replace(k, "/require/", ".ish/pluged/", 1)
|
||||
file = strings.Replace(k, "/require/", ice.ISH_PLUGED, 1)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -242,14 +239,13 @@ func GetCmdFile(m *ice.Message, cmds string) (file string) {
|
||||
func TravelCmd(m *ice.Message, cb func(key, file, line string)) {
|
||||
m.Travel(func(p *ice.Context, s *ice.Context, key string, cmd *ice.Command) {
|
||||
if key[0] == '/' || key[0] == '_' {
|
||||
return // 内部命令
|
||||
return
|
||||
}
|
||||
|
||||
ls := kit.Split(cmd.GetFileLine(), ":")
|
||||
ls := kit.Split(cmd.GetFileLine(), ice.DF)
|
||||
if len(ls) > 1 {
|
||||
cb(kit.Keys(s.Cap(ice.CTX_FOLLOW), key), strings.TrimPrefix(ls[0], kit.Path("")+ice.PS), ls[1])
|
||||
} else {
|
||||
m.Warn(true, "not founc", cmd.Name)
|
||||
m.Warn(true, "not found", cmd.Name, cmd.GetFileLine())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ func _config_save(m *ice.Message, name string, arg ...string) {
|
||||
name = path.Join(ice.VAR_CONF, name)
|
||||
if f, p, e := miss.CreateFile(name); m.Assert(e) {
|
||||
defer f.Close()
|
||||
|
||||
defer m.Echo(p)
|
||||
msg := m.Spawn(m.Source())
|
||||
data := ice.Map{}
|
||||
for _, k := range arg {
|
||||
@ -24,25 +24,20 @@ func _config_save(m *ice.Message, name string, arg ...string) {
|
||||
data[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
// 保存配置
|
||||
if s, e := json.MarshalIndent(data, "", " "); m.Assert(e) {
|
||||
if _, e := f.Write(s); m.Assert(e) {
|
||||
if s, e := json.MarshalIndent(data, "", " "); !m.Warn(e) {
|
||||
if _, e := f.Write(s); !m.Warn(e) {
|
||||
|
||||
}
|
||||
}
|
||||
m.Echo(p)
|
||||
}
|
||||
}
|
||||
func _config_load(m *ice.Message, name string, arg ...string) {
|
||||
name = path.Join(ice.VAR_CONF, name)
|
||||
if f, e := miss.OpenFile(name); e == nil {
|
||||
defer f.Close()
|
||||
|
||||
msg := m.Spawn(m.Source())
|
||||
data := ice.Map{}
|
||||
json.NewDecoder(f).Decode(&data)
|
||||
|
||||
// 加载配置
|
||||
for k, v := range data {
|
||||
msg.Search(k, func(p *ice.Context, s *ice.Context, key string) {
|
||||
if s.Configs[key] == nil {
|
||||
@ -59,10 +54,8 @@ func _config_make(m *ice.Message, key string, arg ...string) {
|
||||
if strings.HasPrefix(arg[1], "@") {
|
||||
arg[1] = msg.Cmdx(nfs.CAT, arg[1][1:])
|
||||
}
|
||||
// 修改配置
|
||||
msg.Confv(key, arg[0], kit.Parse(nil, "", arg[1:]...))
|
||||
}
|
||||
|
||||
if len(arg) > 0 {
|
||||
m.Echo(kit.Formats(msg.Confv(key, arg[0])))
|
||||
} else {
|
||||
@ -72,9 +65,8 @@ func _config_make(m *ice.Message, key string, arg ...string) {
|
||||
func _config_list(m *ice.Message) {
|
||||
for k, v := range m.Source().Configs {
|
||||
if k[0] == '/' || k[0] == '_' {
|
||||
continue // 内部配置
|
||||
continue
|
||||
}
|
||||
|
||||
m.Push(mdb.KEY, k)
|
||||
m.Push(mdb.NAME, v.Name)
|
||||
m.Push(mdb.VALUE, kit.Format(v.Value))
|
||||
@ -85,27 +77,19 @@ func _config_list(m *ice.Message) {
|
||||
const (
|
||||
SAVE = "save"
|
||||
LOAD = "load"
|
||||
RICH = "rich"
|
||||
GROW = "grow"
|
||||
)
|
||||
const CONFIG = "config"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
CONFIG: {Name: "config key auto reset", Help: "配置", Actions: ice.Actions{
|
||||
SAVE: {Name: "save", Help: "保存", Hand: func(m *ice.Message, arg ...string) {
|
||||
CONFIG: {Name: "config key auto", Help: "配置", Actions: ice.Actions{
|
||||
SAVE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
_config_save(m, arg[0], arg[1:]...)
|
||||
}},
|
||||
LOAD: {Name: "load", Help: "加载", Hand: func(m *ice.Message, arg ...string) {
|
||||
LOAD: {Hand: func(m *ice.Message, arg ...string) {
|
||||
_config_load(m, arg[0], arg[1:]...)
|
||||
}},
|
||||
RICH: {Name: "rich", Help: "富有", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(mdb.INSERT, arg[0], arg[1], mdb.HASH, arg[2:])
|
||||
}},
|
||||
GROW: {Name: "grow", Help: "成长", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(mdb.INSERT, arg[0], arg[1], mdb.LIST, arg[2:])
|
||||
}},
|
||||
"list": {Name: "list", Help: "列表", Hand: func(m *ice.Message, arg ...string) {
|
||||
"list": {Hand: func(m *ice.Message, arg ...string) {
|
||||
list := []ice.Any{}
|
||||
for _, v := range arg[2:] {
|
||||
list = append(list, v)
|
||||
|
@ -64,7 +64,7 @@ func init() {
|
||||
func Inputs(m *ice.Message, field string) bool {
|
||||
switch strings.TrimPrefix(field, "extra.") {
|
||||
case ice.POD:
|
||||
m.Cmdy("route")
|
||||
m.Cmdy(ice.SPACE)
|
||||
case ice.CTX:
|
||||
m.Cmdy(CONTEXT)
|
||||
case ice.CMD:
|
||||
|
@ -1,7 +0,0 @@
|
||||
chapter "ctx"
|
||||
|
||||
field "模块" context
|
||||
field "命令" command
|
||||
field "配置" config
|
||||
field "消息" message
|
||||
|
@ -6,44 +6,39 @@ import (
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
"shylinux.com/x/toolkits/logs"
|
||||
)
|
||||
|
||||
func ProcessCommand(m *ice.Message, cmd string, val []string, arg ...string) {
|
||||
if len(arg) > 0 && arg[0] == ice.RUN {
|
||||
m.Cmdy(cmd, arg[1:])
|
||||
return
|
||||
func Display(m *ice.Message, file string, arg ...ice.Any) *ice.Message {
|
||||
if file == "" {
|
||||
file = kit.Keys(kit.FileName(2), nfs.JS)
|
||||
}
|
||||
|
||||
m.Cmdy(COMMAND, cmd)
|
||||
m.ProcessField(cmd, ice.RUN)
|
||||
m.Push(ice.ARG, kit.Format(val))
|
||||
}
|
||||
func ProcessCommandOpt(m *ice.Message, arg []string, args ...string) {
|
||||
if len(arg) > 0 && arg[0] == ice.RUN {
|
||||
return
|
||||
if !strings.HasPrefix(file, ice.PS) && !strings.HasPrefix(file, ice.HTTP) {
|
||||
file = path.Join(ice.PS, path.Join(path.Dir(FileURI(logs.FileLines(2))), file))
|
||||
}
|
||||
m.Push("opt", kit.Format(m.OptionSimple(args...)))
|
||||
return DisplayBase(m, file, arg...)
|
||||
}
|
||||
func DisplayTable(m *ice.Message, arg ...ice.Any) *ice.Message { // /plugin/story/file
|
||||
return m.Display(kit.MergeURL("/plugin/table.js", arg...))
|
||||
func DisplayTable(m *ice.Message, arg ...ice.Any) *ice.Message {
|
||||
return DisplayBase(m, "/plugin/table.js", arg...)
|
||||
}
|
||||
func DisplayTableCard(m *ice.Message, arg ...ice.Any) *ice.Message { // /plugin/story/file
|
||||
return m.Display(kit.MergeURL("/plugin/table.js", "style", "card"))
|
||||
func DisplayTableCard(m *ice.Message, arg ...ice.Any) *ice.Message {
|
||||
return DisplayTable(m, "style", "card")
|
||||
}
|
||||
func DisplayStory(m *ice.Message, file string, arg ...ice.Any) *ice.Message { // /plugin/story/file
|
||||
if !strings.HasPrefix(file, ice.HTTP) && !strings.HasPrefix(file, ice.PS) {
|
||||
func DisplayStory(m *ice.Message, file string, arg ...ice.Any) *ice.Message {
|
||||
if !strings.HasPrefix(file, ice.PS) && !strings.HasPrefix(file, ice.HTTP) {
|
||||
file = path.Join(ice.PLUGIN_STORY, file)
|
||||
}
|
||||
return DisplayBase(m, file, arg...)
|
||||
}
|
||||
func DisplayStoryJSON(m *ice.Message, arg ...ice.Any) *ice.Message { // /plugin/story/json.js
|
||||
func DisplayStoryJSON(m *ice.Message, arg ...ice.Any) *ice.Message {
|
||||
return DisplayStory(m, "json", arg...)
|
||||
}
|
||||
func DisplayStorySpide(m *ice.Message, arg ...ice.Any) *ice.Message { // /plugin/story/json.js
|
||||
func DisplayStorySpide(m *ice.Message, arg ...ice.Any) *ice.Message {
|
||||
return DisplayStory(m, "spide", arg...).StatusTimeCount()
|
||||
}
|
||||
func DisplayLocal(m *ice.Message, file string, arg ...ice.Any) *ice.Message { // /plugin/local/file
|
||||
func DisplayLocal(m *ice.Message, file string, arg ...ice.Any) *ice.Message {
|
||||
if file == "" {
|
||||
file = path.Join(kit.PathName(2), kit.Keys(kit.FileName(2), ice.JS))
|
||||
}
|
||||
@ -53,10 +48,7 @@ func DisplayLocal(m *ice.Message, file string, arg ...ice.Any) *ice.Message { //
|
||||
return DisplayBase(m, file, arg...)
|
||||
}
|
||||
func DisplayBase(m *ice.Message, file string, arg ...ice.Any) *ice.Message {
|
||||
if !strings.Contains(file, ice.PT) {
|
||||
file += ".js"
|
||||
}
|
||||
m.Option(ice.MSG_DISPLAY, kit.MergeURL(ice.DisplayBase(file)[ice.DISPLAY], arg...))
|
||||
m.Option(ice.MSG_DISPLAY, kit.MergeURL(kit.ExtChange(file, nfs.JS), arg...))
|
||||
return m
|
||||
}
|
||||
func Toolkit(m *ice.Message, arg ...string) {
|
@ -27,6 +27,21 @@ func Process(m *ice.Message, key string, args []string, arg ...string) {
|
||||
ProcessField(m, key, args, arg...)
|
||||
}
|
||||
}
|
||||
func ProcessCommand(m *ice.Message, cmd string, val []string, arg ...string) {
|
||||
if len(arg) > 0 && arg[0] == ice.RUN {
|
||||
m.Cmdy(cmd, arg[1:])
|
||||
return
|
||||
}
|
||||
m.Cmdy(COMMAND, cmd)
|
||||
m.ProcessField(cmd, ice.RUN)
|
||||
m.Push(ice.ARG, kit.Format(val))
|
||||
}
|
||||
func ProcessCommandOpt(m *ice.Message, arg []string, args ...string) {
|
||||
if len(arg) > 0 && arg[0] == ice.RUN {
|
||||
return
|
||||
}
|
||||
m.Push("opt", kit.Format(m.OptionSimple(args...)))
|
||||
}
|
||||
func ProcessField(m *ice.Message, cmd string, args []string, arg ...string) {
|
||||
cmd = kit.Select(m.PrefixKey(), cmd)
|
||||
if len(arg) == 0 || arg[0] != ice.RUN {
|
||||
@ -46,26 +61,14 @@ func ProcessFloat(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(COMMAND, arg[0])
|
||||
}
|
||||
|
||||
func ProcessHold(m *ice.Message, text ...ice.Any) {
|
||||
m.Process(ice.PROCESS_HOLD, text...)
|
||||
}
|
||||
func ProcessOpen(m *ice.Message, url string) {
|
||||
m.Process(ice.PROCESS_OPEN, url)
|
||||
}
|
||||
func ProcessRefresh(m *ice.Message, arg ...string) {
|
||||
m.ProcessRefresh(kit.Select("300ms", arg, 0))
|
||||
}
|
||||
func ProcessRewrite(m *ice.Message, arg ...ice.Any) {
|
||||
m.ProcessRewrite(arg...)
|
||||
}
|
||||
func ProcessRefresh(m *ice.Message, arg ...string) { m.ProcessRefresh(arg...) }
|
||||
func ProcessRewrite(m *ice.Message, arg ...ice.Any) { m.ProcessRewrite(arg...) }
|
||||
func ProcessHold(m *ice.Message, text ...ice.Any) { m.Process(ice.PROCESS_HOLD, text...) }
|
||||
func ProcessOpen(m *ice.Message, url string) { m.Process(ice.PROCESS_OPEN, url) }
|
||||
|
||||
func ProcessAction() ice.Actions {
|
||||
return ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
AddProcess(m.CommandKey(), m.PrefixKey())
|
||||
}},
|
||||
PROCESS: {Name: "process", Help: "响应", Hand: func(m *ice.Message, arg ...string) {
|
||||
ProcessField(m, m.PrefixKey(), arg, arg...)
|
||||
}},
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { AddProcess(m.CommandKey(), m.PrefixKey()) }},
|
||||
PROCESS: {Hand: func(m *ice.Message, arg ...string) { ProcessField(m, m.PrefixKey(), arg, arg...) }},
|
||||
}
|
||||
}
|
||||
|
@ -274,7 +274,7 @@ func HashPrunes(m *ice.Message, cb func(Maps) bool) *ice.Message {
|
||||
}
|
||||
HashRemove(m, HashShort(m), value[HashShort(m)])
|
||||
})
|
||||
return m
|
||||
return m.StatusTimeCount()
|
||||
}
|
||||
func HashExport(m *ice.Message, arg ...Any) *ice.Message {
|
||||
return m.Cmdy(EXPORT, m.PrefixKey(), "", HASH, arg)
|
||||
|
@ -34,7 +34,7 @@ func _dream_list(m *ice.Message) *ice.Message {
|
||||
return m.Sort("status,type,name", ice.STR, ice.STR, ice.STR_R).StatusTimeCount(cli.START, len(list))
|
||||
}
|
||||
func _dream_show(m *ice.Message, name string) {
|
||||
if m.Warn(name == "", ice.ErrNotValid) {
|
||||
if m.Warn(name == "", ice.ErrNotValid, mdb.NAME) {
|
||||
return
|
||||
}
|
||||
if !strings.Contains(name, "-") || !strings.HasPrefix(name, "20") {
|
||||
|
@ -181,13 +181,14 @@ func _serve_params(msg *ice.Message, path string) {
|
||||
}
|
||||
}
|
||||
func _serve_handle(key string, cmd *ice.Command, msg *ice.Message, w http.ResponseWriter, r *http.Request) {
|
||||
// 地址参数
|
||||
meta := logs.FileLineMeta("")
|
||||
msg.Options(ice.HEIGHT, "480", ice.WIDTH, "320")
|
||||
if u, e := url.Parse(r.Header.Get(Referer)); e == nil {
|
||||
_serve_params(msg, u.Path)
|
||||
for k, v := range u.Query() {
|
||||
msg.Logs("refer", k, v)
|
||||
msg.Option(k, v)
|
||||
}
|
||||
kit.Fetch(u.Query(), func(k string, v []string) {
|
||||
msg.Logs("refer", k, v, meta)
|
||||
msg.Optionv(k, v)
|
||||
})
|
||||
}
|
||||
_serve_params(msg, r.URL.Path)
|
||||
|
||||
@ -205,14 +206,13 @@ func _serve_handle(key string, cmd *ice.Command, msg *ice.Message, w http.Respon
|
||||
default:
|
||||
r.ParseMultipartForm(kit.Int64(kit.Select("4096", r.Header.Get(ContentLength))))
|
||||
if r.ParseForm(); len(r.PostForm) > 0 {
|
||||
meta := logs.FileLineMeta("")
|
||||
for k, v := range r.PostForm {
|
||||
kit.Fetch(r.PostForm, func(k string, v []string) {
|
||||
if len(v) > 1 {
|
||||
msg.Logs("form", k, len(v), kit.Join(v, ice.SP), meta)
|
||||
} else {
|
||||
msg.Logs("form", k, v, meta)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -230,7 +230,7 @@ func _serve_handle(key string, cmd *ice.Command, msg *ice.Message, w http.Respon
|
||||
msg.Optionv(k, v)
|
||||
}
|
||||
for _, v := range r.Cookies() {
|
||||
msg.Option(v.Name, v.Value)
|
||||
msg.Optionv(v.Name, v.Value)
|
||||
}
|
||||
|
||||
// 用户参数
|
||||
|
@ -21,7 +21,7 @@ import (
|
||||
)
|
||||
|
||||
func _share_render(m *ice.Message, arg ...string) {
|
||||
ice.AddRender(ice.RENDER_DOWNLOAD, func(msg *ice.Message, cmd string, args ...ice.Any) string {
|
||||
ice.AddRender(ice.RENDER_DOWNLOAD, func(msg *ice.Message, args ...ice.Any) string {
|
||||
list := []string{}
|
||||
if msg.Option(ice.MSG_USERPOD) != "" {
|
||||
list = append(list, ice.POD, msg.Option(ice.MSG_USERPOD))
|
||||
|
@ -55,41 +55,33 @@ func (frame *Frame) Begin(m *ice.Message, arg ...string) ice.Server {
|
||||
return frame
|
||||
}
|
||||
func (frame *Frame) Start(m *ice.Message, arg ...string) bool {
|
||||
meta := logs.FileLineMeta("")
|
||||
list := map[*ice.Context]string{}
|
||||
m.Travel(func(p *ice.Context, s *ice.Context) {
|
||||
if frame, ok := s.Server().(*Frame); ok {
|
||||
if frame.ServeMux != nil {
|
||||
m.Travel(func(p *ice.Context, c *ice.Context) {
|
||||
if f, ok := c.Server().(*Frame); ok {
|
||||
if f.ServeMux != nil {
|
||||
return
|
||||
}
|
||||
frame.ServeMux = http.NewServeMux()
|
||||
meta := logs.FileLineMeta("")
|
||||
|
||||
// 级联路由
|
||||
msg := m.Spawn(s)
|
||||
if pframe, ok := p.Server().(*Frame); ok && pframe.ServeMux != nil {
|
||||
route := ice.PS + s.Name + ice.PS
|
||||
f.ServeMux = http.NewServeMux()
|
||||
msg := m.Spawn(c)
|
||||
if pf, ok := p.Server().(*Frame); ok && pf.ServeMux != nil {
|
||||
route := ice.PS + c.Name + ice.PS
|
||||
msg.Log(ROUTE, "%s <= %s", p.Name, route, meta)
|
||||
pframe.Handle(route, http.StripPrefix(path.Dir(route), frame))
|
||||
list[s] = path.Join(list[p], route)
|
||||
pf.Handle(route, http.StripPrefix(path.Dir(route), f))
|
||||
list[c] = path.Join(list[p], route)
|
||||
}
|
||||
|
||||
// 静态路由
|
||||
m.Confm(SERVE, kit.Keym(nfs.PATH), func(key string, value string) {
|
||||
m.Log(ROUTE, "%s <- %s <- %s", s.Name, key, value, meta)
|
||||
frame.Handle(key, http.StripPrefix(key, http.FileServer(http.Dir(value))))
|
||||
m.Log(ROUTE, "%s <- %s <- %s", c.Name, key, value, meta)
|
||||
f.Handle(key, http.StripPrefix(key, http.FileServer(http.Dir(value))))
|
||||
})
|
||||
|
||||
// 命令路由
|
||||
m.Travel(func(p *ice.Context, sub *ice.Context, k string, x *ice.Command) {
|
||||
if s != sub || k[0] != '/' {
|
||||
m.Travel(func(p *ice.Context, _c *ice.Context, key string, cmd *ice.Command) {
|
||||
if c != _c || key[0] != '/' {
|
||||
return
|
||||
}
|
||||
msg.Log(ROUTE, "%s <- %s", s.Name, k, meta)
|
||||
ice.Info.Route[path.Join(list[s], k)] = ctx.FileCmd(logs.FileLines(x.Hand))
|
||||
frame.HandleFunc(k, func(frame http.ResponseWriter, r *http.Request) {
|
||||
m.TryCatch(msg.Spawn(), true, func(msg *ice.Message) {
|
||||
_serve_handle(k, x, msg, frame, r)
|
||||
})
|
||||
msg.Log(ROUTE, "%s <- %s", c.Name, key, meta)
|
||||
ice.Info.Route[path.Join(list[c], key)] = ctx.FileURI(cmd.GetFileLine())
|
||||
f.HandleFunc(key, func(w http.ResponseWriter, r *http.Request) {
|
||||
m.TryCatch(msg.Spawn(), true, func(msg *ice.Message) { _serve_handle(key, cmd, msg, w, r) })
|
||||
})
|
||||
})
|
||||
}
|
||||
@ -120,7 +112,7 @@ const (
|
||||
SERVE_START = "serve.start"
|
||||
SERVE_STOP = "serve.stop"
|
||||
WEBSITE = "website"
|
||||
|
||||
|
||||
CODE_INNER = "web.code.inner"
|
||||
WIKI_WORD = "web.wiki.word"
|
||||
)
|
||||
|
@ -24,7 +24,7 @@ func _cmd_file(m *ice.Message, arg ...string) bool {
|
||||
case nfs.GO:
|
||||
web.RenderCmd(m, ctx.GetFileCmd(p))
|
||||
case nfs.JS:
|
||||
m.Display(ctx.FileURI(p))
|
||||
ctx.DisplayBase(m, ctx.FileURI(p))
|
||||
web.RenderCmd(m, kit.Select(ctx.CAN_PLUGIN, ctx.GetFileCmd(p)))
|
||||
default:
|
||||
if p = strings.TrimPrefix(p, ice.SRC+ice.PS); nfs.ExistsFile(m, path.Join(ice.SRC, p)) {
|
||||
|
@ -20,8 +20,8 @@ func init() {
|
||||
web.RenderIndex(m, ice.VOLCANOS)
|
||||
return
|
||||
}
|
||||
m.RenderRedirect(kit.MergeURL(m.Option(cli.BACK), ice.MSG_SESSID, aaa.UserRoot(m).Cmdx(web.SPACE, m.Option(web.SPACE), aaa.SESS, mdb.CREATE,
|
||||
aaa.USERNAME, m.Option(ice.MSG_USERNAME), aaa.USERROLE, m.Option(ice.MSG_USERROLE), aaa.USERNICK, m.Option(ice.MSG_USERNICK))))
|
||||
m.RenderRedirect(kit.MergeURL(m.Option(cli.BACK), ice.MSG_SESSID, m.Cmdx(web.SPACE, m.Option(web.SPACE), aaa.SESS, mdb.CREATE,
|
||||
aaa.USERNAME, m.Option(ice.MSG_USERNAME), aaa.USERROLE, m.Option(ice.MSG_USERROLE), aaa.USERNICK, m.Option(ice.MSG_USERNICK), kit.Dict(ice.MSG_USERROLE, aaa.ROOT))))
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
|
||||
// "shylinux.com/x/icebergs/base/web"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
@ -44,6 +45,16 @@ func init() {
|
||||
COMPILE: {Value: kit.Data(cli.ENV, kit.Dict("GOPRIVATE", "shylinux.com,github.com", "GOPROXY", "https://goproxy.cn,direct", "CGO_ENABLED", "0"))},
|
||||
}, Commands: ice.Commands{
|
||||
COMPILE: {Name: "compile arch=amd64,386,mipsle,arm,arm64 os=linux,darwin,windows src=src/main.go@key run binpack relay", Help: "编译", Actions: ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
cli.IsAlpine(m, "curl")
|
||||
cli.IsAlpine(m, "make")
|
||||
cli.IsAlpine(m, "gcc")
|
||||
cli.IsAlpine(m, "vim")
|
||||
cli.IsAlpine(m, "tmux")
|
||||
if cli.IsAlpine(m, "git"); !cli.IsAlpine(m, "go", "go git") {
|
||||
mdb.ZoneInsert(m, cli.CLI, "go", cli.CMD, kit.Format("install download https://golang.google.cn/dl/go1.15.5.%s-%s.tar.gz usr/local", runtime.GOOS, runtime.GOARCH))
|
||||
}
|
||||
}},
|
||||
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(nfs.DIR, ice.SRC, nfs.DIR_CLI_FIELDS, kit.Dict(nfs.DIR_REG, `.*\.go$`)).Sort(nfs.PATH)
|
||||
}},
|
||||
@ -60,7 +71,7 @@ func init() {
|
||||
// web.PushStream(m)
|
||||
main, file, goos, arch := _compile_target(m, arg...)
|
||||
m.Optionv(cli.CMD_ENV, kit.Simple(cli.HOME, kit.Env(cli.HOME), cli.PATH, kit.Env(cli.PATH), m.Configv(cli.ENV), m.Optionv(cli.ENV), cli.GOOS, goos, cli.GOARCH, arch))
|
||||
m.Cmd(cli.SYSTEM, GO, "get", "shylinux.com/x/ice")
|
||||
// m.Cmd(cli.SYSTEM, GO, "get", "shylinux.com/x/ice")
|
||||
if msg := m.Cmd(cli.SYSTEM, GO, cli.BUILD, "-o", file, main, ice.SRC_VERSION_GO, ice.SRC_BINPACK_GO); !cli.IsSuccess(msg) {
|
||||
m.Copy(msg)
|
||||
return
|
||||
|
@ -79,7 +79,7 @@ func _js_exec(m *ice.Message, arg ...string) {
|
||||
ctx.ProcessCommand(m, kit.Select("can.plugin", key), kit.Simple())
|
||||
return
|
||||
}
|
||||
m.Display(path.Join("/require", path.Join(arg[2], arg[1])))
|
||||
ctx.DisplayBase(m, path.Join("/require", path.Join(arg[2], arg[1])))
|
||||
key := ctx.GetFileCmd(kit.Replace(path.Join(arg[2], arg[1]), ".js", ".go"))
|
||||
ctx.ProcessCommand(m, kit.Select("can.code.inner._plugin", key), kit.Simple())
|
||||
return
|
||||
|
@ -41,7 +41,7 @@ func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
SPARK: {Name: "spark [name] text auto field:text value:text", Help: "段落", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
ice.AddRender(ice.RENDER_SCRIPT, func(m *ice.Message, cmd string, args ...ice.Any) string {
|
||||
ice.AddRender(ice.RENDER_SCRIPT, func(m *ice.Message, args ...ice.Any) string {
|
||||
arg := kit.Simple(args...)
|
||||
if m.IsCliUA() {
|
||||
if len(arg) > 1 {
|
||||
|
8
info.go
8
info.go
@ -32,10 +32,10 @@ var Info = struct {
|
||||
Help string
|
||||
File Maps
|
||||
Route Maps
|
||||
index Map
|
||||
Index Map
|
||||
|
||||
merges []MergeHandler
|
||||
render map[string]func(*Message, string, ...Any) string
|
||||
render map[string]func(*Message, ...Any) string
|
||||
Save func(m *Message, key ...string) *Message
|
||||
Load func(m *Message, key ...string) *Message
|
||||
Log func(m *Message, p, l, s string)
|
||||
@ -50,9 +50,9 @@ source: https://shylinux.com/x/icebergs
|
||||
`,
|
||||
File: Maps{},
|
||||
Route: Maps{},
|
||||
index: Map{},
|
||||
Index: Map{},
|
||||
|
||||
render: map[string]func(*Message, string, ...Any) string{},
|
||||
render: map[string]func(*Message, ...Any) string{},
|
||||
Save: func(m *Message, key ...string) *Message { return m },
|
||||
Load: func(m *Message, key ...string) *Message { return m },
|
||||
Log: func(m *Message, p, l, s string) {},
|
||||
|
17
init.go
17
init.go
@ -43,10 +43,7 @@ func (s *Frame) Close(m *Message, arg ...string) bool {
|
||||
}
|
||||
})
|
||||
conf.Close()
|
||||
go func() {
|
||||
m.Sleep3s()
|
||||
os.Exit(kit.Int(Pulse.Option(EXIT)))
|
||||
}()
|
||||
go func() { os.Exit(kit.Int(Pulse.Sleep("30ms").Option(EXIT))) }()
|
||||
return true
|
||||
}
|
||||
func (s *Frame) Spawn(m *Message, c *Context, arg ...string) Server { return &Frame{} }
|
||||
@ -60,7 +57,11 @@ const (
|
||||
|
||||
var Index = &Context{Name: ICE, Help: "冰山模块", Configs: Configs{HELP: {Value: kit.Data(INDEX, Info.Help)}}, Commands: Commands{
|
||||
CTX_INIT: {Hand: func(m *Message, arg ...string) {
|
||||
m.Travel(func(p *Context, c *Context) { if p != nil { c._command(m.Spawn(c), c.Commands[CTX_INIT], CTX_INIT, arg...) } })
|
||||
m.Travel(func(p *Context, c *Context) {
|
||||
if p != nil {
|
||||
c._command(m.Spawn(c), c.Commands[CTX_INIT], CTX_INIT, arg...)
|
||||
}
|
||||
})
|
||||
}},
|
||||
INIT: {Hand: func(m *Message, arg ...string) {
|
||||
m.Cmd(CTX_INIT)
|
||||
@ -75,7 +76,11 @@ var Index = &Context{Name: ICE, Help: "冰山模块", Configs: Configs{HELP: {Va
|
||||
}},
|
||||
CTX_EXIT: {Hand: func(m *Message, arg ...string) {
|
||||
defer m.Target().Close(m.Spawn(), arg...)
|
||||
m.Travel(func(p *Context, c *Context) { if p != nil { c._command(m.Spawn(c), c.Commands[CTX_EXIT] , CTX_EXIT, arg...) } })
|
||||
m.Travel(func(p *Context, c *Context) {
|
||||
if p != nil {
|
||||
c._command(m.Spawn(c), c.Commands[CTX_EXIT], CTX_EXIT, arg...)
|
||||
}
|
||||
})
|
||||
}},
|
||||
}, server: &Frame{}}
|
||||
var Pulse = &Message{time: time.Now(), code: 0, meta: map[string][]string{}, data: Map{}, source: Index, target: Index, Hand: true}
|
||||
|
6
logs.go
6
logs.go
@ -29,8 +29,14 @@ func (m *Message) join(arg ...Any) (string, []Any) {
|
||||
continue
|
||||
}
|
||||
switch v := arg[i+1].(type) {
|
||||
case logs.Meta:
|
||||
list = append(list, key)
|
||||
meta = append(meta, v)
|
||||
continue
|
||||
case time.Time:
|
||||
arg[i+1] = v.Format(MOD_TIME)
|
||||
case []string:
|
||||
arg[i+1] = kit.Join(v, " ")
|
||||
}
|
||||
list = append(list, key+kit.Select("", DF, !strings.Contains(key, DF)), kit.Format(arg[i+1]))
|
||||
}
|
||||
|
4
misc.go
4
misc.go
@ -169,7 +169,7 @@ func (m *Message) CmdHand(cmd *Command, key string, arg ...string) *Message {
|
||||
return m
|
||||
}
|
||||
if m._target = logs.FileLine(cmd.Hand); cmd.RawHand != nil {
|
||||
m._target = kit.Format(cmd.RawHand)
|
||||
m._target = kit.Join(kit.Slice(kit.Split(kit.Format(cmd.RawHand), PS), -3), PS)
|
||||
}
|
||||
if fileline := kit.Select(m._target, m._source, m.target.Name == MDB); key == SELECT {
|
||||
m.Log(LOG_CMDS, "%s.%s %d %v %v", m.Target().Name, key, len(arg), arg, m.Optionv(MSG_FIELDS), logs.FileLineMeta(fileline))
|
||||
@ -294,7 +294,7 @@ func (c *Context) _action(m *Message, cmd *Command, key string, sub string, h *A
|
||||
}
|
||||
}
|
||||
if m._target = logs.FileLine(h.Hand); cmd.RawHand != nil {
|
||||
m._target = kit.Format(cmd.RawHand)
|
||||
m._target = kit.Join(kit.Slice(kit.Split(kit.Format(cmd.RawHand), PS), -3), PS)
|
||||
}
|
||||
m.Log(LOG_CMDS, "%s.%s %s %d %v", c.Name, key, sub, len(arg), arg,
|
||||
logs.FileLineMeta(kit.Select(m._target, m._source, m.target.Name == MDB)))
|
||||
|
27
option.go
27
option.go
@ -1,12 +1,9 @@
|
||||
package ice
|
||||
|
||||
import (
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
kit "shylinux.com/x/toolkits"
|
||||
"shylinux.com/x/toolkits/logs"
|
||||
)
|
||||
|
||||
type Option struct {
|
||||
@ -152,27 +149,3 @@ func (m *Message) ProcessBack() { m.Process(PROCESS_BACK) }
|
||||
func (m *Message) ProcessRich(arg ...Any) { m.Process(PROCESS_RICH, arg...) }
|
||||
func (m *Message) ProcessGrow(arg ...Any) { m.Process(PROCESS_GROW, arg...) }
|
||||
func (m *Message) ProcessOpen(url string) { m.Process(PROCESS_OPEN, url) }
|
||||
|
||||
func (m *Message) Display(file string, arg ...Any) *Message {
|
||||
m.Option(MSG_DISPLAY, kit.MergeURL(displayRequire(2, file)[DISPLAY], arg...))
|
||||
return m
|
||||
}
|
||||
func displayRequire(n int, file string, arg ...string) Maps {
|
||||
if file == "" {
|
||||
file = kit.Keys(kit.FileName(n+1), JS)
|
||||
}
|
||||
if !strings.HasPrefix(file, PS) && !strings.HasPrefix(file, HTTP) {
|
||||
file = path.Join(PS, path.Join(path.Dir(FileRequire(n+2)), file))
|
||||
}
|
||||
return DisplayBase(file, arg...)
|
||||
}
|
||||
func DisplayBase(file string, arg ...string) Maps {
|
||||
return Maps{DISPLAY: file, STYLE: kit.Join(arg, SP)}
|
||||
}
|
||||
func FileRequire(n int) string {
|
||||
p := kit.Split(logs.FileLines(n), DF)[0]
|
||||
if strings.Contains(p, "go/pkg/mod") {
|
||||
return path.Join("/require", strings.Split(p, "go/pkg/mod")[1])
|
||||
}
|
||||
return path.Join("/require", kit.ModPath(n), path.Base(p))
|
||||
}
|
||||
|
@ -7,12 +7,12 @@ import (
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func AddRender(key string, render func(*Message, string, ...Any) string) {
|
||||
func AddRender(key string, render func(*Message, ...Any) string) {
|
||||
Info.render[key] = render
|
||||
}
|
||||
func Render(m *Message, cmd string, args ...Any) string {
|
||||
if render, ok := Info.render[cmd]; ok {
|
||||
return render(m, cmd, args...)
|
||||
return render(m, args...)
|
||||
}
|
||||
switch arg := kit.Simple(args...); cmd {
|
||||
case RENDER_BUTTON:
|
||||
|
11
type.go
11
type.go
@ -107,7 +107,7 @@ func (c *Command) GetFileLine() string {
|
||||
|
||||
func (c *Context) Register(s *Context, x Server, n ...string) *Context {
|
||||
for _, n := range n {
|
||||
if s, ok := Info.index[n]; ok {
|
||||
if s, ok := Info.Index[n]; ok {
|
||||
last := ""
|
||||
switch s := s.(type) {
|
||||
case *Context:
|
||||
@ -115,7 +115,7 @@ func (c *Context) Register(s *Context, x Server, n ...string) *Context {
|
||||
}
|
||||
panic(kit.Format("%s %s %v", ErrWarn, n, last))
|
||||
}
|
||||
Info.index[n] = s
|
||||
Info.Index[n] = s
|
||||
}
|
||||
if c.Contexts == nil {
|
||||
c.Contexts = Contexts{}
|
||||
@ -127,6 +127,11 @@ func (c *Context) Register(s *Context, x Server, n ...string) *Context {
|
||||
return s
|
||||
}
|
||||
func (c *Context) MergeCommands(Commands Commands) *Context {
|
||||
for _, cmd := range Commands {
|
||||
if cmd.Hand == nil && cmd.RawHand == nil {
|
||||
cmd.RawHand = logs.FileLines(2)
|
||||
}
|
||||
}
|
||||
configs := Configs{}
|
||||
for k, _ := range Commands {
|
||||
configs[k] = &Config{Value: kit.Data()}
|
||||
@ -419,7 +424,7 @@ func (m *Message) Search(key string, cb Any) *Message {
|
||||
return m
|
||||
}
|
||||
key = ls[len(ls)-1]
|
||||
} else if ctx, ok := Info.index[key].(*Context); ok {
|
||||
} else if ctx, ok := Info.Index[key].(*Context); ok {
|
||||
p = ctx
|
||||
} else {
|
||||
p = m.target
|
||||
|
Loading…
x
Reference in New Issue
Block a user