mirror of
https://shylinux.com/x/icebergs
synced 2025-06-26 10:27:31 +08:00
add some
This commit is contained in:
parent
8df263fceb
commit
776dc32431
@ -29,7 +29,7 @@ func init() {
|
||||
DF = ": "
|
||||
)
|
||||
Index.MergeCommands(ice.Commands{
|
||||
EMAIL: {Name: "email name auto", Help: "邮件", Actions: ice.MergeActions(ice.Actions{
|
||||
EMAIL: {Help: "邮件", Actions: ice.MergeActions(ice.Actions{
|
||||
MAILBOX: {Help: "邮箱", Hand: func(m *ice.Message, arg ...string) { m.EchoIFrame(mdb.Config(m, MAILBOX)).ProcessInner() }},
|
||||
SEND: {Name: "send to*='shy@shylinux.com' cc subject*=hi content*:textarea=hello", Help: "发送", Hand: func(m *ice.Message, arg ...string) {
|
||||
msg := m.Cmd("", m.OptionDefault(mdb.NAME, ADMIN))
|
||||
|
@ -14,7 +14,7 @@ const OFFER = "offer"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
OFFER: {Name: "offer hash auto", Help: "邀请", Actions: ice.MergeActions(ice.Actions{
|
||||
OFFER: {Help: "邀请", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.CREATE: {Name: "create email*='shy@shylinux.com' subject content", Help: "邀请", Hand: func(m *ice.Message, arg ...string) {
|
||||
h := mdb.HashCreate(m.Spawn(), m.OptionSimple(EMAIL, SUBJECT, CONTENT), INVITE, m.Option(ice.MSG_USERNAME), mdb.STATUS, INVITE)
|
||||
m.Cmd(EMAIL, SEND, m.Option(EMAIL), "", m.OptionDefault(SUBJECT, "welcome to contexts, please continue"),
|
||||
|
@ -33,7 +33,7 @@ const SESS = "sess"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
SESS: {Name: "sess hash auto", Help: "会话", Actions: ice.MergeActions(ice.Actions{
|
||||
SESS: {Help: "会话", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.CREATE: {Name: "create username*", Hand: func(m *ice.Message, arg ...string) {
|
||||
_sess_create(m, m.Option(USERNAME), UA, m.Option(ice.MSG_USERUA), IP, m.Option(ice.MSG_USERIP))
|
||||
}},
|
||||
@ -62,5 +62,5 @@ func SessAuth(m *ice.Message, value ice.Any, arg ...string) *ice.Message {
|
||||
)
|
||||
}
|
||||
func SessLogout(m *ice.Message, arg ...string) {
|
||||
kit.If(m.Option(ice.MSG_SESSID) != "", func() { m.Cmd(SESS, mdb.REMOVE, mdb.HASH, m.Option(ice.MSG_SESSID)) })
|
||||
kit.If(m.Option(ice.MSG_SESSID), func(sessid string) { m.Cmd(SESS, mdb.REMOVE, mdb.HASH, sessid) })
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ func init() {
|
||||
SECRET = "secret"
|
||||
)
|
||||
Index.MergeCommands(ice.Commands{
|
||||
TOTP: {Name: "totp name auto", Help: "令牌", Actions: ice.MergeActions(ice.Actions{
|
||||
TOTP: {Help: "令牌", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.CREATE: {Name: "create name*=hi number*=6 period*=30 secret", Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.If(m.Option(SECRET) == "", func() { m.Option(SECRET, _totp_gen(kit.Int64(m.Option(PERIOD)))) })
|
||||
mdb.HashCreate(m, m.OptionSimple(mdb.NAME, NUMBER, PERIOD, SECRET))
|
||||
|
@ -38,7 +38,7 @@ const USER = "user"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
USER: {Name: "user username auto", Help: "用户", Actions: ice.MergeActions(ice.Actions{
|
||||
USER: {Help: "用户", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) {
|
||||
switch mdb.HashInputs(m, arg); arg[0] {
|
||||
case USERNICK:
|
||||
|
@ -31,7 +31,7 @@ const MIRRORS = "mirrors"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
MIRRORS: {Name: "mirrors cli auto repos", Help: "软件镜像", Actions: ice.MergeActions(ice.Actions{
|
||||
MIRRORS: {Help: "软件镜像", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.INSERT: {Name: "insert cli* osid cmd*"},
|
||||
CMD: {Name: "cmd cli osid", Hand: func(m *ice.Message, arg ...string) {
|
||||
osid := kit.Select(mdb.Conf(m, RUNTIME, kit.Keys(HOST, OSID)), m.Option(OSID))
|
||||
@ -72,8 +72,7 @@ func init() {
|
||||
} else {
|
||||
m.PushButton("")
|
||||
}
|
||||
})
|
||||
m.StatusTimeCount("release", _release)
|
||||
}).Action(REPOS).StatusTimeCount("release", _release)
|
||||
}
|
||||
switch {
|
||||
case strings.Contains(_release, ALPINE):
|
||||
|
@ -1,8 +1,9 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"debug/elf"
|
||||
"debug/macho"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
@ -12,7 +13,7 @@ import (
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
"readelf": {Name: "readelf path=usr/publish/ice.linux.amd64 auto", Hand: func(m *ice.Message, arg ...string) {
|
||||
"readelf": {Name: "readelf path=bin/ice.bin auto", Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 || strings.HasSuffix(arg[0], nfs.PS) {
|
||||
m.Cmdy(nfs.DIR, arg)
|
||||
return
|
||||
@ -24,10 +25,14 @@ func init() {
|
||||
if m.Warn(e) {
|
||||
return
|
||||
}
|
||||
kit.If(bytes.Equal(buf[:4], []byte{0x7f, 0x45, 0x4c, 0x46}), func() {
|
||||
switch runtime.GOOS {
|
||||
case LINUX:
|
||||
f, _ := elf.Open(arg[0])
|
||||
m.Echo("%v", kit.Formats(f))
|
||||
})
|
||||
case DARWIN:
|
||||
f, _ := macho.Open(arg[0])
|
||||
m.Echo("%v", kit.Formats(f))
|
||||
}
|
||||
for i := 0; i < n; i++ {
|
||||
kit.If(i%16 == 0, func() { m.Push("addr", kit.Format("%04x", i)) })
|
||||
m.Push(kit.Format("%02x", i%16), kit.Format("%02x", buf[i]))
|
||||
|
@ -263,12 +263,11 @@ func init() {
|
||||
}},
|
||||
}, ctx.ConfAction("")), Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.If(len(arg) > 0 && arg[0] == BOOTINFO, func() { arg = arg[1:] })
|
||||
m.Cmdy(ctx.CONFIG, RUNTIME, arg)
|
||||
ctx.DisplayStoryJSON(m)
|
||||
m.Status(mdb.TIME, ice.Info.Make.Time,
|
||||
m.Cmdy(ctx.CONFIG, RUNTIME, arg).Status(mdb.TIME, ice.Info.Make.Time,
|
||||
mdb.HASH, kit.Cut(ice.Info.Hash, 6), nfs.SIZE, ice.Info.Size,
|
||||
mdb.NAME, ice.Info.NodeName, nfs.VERSION, ice.Info.Make.Versions(),
|
||||
)
|
||||
ctx.DisplayStoryJSON(m)
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
@ -99,6 +99,7 @@ func _system_exec(m *ice.Message, cmd *exec.Cmd) {
|
||||
m.Cost(CODE, _system_code(cmd), EXEC, cmd.Args)
|
||||
}
|
||||
m.Push(mdb.TIME, m.Time()).Push(CODE, _system_code(cmd))
|
||||
m.StatusTime()
|
||||
}
|
||||
func _system_code(cmd *exec.Cmd) string {
|
||||
return kit.Select("1", "0", cmd.ProcessState != nil && cmd.ProcessState.Success())
|
||||
|
@ -14,15 +14,6 @@ import (
|
||||
)
|
||||
|
||||
func _command_list(m *ice.Message, name string) *ice.Message {
|
||||
if name == "" {
|
||||
for k, v := range m.Source().Commands {
|
||||
if IsOrderCmd(k) {
|
||||
continue
|
||||
}
|
||||
m.Push(mdb.KEY, k).Push(mdb.NAME, v.Name).Push(mdb.HELP, v.Help)
|
||||
}
|
||||
return m.Sort(mdb.KEY)
|
||||
}
|
||||
if strings.HasPrefix(name, "can.") {
|
||||
return m.Push(mdb.INDEX, name).Push(mdb.NAME, name).Push(mdb.HELP, "").Push(mdb.META, "").Push(mdb.LIST, "")
|
||||
}
|
||||
@ -40,8 +31,14 @@ func _command_search(m *ice.Message, kind, name, text string) {
|
||||
if IsOrderCmd(key) || !strings.Contains(s.Prefix(key), name) {
|
||||
return
|
||||
}
|
||||
m.PushSearch(ice.CTX, kit.PathName(1), ice.CMD, kit.FileName(1), kit.SimpleKV("", s.Prefix(), cmd.Name, cmd.Help),
|
||||
CONTEXT, s.Prefix(), COMMAND, key, INDEX, kit.Keys(s.Prefix(), key), mdb.HELP, cmd.Help, nfs.FILE, FileURI(cmd.FileLine()))
|
||||
m.PushSearch(ice.CTX, kit.PathName(1),
|
||||
ice.CMD, kit.FileName(1),
|
||||
kit.SimpleKV("", s.Prefix(), kit.Select(key, cmd.Name), cmd.Help),
|
||||
CONTEXT, s.Prefix(),
|
||||
COMMAND, key,
|
||||
INDEX, kit.Keys(s.Prefix(), key),
|
||||
mdb.HELP, cmd.Help,
|
||||
nfs.FILE, FileURI(cmd.FileLine()))
|
||||
})
|
||||
m.Sort(m.OptionFields())
|
||||
}
|
||||
@ -65,9 +62,7 @@ func init() {
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
TravelCmd(m, func(key, file, line string) { AddFileCmd(file, key) })
|
||||
m.Travel(func(p *ice.Context, c *ice.Context, key string, cmd *ice.Command) {
|
||||
if cmd.Actions == nil {
|
||||
return
|
||||
}
|
||||
kit.If(cmd.Actions == nil, func() { cmd.Actions = ice.Actions{} })
|
||||
if _, ok := cmd.Actions[COMMAND]; !ok {
|
||||
cmd.Actions[COMMAND] = &ice.Action{Hand: Command}
|
||||
}
|
||||
@ -98,7 +93,7 @@ func init() {
|
||||
}},
|
||||
}, aaa.RoleAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
m.Cmdy("", mdb.SEARCH, COMMAND, ice.OptionFields(INDEX)).StatusTimeCount()
|
||||
m.Cmdy("", mdb.SEARCH, COMMAND, ice.OptionFields(INDEX)).Action(mdb.EXPORT).StatusTimeCount()
|
||||
DisplayStory(m.Options(nfs.DIR_ROOT, "ice."), "spide.js?split=.")
|
||||
} else {
|
||||
kit.For(arg, func(k string) { _command_list(m, k) })
|
||||
@ -115,28 +110,7 @@ func Run(m *ice.Message, arg ...string) {
|
||||
func Command(m *ice.Message, arg ...string) {
|
||||
kit.If(!PodCmd(m, COMMAND, arg), func() { m.Cmdy(COMMAND, arg) })
|
||||
}
|
||||
func CmdAction(args ...ice.Any) ice.Actions {
|
||||
return ice.Actions{ice.CTX_INIT: mdb.AutoConfig(args...), RUN: {Hand: Run}, COMMAND: {Hand: Command}}
|
||||
}
|
||||
func CmdHandler(args ...ice.Any) ice.Handler {
|
||||
return func(m *ice.Message, arg ...string) { m.Cmdy(args...) }
|
||||
}
|
||||
func CmdList(m *ice.Message) *ice.Message {
|
||||
return m.Cmdy(COMMAND, mdb.SEARCH, COMMAND, ice.OptionFields(INDEX))
|
||||
}
|
||||
func CmdInputs(m *ice.Message, arg ...string) *ice.Message {
|
||||
switch arg[0] {
|
||||
case INDEX:
|
||||
m.Cmdy(COMMAND, mdb.SEARCH, COMMAND, ice.OptionFields(INDEX))
|
||||
case ARGS:
|
||||
if m.Cmdy(m.Option(INDEX), mdb.INPUTS, arg); m.Length() == 0 {
|
||||
m.Cmdy(m.Option(INDEX))
|
||||
}
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
func IsOrderCmd(key string) bool { return key[0] == '/' || key[0] == '_' }
|
||||
func FileURI(dir string) string {
|
||||
kit.If(runtime.GOOS == ice.WINDOWS, func() { dir = strings.ReplaceAll(dir, "\\", nfs.PS) })
|
||||
if dir == "" {
|
||||
@ -204,9 +178,10 @@ func TravelCmd(m *ice.Message, cb func(key, file, line string)) *ice.Message {
|
||||
return
|
||||
}
|
||||
}
|
||||
if ls := kit.Split(cmd.FileLine(), nfs.DF); len(ls) > 0 && cmd.Name != "" {
|
||||
if ls := kit.Split(cmd.FileLine(), nfs.DF); len(ls) > 0 {
|
||||
cb(kit.Keys(s.Prefix(), key), strings.TrimPrefix(ls[0], kit.Path("")+nfs.PS), kit.Select("1", ls, 1))
|
||||
}
|
||||
})
|
||||
return m
|
||||
}
|
||||
func IsOrderCmd(key string) bool { return key[0] == '/' || key[0] == '_' }
|
||||
|
@ -124,7 +124,7 @@ const CONFIG = "config"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
CONFIG: {Name: "config key auto export import trash", Help: "配置", Actions: ice.Actions{
|
||||
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: {Hand: func(m *ice.Message, arg ...string) { _config_load(m, arg[0], arg[1:]...) }},
|
||||
mdb.EXPORT: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(mdb.EXPORT, arg[0], "", mdb.HASH) }},
|
||||
@ -145,14 +145,12 @@ func init() {
|
||||
_config_list(m)
|
||||
} else {
|
||||
_config_make(m, arg[0], arg[1:]...)
|
||||
m.Action(mdb.EXPORT, mdb.IMPORT, nfs.TRASH)
|
||||
}
|
||||
}},
|
||||
})
|
||||
}
|
||||
func init() {
|
||||
ice.Info.Save = Save
|
||||
ice.Info.Load = Load
|
||||
}
|
||||
func init() { ice.Info.Save = Save; ice.Info.Load = Load }
|
||||
func Save(m *ice.Message, arg ...string) *ice.Message {
|
||||
kit.If(len(arg) == 0, func() { arg = kit.SortedKey(m.Target().Configs) })
|
||||
kit.For(arg, func(i int, k string) { arg[i] = strings.Replace(m.Prefix(k), nfs.PS, "", 1) })
|
||||
|
@ -16,13 +16,14 @@ func _context_list(m *ice.Message, sub *ice.Context, name string) {
|
||||
}
|
||||
m.Push(mdb.NAME, s.Prefix()).Push(mdb.HELP, s.Help)
|
||||
})
|
||||
m.StatusTimeCount()
|
||||
}
|
||||
|
||||
const CONTEXT = "context"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
CONTEXT: {Name: "context name=web action=context,command,config key auto", Help: "模块", Hand: func(m *ice.Message, arg ...string) {
|
||||
CONTEXT: {Name: "context name=ice action=context,command,config key auto", Help: "模块", Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.If(len(arg) == 0, func() { arg = append(arg, m.Source().Prefix()) })
|
||||
m.Search(arg[0]+nfs.PT, func(p *ice.Context, s *ice.Context) {
|
||||
msg := m.Spawn(s)
|
||||
|
@ -62,10 +62,3 @@ func ProcessField(m *ice.Message, cmd string, args ice.Any, arg ...string) *ice.
|
||||
}
|
||||
return m
|
||||
}
|
||||
func ProcessCommand(m *ice.Message, cmd string, args []string, arg ...string) {
|
||||
if !kit.HasPrefixList(arg, RUN) {
|
||||
m.Cmdy(COMMAND, cmd).Push(ice.ARG, kit.Format(args)).ProcessField(cmd, RUN)
|
||||
} else {
|
||||
m.Cmdy(cmd, arg[1:])
|
||||
}
|
||||
}
|
||||
|
@ -13,8 +13,6 @@ const (
|
||||
)
|
||||
const EVENT = "event"
|
||||
|
||||
var list map[string]int = map[string]int{}
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
EVENT: {Name: "event event id auto listen happen", Help: "事件流", Actions: ice.MergeActions(ice.Actions{
|
||||
@ -32,6 +30,7 @@ func init() {
|
||||
}, mdb.ZoneAction(mdb.SHORT, EVENT, mdb.FIELD, "time,id,cmd"), mdb.ClearOnExitHashAction())},
|
||||
})
|
||||
}
|
||||
|
||||
func EventsAction(arg ...string) ice.Actions {
|
||||
list := kit.DictList(arg...)
|
||||
return ice.Actions{ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
@ -40,6 +39,9 @@ func EventsAction(arg ...string) ice.Actions {
|
||||
}
|
||||
}}}
|
||||
}
|
||||
|
||||
var list map[string]int = map[string]int{}
|
||||
|
||||
func Watch(m *ice.Message, key string, arg ...string) *ice.Message {
|
||||
kit.If(len(arg) == 0, func() { arg = append(arg, m.PrefixKey()) })
|
||||
return m.Cmd(EVENT, LISTEN, EVENT, key, ice.CMD, kit.Join(arg, ice.SP))
|
||||
|
@ -11,7 +11,7 @@ const ROUTINE = "routine"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
ROUTINE: {Name: "routine hash auto prunes", Help: "协程池", Actions: ice.MergeActions(ice.Actions{
|
||||
ROUTINE: {Help: "协程池", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.CREATE: {Name: "create name cmd", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Go(func() {
|
||||
cb := m.OptionCB("")
|
||||
|
@ -48,7 +48,7 @@ const SIGNAL = "signal"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
SIGNAL: {Name: "signal signal auto listen", Help: "信号量", Actions: ice.MergeActions(ice.Actions{
|
||||
SIGNAL: {Help: "信号量", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if runtime.GOOS == ice.WINDOWS {
|
||||
return
|
||||
@ -57,7 +57,7 @@ func init() {
|
||||
_signal_listen(m, 2, mdb.NAME, RESTART, ice.CMD, "exit 1")
|
||||
_signal_listen(m, 3, mdb.NAME, STOP, ice.CMD, "exit 0")
|
||||
}},
|
||||
LISTEN: {Name: "listen signal name cmd", Hand: func(m *ice.Message, arg ...string) {
|
||||
LISTEN: {Name: "listen signal name cmd", Help: "监听", Hand: func(m *ice.Message, arg ...string) {
|
||||
_signal_listen(m, kit.Int(m.Option(SIGNAL)), arg...)
|
||||
}},
|
||||
HAPPEN: {Name: "happen signal", Help: "触发", Hand: func(m *ice.Message, arg ...string) {
|
||||
@ -73,7 +73,8 @@ func init() {
|
||||
_signal_process(m, m.Option(PID), syscall.Signal(kit.Int(kit.Select("9", m.Option(SIGNAL)))))
|
||||
}},
|
||||
}, mdb.HashAction(mdb.SHORT, SIGNAL, mdb.FIELD, "time,signal,name,cmd", mdb.ACTION, HAPPEN), mdb.ClearOnExitHashAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashSelect(m, arg...).Sort(SIGNAL)
|
||||
defer kit.If(len(arg) == 0, func() { m.Action(LISTEN) })
|
||||
mdb.HashSelect(m, arg...)
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
@ -31,9 +31,7 @@ const TIMER = "timer"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
TIMER: {Name: "timer name auto create prunes", Help: "定时器", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.CREATE: {Name: "create name*=hi delay=10ms interval=10s count=3 cmd*=runtime"},
|
||||
mdb.PRUNES: {Hand: func(m *ice.Message, arg ...string) { mdb.HashPrunesValue(m, mdb.COUNT, "0") }},
|
||||
TIMER: {Help: "定时器", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) {
|
||||
switch mdb.HashInputs(m, arg); arg[0] {
|
||||
case mdb.COUNT:
|
||||
@ -42,8 +40,10 @@ func init() {
|
||||
m.Push(arg[0], "cli.procstat insert")
|
||||
}
|
||||
}},
|
||||
HAPPEN: {Hand: func(m *ice.Message, arg ...string) { _timer_action(m, time.Now(), arg...) }},
|
||||
RESTART: {Name: "restart count=3", Hand: func(m *ice.Message, arg ...string) { mdb.HashModify(m, m.OptionSimple(mdb.HashShort(m)), arg) }},
|
||||
}, mdb.HashAction(mdb.SHORT, mdb.NAME, mdb.FIELD, "time,hash,name,delay,interval,count,cmd", TICK, "1s"))},
|
||||
mdb.CREATE: {Name: "create name*=hi delay=10ms interval=10s count=3 cmd*=runtime"},
|
||||
mdb.PRUNES: {Hand: func(m *ice.Message, arg ...string) { mdb.HashPrunesValue(m, mdb.COUNT, "0") }},
|
||||
HAPPEN: {Hand: func(m *ice.Message, arg ...string) { _timer_action(m, time.Now(), arg...) }},
|
||||
RESTART: {Name: "restart count=3", Hand: func(m *ice.Message, arg ...string) { mdb.HashModify(m, m.OptionSimple(mdb.HashShort(m)), arg) }},
|
||||
}, mdb.HashAction(mdb.SHORT, mdb.NAME, mdb.FIELD, "time,name,delay,interval,count,cmd", TICK, "1s"))},
|
||||
})
|
||||
}
|
||||
|
@ -13,10 +13,10 @@ import (
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
const DEBUG = "debug"
|
||||
|
||||
func _debug_file(k string) string { return ice.VAR_LOG + k + ".log" }
|
||||
|
||||
const DEBUG = "debug"
|
||||
|
||||
func init() {
|
||||
const (
|
||||
LEVEL = "level"
|
||||
|
@ -11,7 +11,7 @@ const ERROR = "error"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
ERROR: {Name: "error auto", Help: "错误", Hand: func(m *ice.Message, arg ...string) {
|
||||
ERROR: {Help: "错误", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(nfs.CAT, path.Join(ice.VAR_LOG, "error.log"))
|
||||
}},
|
||||
})
|
||||
|
@ -15,7 +15,7 @@ const WATCH = "watch"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
WATCH: {Name: "watch auto", Help: "记录", Hand: func(m *ice.Message, arg ...string) {
|
||||
WATCH: {Help: "记录", Hand: func(m *ice.Message, arg ...string) {
|
||||
stats := map[string]int{}
|
||||
m.Cmd(nfs.CAT, path.Join(ice.VAR_LOG, "watch.log"), func(text string) {
|
||||
ls := kit.Split(text)
|
||||
@ -23,8 +23,7 @@ func init() {
|
||||
m.Push(ctx.SHIP, ls[3]).Push("operate", ls[4]).Push(nfs.CONTENT, kit.Join(kit.Slice(ls, 5, -1), lex.SP))
|
||||
stats[ls[4]]++
|
||||
})
|
||||
m.StatusTimeCount(stats)
|
||||
m.Action("filter:text")
|
||||
m.Action("filter:text").StatusTimeCount(stats)
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ func HashAction(arg ...Any) ice.Actions {
|
||||
CREATE: {Hand: func(m *ice.Message, arg ...string) { HashCreate(m, arg) }},
|
||||
REMOVE: {Hand: func(m *ice.Message, arg ...string) { HashRemove(m, arg) }},
|
||||
MODIFY: {Hand: func(m *ice.Message, arg ...string) { HashModify(m, arg) }},
|
||||
SELECT: {Name: "select hash auto create", Hand: func(m *ice.Message, arg ...string) { HashSelect(m, arg...) }},
|
||||
SELECT: {Hand: func(m *ice.Message, arg ...string) { HashSelect(m, arg...) }},
|
||||
PRUNES: {Name: "prunes before@date", Hand: func(m *ice.Message, arg ...string) { HashPrunes(m, nil) }},
|
||||
EXPORT: {Hand: func(m *ice.Message, arg ...string) { HashExport(m, arg) }},
|
||||
IMPORT: {Hand: func(m *ice.Message, arg ...string) { HashImport(m, arg) }},
|
||||
@ -156,21 +156,20 @@ func HashAction(arg ...Any) ice.Actions {
|
||||
}
|
||||
func StatusHashAction(arg ...Any) ice.Actions {
|
||||
return ice.MergeActions(ice.Actions{
|
||||
PRUNES: &ice.Action{Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(PRUNES, m.PrefixKey(), "", HASH, STATUS, "error", STATUS, "close", STATUS, "stop", STATUS, "end", ice.OptionFields(HashField(m)))
|
||||
PRUNES: &ice.Action{Name: "prunes status", Hand: func(m *ice.Message, arg ...string) {
|
||||
args := []string{}
|
||||
kit.For(kit.Split(m.OptionDefault(STATUS, "error,close,stop,end")), func(s string) { args = append(args, STATUS, s) })
|
||||
m.Cmdy(PRUNES, m.PrefixKey(), "", HASH, args, ice.OptionFields(HashField(m)))
|
||||
}},
|
||||
}, HashAction(arg...))
|
||||
}
|
||||
func ClearOnExitHashAction() ice.Actions {
|
||||
return ice.MergeActions(ice.Actions{ice.CTX_EXIT: {Hand: func(m *ice.Message, arg ...string) { Conf(m, m.PrefixKey(), HASH, "") }}})
|
||||
return ice.Actions{ice.CTX_EXIT: {Hand: func(m *ice.Message, arg ...string) { Conf(m, m.PrefixKey(), HASH, "") }}}
|
||||
}
|
||||
func ExportHashAction(arg ...Any) ice.Actions {
|
||||
return ice.MergeActions(ice.Actions{
|
||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
Config(m, IMPORTANT, ice.TRUE)
|
||||
HashExport(m, arg)
|
||||
}},
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { HashImport(m, arg) }},
|
||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, arg ...string) { Config(m, IMPORTANT, ice.TRUE); HashExport(m, arg) }},
|
||||
}, HashAction(arg...))
|
||||
}
|
||||
|
||||
@ -220,12 +219,14 @@ func HashSelect(m *ice.Message, arg ...string) *ice.Message {
|
||||
m.Fields(len(kit.Slice(arg, 0, 1)), HashField(m))
|
||||
}
|
||||
m.Cmdy(SELECT, m.PrefixKey(), m.Option(SUBKEY), HASH, HashShort(m), arg, logs.FileLineMeta(-1))
|
||||
kit.If(Config(m, SORT), func(sort string) { m.Sort(sort) })
|
||||
kit.If(kit.Select(Config(m, SHORT), Config(m, SORT)), func(sort string) {
|
||||
kit.If(sort != UNIQ, func() { m.Sort(sort) })
|
||||
})
|
||||
if m.PushAction(Config(m, ACTION), REMOVE); !m.FieldsIsDetail() {
|
||||
m.Action(CREATE, PRUNES)
|
||||
return m.StatusTimeCount()
|
||||
return m.Action(CREATE, PRUNES).StatusTimeCount()
|
||||
} else {
|
||||
return m.StatusTime()
|
||||
}
|
||||
return m.StatusTime()
|
||||
}
|
||||
func HashPrunes(m *ice.Message, cb func(Map) bool) *ice.Message {
|
||||
expire := kit.Select(m.Time("-"+kit.Select(DAYS, Config(m, EXPIRE))), m.Option("before"))
|
||||
|
@ -239,25 +239,36 @@ func AutoConfig(arg ...Any) *ice.Action {
|
||||
}
|
||||
if cmd := m.Target().Commands[m.CommandKey()]; cmd == nil {
|
||||
return
|
||||
} else if cmd.Actions[INSERT] != nil {
|
||||
if inputs := []Any{}; cmd.Meta[INSERT] == nil {
|
||||
kit.For(kit.Filters(kit.Simple(Config(m, SHORT), kit.Split(ListField(m))), "", TIME, ID), func(k string) { inputs = append(inputs, k) })
|
||||
m.Design(INSERT, "添加", inputs...)
|
||||
}
|
||||
if inputs := []Any{}; cmd.Meta[CREATE] == nil {
|
||||
kit.For(kit.Filters(kit.Split(Config(m, SHORT)), TIME, HASH, COUNT), func(k string) { inputs = append(inputs, k) })
|
||||
m.Design(CREATE, "创建", inputs...)
|
||||
}
|
||||
} else if cmd.Actions[CREATE] != nil {
|
||||
if inputs := []Any{}; cmd.Meta[CREATE] == nil {
|
||||
kit.For(kit.Filters(kit.Split(HashField(m)), TIME, HASH), func(k string) {
|
||||
if kit.IsIn(k, kit.Split(Config(m, SHORT))...) {
|
||||
inputs = append(inputs, k+"*")
|
||||
} else {
|
||||
inputs = append(inputs, k)
|
||||
}
|
||||
} else {
|
||||
if cmd.Name == "" {
|
||||
kit.If(Config(m, SHORT), func(s string) {
|
||||
kit.If(s == UNIQ || strings.Contains(s, ","), func() { s = HASH })
|
||||
cmd.Name = kit.Format("%s %s auto", m.CommandKey(), s)
|
||||
}, func() {
|
||||
cmd.Name = kit.Format("%s %s auto", m.CommandKey(), HASH)
|
||||
})
|
||||
m.Design(CREATE, "创建", inputs...)
|
||||
cmd.List = ice.SplitCmd(cmd.Name, cmd.Actions)
|
||||
}
|
||||
if cmd.Actions[INSERT] != nil {
|
||||
if inputs := []Any{}; cmd.Meta[INSERT] == nil {
|
||||
kit.For(kit.Filters(kit.Simple(Config(m, SHORT), kit.Split(ListField(m))), "", TIME, ID), func(k string) { inputs = append(inputs, k) })
|
||||
m.Design(INSERT, "添加", inputs...)
|
||||
}
|
||||
if inputs := []Any{}; cmd.Meta[CREATE] == nil {
|
||||
kit.For(kit.Filters(kit.Split(Config(m, SHORT)), TIME, HASH, COUNT), func(k string) { inputs = append(inputs, k) })
|
||||
m.Design(CREATE, "创建", inputs...)
|
||||
}
|
||||
} else if cmd.Actions[CREATE] != nil {
|
||||
if inputs := []Any{}; cmd.Meta[CREATE] == nil {
|
||||
kit.For(kit.Filters(kit.Split(HashField(m)), TIME, HASH), func(k string) {
|
||||
if kit.IsIn(k, kit.Split(Config(m, SHORT))...) {
|
||||
inputs = append(inputs, k+"*")
|
||||
} else {
|
||||
inputs = append(inputs, k)
|
||||
}
|
||||
})
|
||||
m.Design(CREATE, "创建", inputs...)
|
||||
}
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
@ -61,7 +61,6 @@ func _cat_list(m *ice.Message, p string) {
|
||||
const (
|
||||
CAT_CONTENT = "cat_content"
|
||||
CONFIGURE = "configure"
|
||||
TEMPLATE = "template"
|
||||
STDIO = "stdio"
|
||||
|
||||
TAGS = "tags"
|
||||
@ -101,6 +100,7 @@ const (
|
||||
PNG = "png"
|
||||
JPG = "jpg"
|
||||
MP4 = "mp4"
|
||||
MOV = "mov"
|
||||
PDF = "pdf"
|
||||
|
||||
DF = ice.DF
|
||||
@ -116,39 +116,22 @@ func init() {
|
||||
ice.CTX_INIT: mdb.AutoConfig(SOURCE, kit.DictList(
|
||||
HTML, CSS, JS, GO, SH, PY, SHY, CSV, JSON, CONFIGURE, PROTO, YAML, CONF, XML, YML, TXT, MD, strings.ToLower(ice.LICENSE), strings.ToLower(ice.MAKEFILE),
|
||||
)),
|
||||
}), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 || strings.HasSuffix(arg[0], PS) {
|
||||
m.Cmdy(DIR, arg)
|
||||
} else {
|
||||
if arg[0] == ice.ACTION {
|
||||
m.Cmdy(DIR, arg)
|
||||
} else {
|
||||
_cat_list(m.Logs(FIND, m.OptionSimple(DIR_ROOT), FILE, arg[0]), arg[0])
|
||||
}
|
||||
}, DIR), Hand: func(m *ice.Message, arg ...string) {
|
||||
if !DirList(m, arg...) {
|
||||
_cat_list(m.Logs(FIND, m.OptionSimple(DIR_ROOT), FILE, arg[0]), arg[0])
|
||||
}
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
||||
type templateMessage interface {
|
||||
Optionv(key string, arg ...ice.Any) ice.Any
|
||||
Cmdx(...ice.Any) string
|
||||
PrefixKey() string
|
||||
func DirList(m *ice.Message, arg ...string) bool {
|
||||
if len(arg) == 0 || strings.HasSuffix(arg[0], PS) {
|
||||
m.Cmdy(DIR, kit.Slice(arg, 0, 1))
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func Template(m templateMessage, p string, arg ...ice.Any) string {
|
||||
return kit.Renders(kit.Format(TemplateText(m, p), arg...), m)
|
||||
}
|
||||
func TemplateText(m templateMessage, p string) string {
|
||||
return m.Cmdx(CAT, path.Join(m.PrefixKey(), path.Base(p)), kit.Dict(DIR_ROOT, ice.SRC_TEMPLATE))
|
||||
}
|
||||
func TemplatePath(m templateMessage, arg ...string) string {
|
||||
if p := path.Join(ice.SRC_TEMPLATE, m.PrefixKey(), path.Join(arg...)); Exists(m, p) {
|
||||
return p
|
||||
} else {
|
||||
return p
|
||||
}
|
||||
}
|
||||
func IsSourceFile(m *ice.Message, ext string) bool {
|
||||
return mdb.Conf(m, Prefix(CAT), kit.Keym(SOURCE, ext)) == ice.TRUE
|
||||
}
|
||||
|
@ -144,6 +144,7 @@ const (
|
||||
USR_PUBLISH = ice.USR_PUBLISH
|
||||
USR_LOCAL_WORK = ice.USR_LOCAL_WORK
|
||||
SRC_DOCUMENT = ice.SRC_DOCUMENT
|
||||
SRC_TEMPLATE = ice.SRC_TEMPLATE
|
||||
REQUIRE = "/require/"
|
||||
VOLCANOS = "/volcanos/"
|
||||
INTSHELL = "/intshell/"
|
||||
@ -186,10 +187,10 @@ func init() {
|
||||
aaa.Black(m, ice.USR_LOCAL)
|
||||
}},
|
||||
ice.APP: {Help: "本机", Hand: func(m *ice.Message, arg ...string) { m.Cmd("cli.system", "opens", "Finder.app") }},
|
||||
TRASH: {Hand: func(m *ice.Message, arg ...string) { m.Cmd(TRASH, mdb.CREATE, m.Option(PATH)) }},
|
||||
mdb.SHOW: {Help: "预览", Hand: func(m *ice.Message, arg ...string) {
|
||||
Show(m.ProcessInner(), path.Join(m.Option(DIR_ROOT), m.Option(PATH)))
|
||||
}}, mdb.UPLOAD: {},
|
||||
TRASH: {Hand: func(m *ice.Message, arg ...string) { m.Cmd(TRASH, mdb.CREATE, m.Option(PATH)) }},
|
||||
}, Hand: func(m *ice.Message, arg ...string) {
|
||||
root, dir := kit.Select(PWD, m.Option(DIR_ROOT)), kit.Select(PWD, arg, 0)
|
||||
kit.If(strings.HasPrefix(dir, PS), func() { root = "" })
|
||||
@ -255,9 +256,9 @@ func Show(m *ice.Message, file string) bool {
|
||||
p := "/share/local/" + file
|
||||
kit.If(m.Option(ice.MSG_USERPOD), func(pod string) { p += "?pod=" + pod })
|
||||
switch strings.ToLower(kit.Ext(file)) {
|
||||
case "png", "jpg":
|
||||
case PNG, JPG:
|
||||
m.EchoImages(p)
|
||||
case "mp4", "mov":
|
||||
case MP4, MOV:
|
||||
m.EchoVideos(p)
|
||||
default:
|
||||
if IsSourceFile(m, kit.Ext(file)) {
|
||||
|
44
base/nfs/document.go
Normal file
44
base/nfs/document.go
Normal file
@ -0,0 +1,44 @@
|
||||
package nfs
|
||||
|
||||
import (
|
||||
"path"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
const DOCUMENT = "document"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
DOCUMENT: {Name: "document index path auto", Help: "文档", Actions: ice.MergeActions(ice.Actions{}), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
m.Cmdy(ice.COMMAND).Action("filter:text").Option(ice.MSG_DISPLAY, "")
|
||||
return
|
||||
}
|
||||
m.Search(arg[0], func(p *ice.Context, c *ice.Context, key string, cmd *ice.Command) {
|
||||
if p := DocumentPath(m); p != "" {
|
||||
if len(kit.Slice(arg, 0, 2)) == 1 {
|
||||
m.Cmdy(DIR, p)
|
||||
} else {
|
||||
m.Cmdy(CAT, arg[1])
|
||||
}
|
||||
}
|
||||
})
|
||||
}},
|
||||
})
|
||||
}
|
||||
func Document(m *ice.Message, p string, arg ...ice.Any) string {
|
||||
return kit.Renders(kit.Format(DocumentText(m, p), arg...), m)
|
||||
}
|
||||
|
||||
var DocumentText = func(m *ice.Message, p string) string {
|
||||
return m.Cmdx(CAT, DocumentPath(m, path.Base(p)))
|
||||
}
|
||||
var DocumentPath = func(m *ice.Message, arg ...string) string {
|
||||
if p := path.Join(ice.SRC_DOCUMENT, m.PrefixKey(), path.Join(arg...)); Exists(m, p) {
|
||||
return p
|
||||
} else {
|
||||
return p
|
||||
}
|
||||
}
|
25
base/nfs/find.go
Normal file
25
base/nfs/find.go
Normal file
@ -0,0 +1,25 @@
|
||||
package nfs
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
const FIND = "find"
|
||||
|
||||
func init() {
|
||||
const CMD_DIR = "cmd_dir"
|
||||
Index.MergeCommands(ice.Commands{
|
||||
FIND: {Name: "find word file auto", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.If(len(arg) == 0, func() { arg = append(arg, "main.go") })
|
||||
m.Options(mdb.VALUE, arg[0], CMD_DIR, kit.Select("", arg, 2))
|
||||
msg := m.Cmd("cli.system", FIND, kit.Select(SRC, arg, 1), "-name", arg[0])
|
||||
m.Echo(msg.FormatsMeta(nil))
|
||||
kit.For(strings.Split(msg.Result(), ice.NL), func(s string) { m.Push(FILE, s) })
|
||||
m.StatusTimeCount(kit.Dict(PATH, m.Option(CMD_DIR)))
|
||||
}},
|
||||
})
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package nfs
|
||||
|
||||
import (
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
@ -9,7 +10,6 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
FIND = "find"
|
||||
OPENS = "opens"
|
||||
)
|
||||
|
||||
@ -18,14 +18,15 @@ const GREP = "grep"
|
||||
func init() {
|
||||
const CMD_DIR = "cmd_dir"
|
||||
Index.MergeCommands(ice.Commands{
|
||||
GREP: {Name: "grep word file path auto", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
||||
GREP: {Name: "grep word file auto", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.If(len(arg) == 0, func() { arg = append(arg, ice.MAIN) })
|
||||
m.Options(mdb.VALUE, arg[0], CMD_DIR, kit.Select("", arg, 2))
|
||||
kit.For(strings.Split(m.Cmdx("cli.system", GREP, "--exclude=.[a-z]*", "--exclude-dir=.[a-z]*", "-rni", arg[0], kit.Select(PT, arg, 1)), ice.NL), func(s string) {
|
||||
kit.For(strings.Split(m.Cmdx("cli.system", GREP, "--exclude=.[a-z]*", "--exclude-dir=.[a-z]*", "-rni", arg[0], path.Join(kit.Select(SRC, arg, 1))), ice.NL), func(s string) {
|
||||
if ls := strings.SplitN(s, DF, 3); len(ls) > 2 {
|
||||
m.Push(FILE, strings.TrimPrefix(ls[0], PWD)).Push(LINE, ls[1]).Push(mdb.TEXT, ls[2])
|
||||
}
|
||||
})
|
||||
m.StatusTimeCount(PATH, m.Option(CMD_DIR))
|
||||
m.StatusTimeCount(kit.Dict(PATH, m.Option(CMD_DIR)))
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import (
|
||||
"encoding/hex"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
@ -17,8 +16,7 @@ const HEX = "hex"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{HEX: {Name: "hex path compress=raw,gzip,zlib size auto", Help: "二进制", Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 || arg[0] == "" || strings.HasSuffix(arg[0], PS) {
|
||||
m.Cmdy(DIR, kit.Slice(arg, 0, 1))
|
||||
if DirList(m, arg...) {
|
||||
return
|
||||
}
|
||||
Open(m, arg[0], func(r io.Reader, s os.FileInfo) {
|
||||
|
@ -10,6 +10,6 @@ const NFS = "nfs"
|
||||
var Index = &ice.Context{Name: NFS, Help: "存储模块"}
|
||||
|
||||
func init() {
|
||||
ice.Index.Register(Index, nil, ZIP, TAR, CAT, DIR, PACK, DEFS, SAVE, PUSH, COPY, LINK, GREP, TRASH)
|
||||
ice.Index.Register(Index, nil, ZIP, TAR, CAT, DIR, PACK, DEFS, SAVE, PUSH, COPY, LINK, GREP, FIND, TRASH)
|
||||
}
|
||||
func Prefix(arg ...string) string { return kit.Keys(NFS, arg) }
|
||||
|
@ -16,7 +16,7 @@ const PACK = "pack"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
PACK: {Name: "pack path auto upload create", Help: "文件系统", Actions: ice.Actions{
|
||||
PACK: {Name: "pack path auto create upload", Help: "文件系统", Actions: ice.Actions{
|
||||
mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if arg[0] == mdb.FOREACH && arg[1] != "" {
|
||||
m.Cmd(DIR, SRC, PATH, kit.Dict(DIR_REG, arg[1], DIR_DEEP, ice.TRUE, DIR_TYPE, CAT), func(value ice.Maps) {
|
||||
@ -38,13 +38,6 @@ func init() {
|
||||
})
|
||||
}},
|
||||
mdb.REMOVE: {Hand: func(m *ice.Message, arg ...string) { PackFile.Remove(path.Clean(m.Option(PATH))) }},
|
||||
mdb.IMPORT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
OptionFiles(m, DiskFile)
|
||||
Open(m, path.Join(m.Option(PATH), m.Option(FILE)), func(r io.Reader, p string) {
|
||||
OptionFiles(m, PackFile)
|
||||
Create(m, p, func(w io.Writer) { Copy(m, w, r, func(n int) { m.Logs(LOAD, FILE, p, SIZE, n) }) })
|
||||
})
|
||||
}},
|
||||
mdb.EXPORT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
OptionFiles(m, PackFile)
|
||||
Open(m, path.Join(m.Option(PATH), m.Option(FILE)), func(r io.Reader, p string) {
|
||||
@ -52,6 +45,13 @@ func init() {
|
||||
Create(m, p, func(w io.Writer) { Copy(m, w, r, func(n int) { m.Logs(LOAD, FILE, p, SIZE, n) }) })
|
||||
})
|
||||
}},
|
||||
mdb.IMPORT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
OptionFiles(m, DiskFile)
|
||||
Open(m, path.Join(m.Option(PATH), m.Option(FILE)), func(r io.Reader, p string) {
|
||||
OptionFiles(m, PackFile)
|
||||
Create(m, p, func(w io.Writer) { Copy(m, w, r, func(n int) { m.Logs(LOAD, FILE, p, SIZE, n) }) })
|
||||
})
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, arg ...string) {
|
||||
OptionFiles(m, PackFile)
|
||||
if p := kit.Select("", arg, 0); p != "" && !strings.HasSuffix(p, PS) {
|
||||
|
48
base/nfs/template.go
Normal file
48
base/nfs/template.go
Normal file
@ -0,0 +1,48 @@
|
||||
package nfs
|
||||
|
||||
import (
|
||||
"path"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
const TEMPLATE = "template"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
TEMPLATE: {Name: "template index path auto", Help: "模板", Actions: ice.MergeActions(ice.Actions{}), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
m.Cmdy(ice.COMMAND).Action("filter:text").Option(ice.MSG_DISPLAY, "")
|
||||
return
|
||||
}
|
||||
m.Search(arg[0], func(p *ice.Context, c *ice.Context, key string, cmd *ice.Command) {
|
||||
if p := TemplatePath(m); p != "" {
|
||||
if len(kit.Slice(arg, 0, 2)) == 1 {
|
||||
m.Cmdy(DIR, p)
|
||||
} else {
|
||||
m.Cmdy(CAT, arg[1])
|
||||
}
|
||||
}
|
||||
})
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
||||
func Template(m *ice.Message, p string, data ...ice.Any) string {
|
||||
if len(data) == 0 {
|
||||
return kit.Renders(TemplateText(m, p), m)
|
||||
}
|
||||
return kit.Renders(TemplateText(m, p), data[0])
|
||||
}
|
||||
|
||||
var TemplateText = func(m *ice.Message, p string) string {
|
||||
return m.Cmdx(CAT, TemplatePath(m, path.Base(p)))
|
||||
}
|
||||
var TemplatePath = func(m *ice.Message, arg ...string) string {
|
||||
if p := path.Join(ice.SRC_TEMPLATE, m.PrefixKey(), path.Join(arg...)); Exists(m, p) {
|
||||
return p
|
||||
} else {
|
||||
return p
|
||||
}
|
||||
}
|
@ -102,7 +102,7 @@ func (f *Frame) parse(m *ice.Message, h, line string) string {
|
||||
return ""
|
||||
}
|
||||
func (f *Frame) scan(m *ice.Message, h, line string) *Frame {
|
||||
kit.If(f.source == STDIO, func() { m.Option(ice.LOG_DISABLE, ice.TRUE) })
|
||||
// kit.If(f.source == STDIO, func() { m.Option(ice.LOG_DISABLE, ice.TRUE) })
|
||||
f.ps1 = kit.Simple(mdb.Confv(m, PROMPT, kit.Keym(PS1)))
|
||||
f.ps2 = kit.Simple(mdb.Confv(m, PROMPT, kit.Keym(PS2)))
|
||||
ps, bio := f.ps1, bufio.NewScanner(f.stdin)
|
||||
|
@ -47,7 +47,7 @@ const CLIENT = "client"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
CLIENT: {Name: "client hash auto prunes", Help: "客户端", Actions: ice.MergeActions(ice.Actions{
|
||||
CLIENT: {Help: "客户端", Actions: ice.MergeActions(ice.Actions{
|
||||
DIAL: {Name: "dial type name port=9010 host=", Help: "连接", Hand: func(m *ice.Message, arg ...string) {
|
||||
switch m.Option(mdb.TYPE) {
|
||||
case UDP4:
|
||||
|
@ -50,18 +50,18 @@ func init() {
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd("", func(value ice.Maps) { m.Cmd("", aaa.WHITE, LOCALHOST, value[aaa.IP]) })
|
||||
}},
|
||||
aaa.WHITE: {Name: "white name text", Help: "白名单", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashCreate(m, mdb.TYPE, m.ActionKey(), m.OptionSimple(mdb.NAME, mdb.TEXT))
|
||||
}},
|
||||
aaa.BLACK: {Name: "black name text", Help: "黑名单", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashCreate(m, mdb.TYPE, m.ActionKey(), m.OptionSimple(mdb.NAME, mdb.TEXT))
|
||||
}},
|
||||
mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if mdb.IsSearchPreview(m, arg) {
|
||||
ip := m.Cmdv(HOST, GATEWAY, aaa.IP)
|
||||
m.PushSearch(mdb.TYPE, GATEWAY, mdb.NAME, ip, mdb.TEXT, "http://"+ip)
|
||||
}
|
||||
}},
|
||||
aaa.WHITE: {Name: "white name text", Help: "白名单", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashCreate(m, mdb.TYPE, m.ActionKey(), m.OptionSimple(mdb.NAME, mdb.TEXT))
|
||||
}},
|
||||
aaa.BLACK: {Name: "black name text", Help: "黑名单", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashCreate(m, mdb.TYPE, m.ActionKey(), m.OptionSimple(mdb.NAME, mdb.TEXT))
|
||||
}},
|
||||
ISLOCAL: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if arg[0] = strings.Split(strings.TrimPrefix(arg[0], "["), "]")[0]; arg[0] == "::1" || strings.HasPrefix(arg[0], "127.") || arg[0] == LOCALHOST {
|
||||
m.Echo(ice.OK)
|
||||
|
@ -33,6 +33,7 @@ func _port_right(m *ice.Message, arg ...string) string {
|
||||
}
|
||||
|
||||
const (
|
||||
SOCKET = "socket"
|
||||
BEGIN = "begin"
|
||||
CURRENT = "current"
|
||||
RANDOM = "random"
|
||||
@ -43,24 +44,18 @@ const PORT = "port"
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
PORT: {Name: "port port path auto socket", Help: "端口", Actions: ice.MergeActions(ice.Actions{
|
||||
CURRENT: {Hand: func(m *ice.Message, arg ...string) { m.Echo(mdb.Config(m, CURRENT)) }},
|
||||
aaa.RIGHT: {Hand: func(m *ice.Message, arg ...string) { m.Echo(_port_right(m, arg...)) }},
|
||||
nfs.TRASH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Assert(m.Option(PORT) != "")
|
||||
nfs.Trash(m, path.Join(ice.USR_LOCAL_DAEMON, m.Option(PORT)))
|
||||
}},
|
||||
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) {
|
||||
switch arg[0] {
|
||||
case "server":
|
||||
m.Cmd(PORT, "socket", func(value ice.Maps) {
|
||||
switch value["status"] {
|
||||
case SERVER:
|
||||
m.Cmd(PORT, SOCKET, func(value ice.Maps) {
|
||||
switch value[mdb.STATUS] {
|
||||
case "LISTEN":
|
||||
m.Push(arg[0], strings.Replace(value["local"], "0.0.0.0", "127.0.0.1", 1))
|
||||
}
|
||||
})
|
||||
case "port":
|
||||
m.Cmd(PORT, "socket", func(value ice.Maps) {
|
||||
switch value["status"] {
|
||||
case PORT:
|
||||
m.Cmd(PORT, SOCKET, func(value ice.Maps) {
|
||||
switch value[mdb.STATUS] {
|
||||
case "LISTEN":
|
||||
m.Push(arg[0], strings.TrimPrefix(value["local"], "0.0.0.0:"))
|
||||
m.Push(mdb.NAME, "listen")
|
||||
@ -68,7 +63,7 @@ func init() {
|
||||
})
|
||||
}
|
||||
}},
|
||||
"socket": {Hand: func(m *ice.Message, arg ...string) {
|
||||
SOCKET: {Hand: func(m *ice.Message, arg ...string) {
|
||||
parse := func(str string) int64 {
|
||||
port, _ := strconv.ParseInt(str, 16, 32)
|
||||
return port
|
||||
@ -88,7 +83,7 @@ func init() {
|
||||
stats := map[string]int{}
|
||||
m.Spawn().Split(m.Cmdx(nfs.CAT, "/proc/net/tcp")).Table(func(value ice.Maps) {
|
||||
stats[trans(value["st"])]++
|
||||
m.Push("status", trans(value["st"]))
|
||||
m.Push(mdb.STATUS, trans(value["st"]))
|
||||
ls := kit.Split(value["local_address"], ":")
|
||||
m.Push("local", kit.Format("%d.%d.%d.%d:%d", parse(ls[0][6:8]), parse(ls[0][4:6]), parse(ls[0][2:4]), parse(ls[0][:2]), parse(ls[1])))
|
||||
ls = kit.Split(value["rem_address"], ":")
|
||||
@ -96,7 +91,7 @@ func init() {
|
||||
})
|
||||
m.Spawn().Split(m.Cmdx(nfs.CAT, "/proc/net/tcp6")).Table(func(value ice.Maps) {
|
||||
stats[trans(value["st"])]++
|
||||
m.Push("status", trans(value["st"]))
|
||||
m.Push(mdb.STATUS, trans(value["st"]))
|
||||
ls := kit.Split(value["local_address"], ":")
|
||||
m.Push("local", kit.Format("%d.%d.%d.%d:%d", parse(ls[0][30:32]), parse(ls[0][28:30]), parse(ls[0][26:28]), parse(ls[0][24:26]), parse(ls[1])))
|
||||
ls = kit.Split(value["remote_address"], ":")
|
||||
@ -104,6 +99,12 @@ func init() {
|
||||
})
|
||||
m.Sort("status,local").StatusTimeCount(stats)
|
||||
}},
|
||||
nfs.TRASH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Assert(m.Option(PORT) != "")
|
||||
nfs.Trash(m, path.Join(ice.USR_LOCAL_DAEMON, m.Option(PORT)))
|
||||
}},
|
||||
aaa.RIGHT: {Hand: func(m *ice.Message, arg ...string) { m.Echo(_port_right(m, arg...)) }},
|
||||
CURRENT: {Hand: func(m *ice.Message, arg ...string) { m.Echo(mdb.Config(m, CURRENT)) }},
|
||||
}, mdb.HashAction(BEGIN, 10000, CURRENT, 10000, END, 20000)), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) > 0 {
|
||||
m.Cmdy(nfs.DIR, arg[1:], kit.Dict(nfs.DIR_ROOT, path.Join(ice.USR_LOCAL_DAEMON, arg[0])))
|
||||
|
@ -73,7 +73,7 @@ const SERVER = "server"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
SERVER: {Name: "server hash auto prunes", Help: "服务器", Actions: ice.MergeActions(ice.Actions{
|
||||
SERVER: {Help: "服务器", Actions: ice.MergeActions(ice.Actions{
|
||||
LISTEN: {Name: "listen type name port=9030 host=", Hand: func(m *ice.Message, arg ...string) {
|
||||
switch m.Option(mdb.TYPE) {
|
||||
case UDP4:
|
||||
|
@ -20,7 +20,7 @@ func _broad_send(m *ice.Message, to_host, to_port string, host, port string, arg
|
||||
})
|
||||
}
|
||||
func _broad_serve(m *ice.Message) {
|
||||
m.GoSleep("10ms", tcp.HOST, func(value ice.Maps) {
|
||||
m.GoSleep("30ms", tcp.HOST, func(value ice.Maps) {
|
||||
_broad_send(m, "", "", value[aaa.IP], m.Option(tcp.PORT), gdb.EVENT, tcp.LISTEN, mdb.NAME, ice.Info.NodeName, mdb.TYPE, ice.Info.NodeType)
|
||||
})
|
||||
m.Cmd(tcp.SERVER, tcp.LISTEN, mdb.TYPE, tcp.UDP4, mdb.NAME, logs.FileLine(1), m.OptionSimple(tcp.HOST, tcp.PORT), func(from *net.UDPAddr, buf []byte) {
|
||||
@ -37,7 +37,7 @@ const BROAD = "broad"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
BROAD: {Name: "broad hash auto", Help: "广播", Actions: ice.MergeActions(ice.Actions{
|
||||
BROAD: {Help: "广播", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if mdb.IsSearchPreview(m, arg) {
|
||||
host, domain := m.Cmdv(tcp.HOST, aaa.IP), UserWeb(m).Hostname()
|
||||
|
@ -5,13 +5,13 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/tcp"
|
||||
"shylinux.com/x/icebergs/base/web/html"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
"shylinux.com/x/toolkits/miss"
|
||||
)
|
||||
@ -111,7 +111,10 @@ const CACHE = "cache"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
CACHE: {Name: "cache hash auto write catch upload download", Help: "缓存池", Actions: ice.MergeActions(ice.Actions{
|
||||
CACHE: {Name: "cache hash auto write catch upload", Help: "缓存池", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.RENDER_DOWNLOAD: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Echo(_share_link(m, kit.Select(arg[0], arg, 1), ice.POD, m.Option(ice.MSG_USERPOD), nfs.FILENAME, kit.Select("", arg[0], len(arg) > 1)))
|
||||
}},
|
||||
WATCH: {Name: "watch hash* path*", Hand: func(m *ice.Message, arg ...string) {
|
||||
_cache_watch(m, m.Option(mdb.HASH), m.Option(nfs.PATH))
|
||||
}},
|
||||
@ -132,9 +135,6 @@ func init() {
|
||||
_cache_save(m, m.Option(mdb.TYPE), m.Option(mdb.NAME), "", file, size)
|
||||
}
|
||||
}},
|
||||
ice.RENDER_DOWNLOAD: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Echo(_share_link(m, kit.Select(arg[0], arg, 1), ice.POD, m.Option(ice.MSG_USERPOD), nfs.FILENAME, kit.Select("", arg[0], len(arg) > 1)))
|
||||
}},
|
||||
nfs.PS: {Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashSelectDetail(m, arg[0], func(value ice.Map) {
|
||||
kit.If(kit.Format(value[nfs.FILE]), func() { m.RenderDownload(value[nfs.FILE]) }, func() { m.RenderResult(value[mdb.TEXT]) })
|
||||
@ -142,9 +142,8 @@ func init() {
|
||||
}},
|
||||
}, mdb.HashAction(mdb.SHORT, mdb.TEXT, mdb.FIELD, "time,hash,size,type,name,text,file", ctx.ACTION, WATCH), ice.RenderAction(ice.RENDER_DOWNLOAD)), Hand: func(m *ice.Message, arg ...string) {
|
||||
if mdb.HashSelect(m, arg...); len(arg) == 0 || m.R != nil && m.R.Method == http.MethodGet {
|
||||
return
|
||||
}
|
||||
if m.Append(nfs.FILE) == "" {
|
||||
m.Option(ice.MSG_ACTION, "")
|
||||
} else if m.Append(nfs.FILE) == "" {
|
||||
m.PushScript(mdb.TEXT, m.Append(mdb.TEXT))
|
||||
} else {
|
||||
PushDisplay(m, m.Append(mdb.TYPE), m.Append(mdb.NAME), MergeURL2(m, P(SHARE, CACHE, arg[0])))
|
||||
@ -183,10 +182,12 @@ func Download(m *ice.Message, link string, cb func(count, total, value int)) *ic
|
||||
return m.Cmdy(Prefix(SPIDE), ice.DEV, SPIDE_CACHE, http.MethodGet, link, cb)
|
||||
}
|
||||
func PushDisplay(m *ice.Message, mime, name, link string) {
|
||||
if strings.HasPrefix(mime, IMAGE+nfs.PS) || kit.ExtIsImage(name) {
|
||||
if html.IsImage(name, mime) {
|
||||
m.PushImages(nfs.FILE, link)
|
||||
} else if strings.HasPrefix(mime, VIDEO+nfs.PS) || kit.ExtIsImage(name) {
|
||||
} else if html.IsVideo(name, mime) {
|
||||
m.PushVideos(nfs.FILE, link)
|
||||
} else if html.IsAudio(name, mime) {
|
||||
m.PushAudios(nfs.FILE, link)
|
||||
} else {
|
||||
m.PushDownload(nfs.FILE, name, link)
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package web
|
||||
|
||||
import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
@ -11,42 +10,10 @@ const COUNT = "count"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
COUNT: &ice.Command{Name: "count hash auto prunes", Help: "计数", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if mdb.IsSearchPreview(m, arg) {
|
||||
count, limit, list := 0, 5, map[string]bool{}
|
||||
mdb.HashSelect(m.Spawn(kit.Dict(ice.MSG_FIELDS, mdb.Config(m, mdb.FIELD)))).Sort(mdb.TIME, "time_r").Table(func(value ice.Maps) {
|
||||
switch value[mdb.TYPE] {
|
||||
case ctx.ACTION:
|
||||
if list[value[mdb.NAME]] {
|
||||
break
|
||||
}
|
||||
if count++; count <= limit {
|
||||
list[value[mdb.NAME]] = true
|
||||
m.PushSearch(mdb.TYPE, ice.CMD, value)
|
||||
}
|
||||
}
|
||||
})
|
||||
count, limit = 0, 5
|
||||
mdb.HashSelect(m.Spawn(kit.Dict(ice.MSG_FIELDS, mdb.Config(m, mdb.FIELD)))).Sort(mdb.COUNT, "int_r").Table(func(value ice.Maps) {
|
||||
switch value[mdb.TYPE] {
|
||||
case ctx.ACTION:
|
||||
if list[value[mdb.NAME]] {
|
||||
break
|
||||
}
|
||||
if count++; count <= limit {
|
||||
list[value[mdb.NAME]] = true
|
||||
m.PushSearch(mdb.TYPE, ice.CMD, value)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}},
|
||||
COUNT: &ice.Command{Help: "计数", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.CREATE: {Name: "create type name text", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashSelectUpdate(m, mdb.HashCreate(m), func(value ice.Map) { value[mdb.COUNT] = kit.Int(value[mdb.COUNT]) + 1 })
|
||||
}},
|
||||
}, mdb.HashAction(mdb.LIMIT, 1000, mdb.LEAST, 500, mdb.SHORT, "type,name", mdb.FIELD, "time,hash,count,type,name,text")), Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashSelect(m, arg...).Sort("type,name,text")
|
||||
}},
|
||||
}, mdb.HashAction(mdb.LIMIT, 1000, mdb.LEAST, 500, mdb.SHORT, "type,name", mdb.FIELD, "time,hash,count,type,name,text", mdb.SORT, "type,name,text"))},
|
||||
})
|
||||
}
|
||||
|
@ -21,8 +21,8 @@ import (
|
||||
)
|
||||
|
||||
func _dream_list(m *ice.Message) *ice.Message {
|
||||
list := m.CmdMap(SPACE, mdb.NAME)
|
||||
stats := map[string]int{}
|
||||
list := m.CmdMap(SPACE, mdb.NAME)
|
||||
mdb.HashSelect(m).Table(func(value ice.Maps) {
|
||||
if space, ok := list[value[mdb.NAME]]; ok {
|
||||
msg := gdb.Event(m.Spawn(value, space), DREAM_TABLES).Copy(m.Spawn().PushButton(cli.STOP))
|
||||
@ -32,23 +32,22 @@ func _dream_list(m *ice.Message) *ice.Message {
|
||||
m.Push(mdb.TEXT, msg.Append(mdb.TEXT))
|
||||
m.PushButton(strings.Join(msg.Appendv(ctx.ACTION), ""))
|
||||
stats[cli.START]++
|
||||
} else if nfs.Exists(m, path.Join(ice.USR_LOCAL_WORK, value[mdb.NAME])) {
|
||||
m.Push(nfs.VERSION, "")
|
||||
m.Push(mdb.TYPE, WORKER)
|
||||
m.Push(cli.STATUS, cli.STOP)
|
||||
m.Push(mdb.TEXT, "")
|
||||
m.PushButton(cli.START, nfs.TRASH)
|
||||
stats[cli.STOP]++
|
||||
} else {
|
||||
m.Push(nfs.VERSION, "")
|
||||
m.Push(mdb.TYPE, WORKER)
|
||||
m.Push(cli.STATUS, cli.STOP)
|
||||
m.Push(mdb.TEXT, "")
|
||||
m.PushButton(cli.START, mdb.REMOVE)
|
||||
stats[ice.INIT]++
|
||||
if nfs.Exists(m, path.Join(ice.USR_LOCAL_WORK, value[mdb.NAME])) {
|
||||
m.PushButton(cli.START, nfs.TRASH)
|
||||
stats[cli.STOP]++
|
||||
} else {
|
||||
m.PushButton(cli.START, mdb.REMOVE)
|
||||
stats[ice.INIT]++
|
||||
}
|
||||
}
|
||||
})
|
||||
return m.Sort("status,type,name", ice.STR, ice.STR, ice.STR_R).StatusTimeCount(stats)
|
||||
|
||||
}
|
||||
func _dream_start(m *ice.Message, name string) {
|
||||
if m.Warn(name == "", ice.ErrNotValid, mdb.NAME) {
|
||||
@ -283,13 +282,12 @@ func init() {
|
||||
}},
|
||||
}, DreamAction(), mdb.ImportantHashAction(mdb.SHORT, mdb.NAME, mdb.FIELD, "time,name,icon,repos,binary,template")), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
_dream_list(m)
|
||||
m.RewriteAppend(func(value, key string, index int) string {
|
||||
_dream_list(m).RewriteAppend(func(value, key string, index int) string {
|
||||
if key == mdb.ICON {
|
||||
return kit.MergeURL(ctx.FileURI(value), ice.POD, m.Appendv(mdb.NAME)[index])
|
||||
}
|
||||
return value
|
||||
})
|
||||
}).Option(ice.MSG_ACTION, "")
|
||||
ctx.DisplayTableCard(m)
|
||||
} else if arg[0] == ctx.ACTION {
|
||||
gdb.Event(m, DREAM_ACTION, arg)
|
||||
|
@ -22,7 +22,9 @@ type Message interface {
|
||||
PrefixKey() string
|
||||
}
|
||||
|
||||
func UserWeb(m Message) *url.URL { return kit.ParseURL(m.Option(ice.MSG_USERWEB)) }
|
||||
func UserWeb(m Message) *url.URL {
|
||||
return kit.ParseURL(m.Option(ice.MSG_USERWEB))
|
||||
}
|
||||
func UserHost(m *ice.Message) string {
|
||||
if u := UserWeb(m); strings.Contains(u.Host, tcp.LOCALHOST) {
|
||||
return m.Option(ice.MSG_USERHOST, tcp.PublishLocalhost(m, u.Scheme+"://"+u.Host))
|
||||
@ -38,14 +40,16 @@ func AgentIs(m Message, arg ...string) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
func MergeURL2(m Message, url string, arg ...ice.Any) string {
|
||||
func MergeURL2(m *ice.Message, url string, arg ...ice.Any) string {
|
||||
kit.If(m.Option(log.DEBUG) == ice.TRUE, func() { arg = append(arg, log.DEBUG, ice.TRUE) })
|
||||
kit.If(m.Option(ice.MSG_USERWEB) == "", func() {
|
||||
m.Debug("what %v", 123)
|
||||
m.Option(ice.MSG_USERWEB, Domain(ice.Pulse.Cmdv(tcp.HOST, aaa.IP), ice.Pulse.Cmdv(SERVE, tcp.PORT)))
|
||||
m.Debug("what %v", 123)
|
||||
})
|
||||
return kit.MergeURL2(m.Option(ice.MSG_USERWEB), url, arg...)
|
||||
}
|
||||
func MergeLink(m Message, url string, arg ...ice.Any) string {
|
||||
func MergeLink(m *ice.Message, url string, arg ...ice.Any) string {
|
||||
kit.If(m.Option(log.DEBUG) == ice.TRUE, func() { arg = append(arg, log.DEBUG, ice.TRUE) })
|
||||
return kit.MergeURL(strings.Split(MergeURL2(m, url), QS)[0], arg...)
|
||||
}
|
||||
@ -61,7 +65,6 @@ func PushPodCmd(m *ice.Message, cmd string, arg ...string) {
|
||||
list := []string{}
|
||||
m.Cmds(SPACE, func(value ice.Maps) {
|
||||
kit.If(kit.IsIn(value[mdb.TYPE], WORKER), func() { list = append(list, value[mdb.NAME]) })
|
||||
// kit.If(kit.IsIn(value[mdb.TYPE], WORKER, SERVER), func() { list = append(list, value[mdb.NAME]) })
|
||||
})
|
||||
if len(list) == 0 {
|
||||
return
|
||||
@ -111,12 +114,8 @@ func Toast(m *ice.Message, text string, arg ...ice.Any) { // [title [duration [p
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(arg) == 0 {
|
||||
arg = append(arg, m.PrefixKey())
|
||||
}
|
||||
if len(arg) > 0 {
|
||||
arg[0] = kit.Select(m.PrefixKey(), arg[0])
|
||||
}
|
||||
kit.If(len(arg) == 0, func() { arg = append(arg, m.PrefixKey()) })
|
||||
kit.If(len(arg) > 0, func() { arg[0] = kit.Select(m.PrefixKey(), arg[0]) })
|
||||
PushNoticeToast(m, text, arg)
|
||||
}
|
||||
func toastContent(m *ice.Message, state string) string {
|
||||
|
@ -143,6 +143,7 @@ func init() {
|
||||
}
|
||||
})
|
||||
m.Sort("status,space", ice.STR_R, ice.STR).StatusTimeCount(stat)
|
||||
m.Option(ice.MSG_ACTION, "")
|
||||
}
|
||||
}},
|
||||
})
|
||||
|
@ -198,7 +198,9 @@ func init() {
|
||||
}
|
||||
}},
|
||||
cli.SYSTEM: {Help: "系统", Hand: func(m *ice.Message, arg ...string) { cli.Opens(m, "System Settings.app") }},
|
||||
cli.START: {Name: "start dev proto host port=9020 nodename username usernick", Hand: func(m *ice.Message, arg ...string) { _serve_start(m) }},
|
||||
cli.START: {Name: "start dev proto host port=9020 nodename username usernick", Hand: func(m *ice.Message, arg ...string) {
|
||||
_serve_start(m)
|
||||
}},
|
||||
SERVE_START: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Go(func() {
|
||||
m.Option(ice.MSG_USERIP, "127.0.0.1")
|
||||
@ -207,7 +209,7 @@ func init() {
|
||||
})
|
||||
}},
|
||||
}, mdb.HashAction(mdb.SHORT, mdb.NAME, mdb.FIELD, "time,status,name,proto,host,port"), mdb.ClearOnExitHashAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashSelect(m, arg...).StatusTimeCount(ice.MAIN, mdb.Config(m, ice.MAIN))
|
||||
mdb.HashSelect(m, arg...).Options(ice.MSG_ACTION, "").StatusTimeCount(kit.Dict(ice.MAIN, mdb.Config(m, ice.MAIN)))
|
||||
}},
|
||||
})
|
||||
ice.AddMergeAction(func(c *ice.Context, key string, cmd *ice.Command, sub string, action *ice.Action) {
|
||||
|
@ -62,7 +62,7 @@ const SHARE = "share"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
SHARE: {Name: "share hash auto login prunes", Help: "共享链", Actions: ice.MergeActions(ice.Actions{
|
||||
SHARE: {Name: "share hash auto login", Help: "共享链", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.CREATE: {Name: "create type name text", Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.If(m.Option(mdb.TYPE) == LOGIN, func() { arg = append(arg, mdb.TEXT, tcp.PublishLocalhost(m, m.Option(mdb.TEXT))) })
|
||||
mdb.HashCreate(m, arg, aaa.USERNICK, m.Option(ice.MSG_USERNICK), aaa.USERNAME, m.Option(ice.MSG_USERNAME), aaa.USERROLE, m.Option(ice.MSG_USERROLE))
|
||||
|
@ -29,14 +29,19 @@ func _space_qrcode(m *ice.Message, dev string) {
|
||||
func _space_dial(m *ice.Message, dev, name string, arg ...string) {
|
||||
u := kit.ParseURL(kit.MergeURL2(strings.Replace(m.Cmdv(SPIDE, dev, CLIENT_ORIGIN), HTTP, "ws", 1), PP(SPACE), mdb.TYPE, ice.Info.NodeType, mdb.NAME, name,
|
||||
nfs.MODULE, ice.Info.Make.Module, nfs.VERSION, ice.Info.Make.Versions(), arg))
|
||||
args := kit.SimpleKV("type,name,host,port", u.Scheme, dev, u.Hostname(), kit.Select(kit.Select("443", "80", u.Scheme == "ws"), u.Port()))
|
||||
m.Debug("what %v", m.Cmd(SPIDE, dev).FormatsMeta(nil))
|
||||
m.Debug("what %v", u)
|
||||
m.Debug("what %v", kit.Formats(m.Confv(SPIDE)))
|
||||
m.Debug("what %v", m.Cmdv(SPIDE, dev, CLIENT_ORIGIN))
|
||||
args := kit.SimpleKV("type,name,host,port", u.Scheme, dev, u.Hostname(),
|
||||
kit.Select(kit.Select("443", "80", u.Scheme == "ws"), u.Port()))
|
||||
gdb.Go(m, func() {
|
||||
once := sync.Once{}
|
||||
redial := kit.Dict(mdb.Configv(m, REDIAL))
|
||||
a, b, c := kit.Int(redial["a"]), kit.Int(redial["b"]), kit.Int(redial["c"])
|
||||
for i := 1; i < c; i++ {
|
||||
next := time.Duration(rand.Intn(a*(i+1))+b*i) * time.Millisecond
|
||||
m.Cmd(tcp.CLIENT, tcp.DIAL, args, func(c net.Conn) {
|
||||
m.Spawn().Cmd(tcp.CLIENT, tcp.DIAL, args, func(c net.Conn) {
|
||||
if c, e := websocket.NewClient(c, u); !m.Warn(e, tcp.DIAL, dev, SPACE, u.String()) {
|
||||
defer mdb.HashCreateDeferRemove(m, kit.SimpleKV("", MASTER, dev, u.Host), kit.Dict(mdb.TARGET, c))()
|
||||
kit.If(ice.Info.Colors, func() { once.Do(func() { m.Go(func() { _space_qrcode(m, dev) }) }) })
|
||||
@ -81,10 +86,12 @@ func _space_fork(m *ice.Message) {
|
||||
}
|
||||
func _space_handle(m *ice.Message, safe bool, name string, c *websocket.Conn) {
|
||||
defer m.Cost(SPACE, name)
|
||||
m.Debug("what %v", name)
|
||||
m.Options(ice.MSG_USERROLE, "", mdb.TYPE, "", mdb.NAME, "", cli.DAEMON, "")
|
||||
for {
|
||||
_, b, e := c.ReadMessage()
|
||||
if e != nil {
|
||||
m.Debug("what %v", e)
|
||||
break
|
||||
}
|
||||
msg := m.Spawn(b)
|
||||
@ -209,7 +216,7 @@ func init() {
|
||||
return false
|
||||
}
|
||||
Index.MergeCommands(ice.Commands{
|
||||
SPACE: {Name: "space name cmds auto", Help: "空间站", Actions: ice.MergeActions(ice.Actions{
|
||||
SPACE: {Help: "空间站", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { aaa.White(m, SPACE, ice.MAIN) }},
|
||||
ice.MAIN: {Name: "main index", Help: "首页", Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) > 0 {
|
||||
|
@ -265,9 +265,37 @@ const (
|
||||
const SPIDE = "spide"
|
||||
|
||||
func init() {
|
||||
nfs.TemplatePath = func(m *ice.Message, arg ...string) string {
|
||||
if p := path.Join(ice.SRC_TEMPLATE, m.PrefixKey(), path.Join(arg...)); nfs.Exists(m, p) {
|
||||
return p + kit.Select("", nfs.PS, len(arg) == 0)
|
||||
} else {
|
||||
return path.Join(path.Dir(ctx.GetCmdFile(m, m.PrefixKey())), path.Join(arg...)) + kit.Select("", nfs.PS, len(arg) == 0)
|
||||
}
|
||||
}
|
||||
nfs.TemplateText = func(m *ice.Message, p string) string {
|
||||
if p := nfs.TemplatePath(m, path.Base(p)); kit.HasPrefix(p, "/require/", ice.HTTP) {
|
||||
return m.Cmdx(SPIDE, ice.DEV, SPIDE_RAW, http.MethodGet, p)
|
||||
} else {
|
||||
return m.Cmdx(nfs.CAT, p)
|
||||
}
|
||||
}
|
||||
nfs.DocumentPath = func(m *ice.Message, arg ...string) string {
|
||||
if p := path.Join(ice.SRC_DOCUMENT, m.PrefixKey(), path.Join(arg...)); nfs.Exists(m, p) {
|
||||
return p + kit.Select("", nfs.PS, len(arg) == 0)
|
||||
} else {
|
||||
return path.Join(path.Dir(ctx.GetCmdFile(m, m.PrefixKey())), path.Join(arg...)) + kit.Select("", nfs.PS, len(arg) == 0)
|
||||
}
|
||||
}
|
||||
nfs.DocumentText = func(m *ice.Message, p string) string {
|
||||
if p := nfs.DocumentPath(m, path.Base(p)); kit.HasPrefix(p, "/require/", ice.HTTP) {
|
||||
return m.Cmdx(SPIDE, ice.DEV, SPIDE_RAW, http.MethodGet, p)
|
||||
} else {
|
||||
return m.Cmdx(nfs.CAT, p)
|
||||
}
|
||||
}
|
||||
Index.MergeCommands(ice.Commands{
|
||||
// SPIDE: {Name: "spide client.name action=raw,msg,save,cache method=GET,PUT,POST,DELETE url format=form,part,json,data,file arg run create", Help: "蜘蛛侠", Actions: ice.MergeActions(ice.Actions{
|
||||
SPIDE: {Name: "spide client.name auto", Help: "蜘蛛侠", Actions: ice.MergeActions(ice.Actions{
|
||||
SPIDE: {Help: "蜘蛛侠", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
conf := mdb.Confm(m, cli.RUNTIME, cli.CONF)
|
||||
m.Cmd("", mdb.CREATE, ice.OPS, kit.Select("http://127.0.0.1:9020", conf[cli.CTX_OPS]))
|
||||
|
@ -23,7 +23,7 @@ func init() {
|
||||
LOCAL = "http://localhost:9020"
|
||||
)
|
||||
Index.MergeCommands(ice.Commands{
|
||||
TOKEN: {Name: "token hash auto prunes", Help: "令牌", Actions: ice.MergeActions(ice.Actions{
|
||||
TOKEN: {Help: "令牌", Actions: ice.MergeActions(ice.Actions{
|
||||
GEN: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Echo("请授权 %s 代码权限\n", m.Option(tcp.HOST)).EchoButton(CONFIRM)
|
||||
}},
|
||||
|
@ -59,7 +59,7 @@ func (f *Frame) Start(m *ice.Message, arg ...string) {
|
||||
case func(http.Handler):
|
||||
cb(f)
|
||||
default:
|
||||
m.Cmdy(tcp.SERVER, tcp.LISTEN, mdb.TYPE, HTTP, mdb.NAME, logs.FileLine(1), m.OptionSimple(tcp.HOST, tcp.PORT), func(l net.Listener) {
|
||||
m.Spawn().Cmdy(tcp.SERVER, tcp.LISTEN, mdb.TYPE, HTTP, mdb.NAME, logs.FileLine(1), m.OptionSimple(tcp.HOST, tcp.PORT), func(l net.Listener) {
|
||||
defer mdb.HashCreateDeferRemove(m, m.OptionSimple(mdb.NAME, tcp.PROTO), arg, cli.STATUS, tcp.START)()
|
||||
gdb.Event(m, SERVE_START, arg)
|
||||
m.Warn(f.Server.Serve(l))
|
||||
@ -77,7 +77,10 @@ const WEB = "web"
|
||||
var Index = &ice.Context{Name: WEB, Help: "网络模块"}
|
||||
|
||||
func init() {
|
||||
ice.Index.Register(Index, &Frame{}, COUNT, BROAD, SERVE, SPACE, DREAM, CACHE, SPIDE, SHARE)
|
||||
ice.Index.Register(Index, &Frame{},
|
||||
BROAD, SERVE, DREAM, ROUTE, SPACE,
|
||||
TOKEN, SHARE, CACHE, SPIDE, COUNT,
|
||||
)
|
||||
}
|
||||
|
||||
func ApiAction(arg ...string) ice.Actions { return ice.Actions{kit.Select(nfs.PS, arg, 0): {}} }
|
||||
|
@ -23,7 +23,7 @@ const FAVOR = "favor"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
FAVOR: {Name: "favor hash auto create upload getClipboardData", Help: "收藏夹", Icon: "favor.png", Actions: ice.MergeActions(ice.Actions{
|
||||
FAVOR: {Help: "收藏夹", Icon: "favor.png", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if mdb.IsSearchPreview(m, arg) {
|
||||
m.Cmds("", func(value ice.Maps) {
|
||||
@ -91,18 +91,18 @@ func init() {
|
||||
}
|
||||
return
|
||||
}
|
||||
if len(arg) == 0 {
|
||||
if m.IsMobileUA() {
|
||||
m.Action("getLocation", "scanQRCode")
|
||||
} else {
|
||||
m.Action("record1", "record2")
|
||||
}
|
||||
}
|
||||
if mdb.HashSelect(m, arg...); len(arg) > 0 {
|
||||
text := m.Append(mdb.TEXT)
|
||||
m.PushQRCode(cli.QRCODE, text)
|
||||
m.PushScript(text)
|
||||
}
|
||||
if len(arg) == 0 {
|
||||
if m.IsMobileUA() {
|
||||
m.Action("upload", "getClipboardData", "getLocation", "scanQRCode")
|
||||
} else {
|
||||
m.Action("getClipboardData", "upload", "record1", "record2")
|
||||
}
|
||||
}
|
||||
m.Table(func(value ice.Maps) {
|
||||
delete(value, ctx.ACTION)
|
||||
if msg := gdb.Event(m.Spawn(value), FAVOR_TABLES, mdb.TYPE, value[mdb.TYPE]); msg.Append(ctx.ACTION) != "" {
|
||||
|
@ -29,7 +29,7 @@ func init() {
|
||||
}},
|
||||
}, mdb.ExportHashAction(mdb.SHORT, mdb.ZONE, mdb.FIELD, "time,zone", mdb.FIELDS, "time,hash,name,space,index,args,prev,from,status")), Hand: func(m *ice.Message, arg ...string) {
|
||||
if arg = kit.Slice(arg, 0, 2); len(arg) == 0 || arg[0] == "" {
|
||||
mdb.HashSelect(m)
|
||||
mdb.HashSelect(m).Option(ice.MSG_ACTION, "")
|
||||
} else {
|
||||
m.Fields(len(arg)-1, mdb.Config(m, mdb.FIELDS), mdb.DETAIL)
|
||||
m.Cmdy(mdb.SELECT, m.PrefixKey(), kit.KeyHash(arg[0]), mdb.HASH, arg[1:])
|
||||
|
@ -2,7 +2,7 @@
|
||||
Volcanos(chat.ONIMPORT, {
|
||||
_init: function(can, msg, cb) { can.ui = can.onappend.layout(can), cb && cb(msg)
|
||||
can.core.Item(can.Action(), function(key) { can.onaction[key] = can.onaction[key]||can.onaction.refresh, can.Action(key, can.misc.localStorage(can, ACTION_STORE+key)) })
|
||||
if (can.Option(mdb.ZONE)) { return can.onmotion.hidden(can, can.ui.project), can.onimport._content(can, msg, can.Option(mdb.ZONE)) } can.onimport._project(can, msg)
|
||||
if (can.Option(mdb.ZONE)) { can.onmotion.hidden(can, can.ui.project), can.onimport._content(can, msg, can.Option(mdb.ZONE)) } else { can.onimport._project(can, msg) }
|
||||
},
|
||||
_project: function(can, msg) { var target; msg.Table(function(value) {
|
||||
var item = can.onimport.item(can, value, function(event) { can.Option(mdb.ZONE, value.zone)
|
||||
|
@ -28,7 +28,7 @@ func init() {
|
||||
}))
|
||||
}
|
||||
Index.MergeCommands(ice.Commands{
|
||||
LOCATION: {Name: "location hash auto", Help: "地图", Icon: "Maps.png", Actions: ice.MergeActions(ice.Actions{
|
||||
LOCATION: {Help: "地图", Icon: "Maps.png", Actions: ice.MergeActions(ice.Actions{
|
||||
"explore": {Help: "周边", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Echo(get(m, "place/v1/explore", m.OptionSimple("keyword,boundary,page_index")))
|
||||
}},
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
const FINDER = "finder"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{FINDER: {Name: "finder list insert", Help: "应用", Actions: ice.MergeActions(ice.Actions{
|
||||
Index.MergeCommands(ice.Commands{FINDER: {Name: "finder list", Help: "应用", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(APPLICATIONS, mdb.INPUTS, arg) }},
|
||||
mdb.INSERT: {Name: "insert space index* args name* icon*@icon", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(APPLICATIONS, mdb.CREATE, arg) }},
|
||||
}, CmdHashAction(mdb.NAME))}})
|
||||
|
@ -45,7 +45,7 @@ func CmdHashAction(arg ...string) ice.Actions {
|
||||
m.Cmd(nfs.DIR, ice.USR_ICONS, func(value ice.Maps) { m.Push(arg[0], kit.TrimExt(value[nfs.PATH], nfs.PNG)) })
|
||||
}
|
||||
}},
|
||||
mdb.SELECT: {Name: "list hash auto create", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.SELECT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashSelect(m, arg...).Sort(mdb.NAME).Display(ctx.FileURI(file))
|
||||
}},
|
||||
}, mdb.HashAction(mdb.SHORT, kit.Select("", arg, 0), mdb.FIELD, kit.Select("time,hash,icon,name,text,space,index,args", arg, 1), kit.Slice(arg, 2)))
|
||||
|
@ -103,7 +103,7 @@ func (s Client) List(m *ice.Message, arg ...string) {
|
||||
func init() { ice.ChatCtxCmd(Client{}) }
|
||||
|
||||
func (s Client) RedirectURI(m *ice.Message) string {
|
||||
return strings.Split(web.MergeURL2(m, web.ChatCmdPath(m.Message, m.PrefixKey(), ctx.ACTION, aaa.LOGIN)), web.QS)[0]
|
||||
return strings.Split(web.MergeURL2(m.Message, web.ChatCmdPath(m.Message, m.PrefixKey(), ctx.ACTION, aaa.LOGIN)), web.QS)[0]
|
||||
}
|
||||
func (s Client) Login(m *ice.Message, arg ...string) {
|
||||
if state, code := m.Option(STATE), m.Option(CODE); !m.Warn(state == "" || code == "") {
|
||||
|
@ -30,8 +30,12 @@ func _autogen_source(m *ice.Message, main, file string) {
|
||||
m.Cmd(nfs.DEFS, main, m.Cmdx(nfs.CAT, ice.SRC_MAIN_SHY))
|
||||
m.Cmd(nfs.PUSH, main, lex.NL+ssh.SOURCE+lex.SP+strings.TrimPrefix(file, ice.SRC+nfs.PS)+lex.NL)
|
||||
}
|
||||
func _autogen_script(m *ice.Message, file string) { m.Cmd(nfs.DEFS, file, nfs.Template(m, "demo.shy")) }
|
||||
func _autogen_module(m *ice.Message, file string) { m.Cmd(nfs.DEFS, file, nfs.Template(m, "demo.go")) }
|
||||
func _autogen_script(m *ice.Message, file string) {
|
||||
m.Cmd(nfs.DEFS, file, nfs.Template(m, "demo.shy"))
|
||||
}
|
||||
func _autogen_module(m *ice.Message, file string) {
|
||||
m.Cmd(nfs.DEFS, file, nfs.Template(m, "demo.go"))
|
||||
}
|
||||
func _autogen_import(m *ice.Message, main string, ctx string, mod string) {
|
||||
m.Cmd(nfs.DEFS, ice.ETC_MISS_SH, m.Cmdx(nfs.CAT, ice.ETC_MISS_SH))
|
||||
m.Cmd(nfs.DEFS, ice.README_MD, m.Cmdx(nfs.CAT, ice.README_MD))
|
||||
@ -94,7 +98,7 @@ func _autogen_mod(m *ice.Message, file string) (mod string) {
|
||||
} else {
|
||||
host = path.Join(host, "x", path.Base(kit.Path("")))
|
||||
}
|
||||
m.Cmd(nfs.DEFS, file, nfs.Template(m, ice.GO_MOD, host))
|
||||
m.Cmd(nfs.DEFS, file, kit.Format(nfs.Template(m, ice.GO_MOD), host))
|
||||
m.Cmd(nfs.CAT, file, func(line string) {
|
||||
kit.If(strings.HasPrefix(line, nfs.MODULE), func() { mod = kit.Split(line, lex.SP)[1] })
|
||||
})
|
||||
|
@ -55,10 +55,10 @@ func _css_show(m *ice.Message, arg ...string) {
|
||||
func _css_exec(m *ice.Message, arg ...string) {
|
||||
if arg[2] == ice.USR_VOLCANOS {
|
||||
if strings.HasPrefix(arg[1], ice.PLUGIN_LOCAL) {
|
||||
ctx.ProcessCommand(m, kit.Select(ice.CAN_PLUGIN, "web."+strings.Replace(kit.TrimExt(strings.TrimPrefix(arg[1], ice.PLUGIN_LOCAL), JS), nfs.PS, nfs.PT, -1)), kit.Simple())
|
||||
ctx.ProcessField(m, kit.Select(ice.CAN_PLUGIN, "web."+strings.Replace(kit.TrimExt(strings.TrimPrefix(arg[1], ice.PLUGIN_LOCAL), JS), nfs.PS, nfs.PT, -1)), kit.Simple())
|
||||
}
|
||||
} else {
|
||||
ctx.ProcessCommand(m, kit.Select(ice.CAN_PLUGIN, ctx.GetFileCmd(kit.ExtChange(path.Join(arg[2], arg[1]), GO))), kit.Simple())
|
||||
ctx.ProcessField(m, kit.Select(ice.CAN_PLUGIN, ctx.GetFileCmd(kit.ExtChange(path.Join(arg[2], arg[1]), GO))), kit.Simple())
|
||||
m.Push(ctx.STYLE, require(arg[2], arg[1]))
|
||||
}
|
||||
}
|
||||
|
@ -113,11 +113,11 @@ func init() {
|
||||
} else if arg[1] == "misc/xterm/iterm.go" {
|
||||
ProcessXterm(m, "ish", "", arg[1])
|
||||
} else if cmd := ctx.GetFileCmd(path.Join(arg[2], arg[1])); cmd != "" {
|
||||
ctx.ProcessCommand(m, cmd, kit.Simple())
|
||||
ctx.ProcessField(m, cmd, kit.Simple())
|
||||
} else if msg := m.Cmd(yac.STACK, path.Join(arg[2], arg[1])); msg.Option("__index") != "" {
|
||||
ctx.ProcessCommand(m, msg.Option("__index"), kit.Simple())
|
||||
ctx.ProcessField(m, msg.Option("__index"), kit.Simple())
|
||||
} else {
|
||||
ctx.ProcessCommand(m, yac.STACK, kit.Simple(path.Join(arg[2], arg[1])))
|
||||
ctx.ProcessField(m, yac.STACK, kit.Simple(path.Join(arg[2], arg[1])))
|
||||
}
|
||||
}},
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
@ -126,11 +126,11 @@ func init() {
|
||||
} else if arg[1] == "misc/xterm/iterm.go" {
|
||||
ProcessXterm(m, "ish", "", arg[1])
|
||||
} else if cmd := ctx.GetFileCmd(path.Join(arg[2], arg[1])); cmd != "" {
|
||||
ctx.ProcessCommand(m, cmd, kit.Simple())
|
||||
ctx.ProcessField(m, cmd, kit.Simple())
|
||||
} else if msg := m.Cmd(yac.STACK, path.Join(arg[2], arg[1])); msg.Option("__index") != "" {
|
||||
ctx.ProcessCommand(m, msg.Option("__index"), kit.Simple())
|
||||
ctx.ProcessField(m, msg.Option("__index"), kit.Simple())
|
||||
} else {
|
||||
ctx.ProcessCommand(m, yac.STACK, kit.Simple(path.Join(arg[2], arg[1])))
|
||||
ctx.ProcessField(m, yac.STACK, kit.Simple(path.Join(arg[2], arg[1])))
|
||||
}
|
||||
}},
|
||||
TEMPLATE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
|
@ -15,11 +15,11 @@ import (
|
||||
func _js_show(m *ice.Message, arg ...string) {
|
||||
if arg[2] == ice.USR_VOLCANOS {
|
||||
if strings.HasPrefix(arg[1], "plugin/local/") {
|
||||
ctx.ProcessCommand(m, kit.Select(ice.CAN_PLUGIN, "web."+strings.Replace(strings.TrimSuffix(strings.TrimPrefix(arg[1], "plugin/local/"), nfs.PT+JS), nfs.PS, nfs.PT, -1)), kit.Simple())
|
||||
ctx.ProcessField(m, kit.Select(ice.CAN_PLUGIN, "web."+strings.Replace(strings.TrimSuffix(strings.TrimPrefix(arg[1], "plugin/local/"), nfs.PT+JS), nfs.PS, nfs.PT, -1)), kit.Simple())
|
||||
}
|
||||
} else {
|
||||
ctx.DisplayBase(m, require(arg[2], arg[1]))
|
||||
ctx.ProcessCommand(m, kit.Select(ice.CAN_PLUGIN, ctx.GetFileCmd(kit.ExtChange(path.Join(arg[2], arg[1]), GO))), kit.Simple())
|
||||
ctx.ProcessField(m, kit.Select(ice.CAN_PLUGIN, ctx.GetFileCmd(kit.ExtChange(path.Join(arg[2], arg[1]), GO))), kit.Simple())
|
||||
}
|
||||
|
||||
}
|
||||
@ -31,7 +31,7 @@ func init() {
|
||||
JS: {Name: "js path auto", Help: "前端", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if arg[1] == "main.js" {
|
||||
ctx.ProcessCommand(m, "web.chat.iframe", kit.Simple(web.UserHost(m)))
|
||||
ctx.ProcessField(m, "web.chat.iframe", kit.Simple(web.UserHost(m)))
|
||||
} else {
|
||||
_js_show(m, arg...)
|
||||
}
|
||||
|
@ -19,17 +19,17 @@ func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
SHY: {Name: "shy path auto", Help: "笔记", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) {
|
||||
ctx.ProcessCommand(m, web.WIKI_WORD, kit.Simple(path.Join(arg[2], arg[1])))
|
||||
ctx.ProcessField(m, web.WIKI_WORD, kit.Simple(path.Join(arg[2], arg[1])))
|
||||
return
|
||||
ctx.ProcessCommand(m, yac.STACK, kit.Simple(path.Join(arg[2], arg[1])))
|
||||
ctx.ProcessField(m, yac.STACK, kit.Simple(path.Join(arg[2], arg[1])))
|
||||
}},
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
ctx.ProcessCommand(m, web.WIKI_WORD, kit.Simple(path.Join(arg[2], arg[1])))
|
||||
ctx.ProcessField(m, web.WIKI_WORD, kit.Simple(path.Join(arg[2], arg[1])))
|
||||
return
|
||||
if msg := m.Cmd(yac.STACK, path.Join(arg[2], arg[1])); msg.Option("__index") != "" {
|
||||
ctx.ProcessCommand(m, msg.Option("__index"), kit.Simple())
|
||||
ctx.ProcessField(m, msg.Option("__index"), kit.Simple())
|
||||
} else {
|
||||
ctx.ProcessCommand(m, yac.STACK, kit.Simple(path.Join(arg[2], arg[1])))
|
||||
ctx.ProcessField(m, yac.STACK, kit.Simple(path.Join(arg[2], arg[1])))
|
||||
}
|
||||
}},
|
||||
TEMPLATE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
|
@ -87,7 +87,7 @@ func init() {
|
||||
m.Push(arg[0], ONCE, STEP, WEEK)
|
||||
case ctx.INDEX, ctx.ARGS:
|
||||
m.Option(ctx.INDEX, m.Option("extra.index"))
|
||||
ctx.CmdInputs(m, arg...)
|
||||
mdb.ZoneInputs(m, arg)
|
||||
default:
|
||||
mdb.ZoneInputs(m, arg)
|
||||
}
|
||||
|
@ -55,7 +55,11 @@ func _wiki_upload(m *ice.Message, dir string) {
|
||||
m.Cmdy(web.CACHE, web.WATCH, m.Option(ice.MSG_UPLOAD), _wiki_path(m, dir, m.Option(mdb.NAME)))
|
||||
}
|
||||
func _wiki_template(m *ice.Message, file, name, text string, arg ...string) *ice.Message {
|
||||
return m.Echo(nfs.Template(&Message{_option(m, m.CommandKey(), name, strings.TrimSpace(text), arg...)}, kit.Keys(kit.Select(m.CommandKey(), file), nfs.HTML)))
|
||||
msg := _option(m, m.CommandKey(), name, strings.TrimSpace(text), arg...)
|
||||
return m.Echo(nfs.Template(msg,
|
||||
kit.Keys(kit.Select(m.CommandKey(), file), nfs.HTML),
|
||||
&Message{msg},
|
||||
))
|
||||
}
|
||||
|
||||
const WIKI = "wiki"
|
||||
@ -66,7 +70,7 @@ func init() {
|
||||
web.Index.Register(Index, &web.Frame{},
|
||||
TITLE, BRIEF, REFER, SPARK, PARSE, FIELD,
|
||||
ORDER, TABLE, CHART, IMAGE, VIDEO, AUDIO,
|
||||
WORD, DATA, DRAW, FEEL, PORTAL,
|
||||
WORD, DATA, DRAW, FEEL, STYLE, PORTAL,
|
||||
)
|
||||
}
|
||||
func Prefix(arg ...string) string { return web.Prefix(WIKI, kit.Keys(arg)) }
|
||||
|
@ -3,6 +3,7 @@ package chrome
|
||||
import (
|
||||
"shylinux.com/x/ice"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/web"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
@ -30,8 +31,8 @@ func (s daemon) Inputs(m *ice.Message, arg ...string) {
|
||||
}
|
||||
})
|
||||
}).Sort(arg[0])
|
||||
case ctx.INDEX:
|
||||
ctx.CmdList(m.Message)
|
||||
case ctx.INDEX, ctx.ARGS:
|
||||
mdb.HashInputs(m.Message, arg)
|
||||
}
|
||||
}
|
||||
func (s daemon) List(m *ice.Message, arg ...string) {
|
||||
|
@ -478,7 +478,7 @@ func init() {
|
||||
}
|
||||
}},
|
||||
INIT: {Name: "clone origin* branch name path", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(nfs.DEFS, kit.Path(".git/config"), nfs.Template(m, "config", m.Option(ORIGIN)))
|
||||
m.Cmd(nfs.DEFS, kit.Path(".git/config"), kit.Format(nfs.Template(m, "config"), m.Option(ORIGIN)))
|
||||
git.PlainInit(m.Option(nfs.PATH), false)
|
||||
_repos_insert(m, kit.Path(""))
|
||||
m.ProcessRefresh()
|
||||
|
@ -137,7 +137,7 @@ func init() {
|
||||
m.Cmdy(REPOS, INIT)
|
||||
}},
|
||||
CONFIGS: {Name: "configs email* username* token", Help: "配置", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(nfs.DEFS, kit.HomePath(".gitconfig"), nfs.Template(m, "gitconfig", m.Option(aaa.USERNAME), m.Option(aaa.EMAIL)))
|
||||
m.Cmd(nfs.DEFS, kit.HomePath(".gitconfig"), kit.Format(nfs.Template(m, "gitconfig"), m.Option(aaa.USERNAME), m.Option(aaa.EMAIL)))
|
||||
mdb.Config(m, aaa.USERNAME, m.Option(aaa.USERNAME))
|
||||
mdb.Config(m, aaa.EMAIL, m.Option(aaa.EMAIL))
|
||||
kit.If(m.Option(web.TOKEN), func() { m.Cmd(web.TOKEN, "set") })
|
||||
|
@ -200,8 +200,13 @@ func (m *Message) EchoQRCode(src string) *Message { return m.Echo(Render(m, R
|
||||
func (m *Message) EchoImages(src string) *Message { return m.Echo(Render(m, RENDER_IMAGES, src)) }
|
||||
func (m *Message) EchoVideos(src string) *Message { return m.Echo(Render(m, RENDER_VIDEOS, src)) }
|
||||
func (m *Message) EchoAudios(src string) *Message { return m.Echo(Render(m, RENDER_AUDIOS, src)) }
|
||||
func (m *Message) EchoIFrame(src string) *Message { return m.Echo(Render(m, RENDER_IFRAME, src)) }
|
||||
func (m *Message) EchoScript(arg ...string) *Message { return m.Echo(Render(m, RENDER_SCRIPT, arg)) }
|
||||
func (m *Message) EchoIFrame(src string) *Message {
|
||||
kit.If(src, func() { m.Echo(Render(m, RENDER_IFRAME, src)) })
|
||||
return m
|
||||
}
|
||||
func (m *Message) EchoScript(arg ...string) *Message {
|
||||
return m.Echo(Render(m, RENDER_SCRIPT, arg))
|
||||
}
|
||||
func (m *Message) EchoDownload(arg ...string) *Message {
|
||||
return m.Echo(Render(m, RENDER_DOWNLOAD, arg))
|
||||
}
|
||||
|
16
type.go
16
type.go
@ -99,11 +99,12 @@ func (c *Context) Register(s *Context, x Server, cmd ...string) *Context {
|
||||
return s
|
||||
}
|
||||
func (c *Context) MergeCommands(Commands Commands) *Context {
|
||||
for key, cmd := range Commands {
|
||||
// for key, cmd := range Commands {
|
||||
for _, cmd := range Commands {
|
||||
if cmd.Hand == nil && cmd.RawHand == nil {
|
||||
if cmd.RawHand = logs.FileLines(2); cmd.Actions != nil {
|
||||
if action, ok := cmd.Actions[SELECT]; ok {
|
||||
cmd.Name = kit.Select(strings.Replace(action.Name, SELECT, key, 1), cmd.Name)
|
||||
// cmd.Name = kit.Select(strings.Replace(action.Name, SELECT, key, 1), cmd.Name)
|
||||
cmd.Help = kit.Select(action.Help, cmd.Help)
|
||||
}
|
||||
}
|
||||
@ -163,7 +164,7 @@ func (c *Context) Merge(s *Context) *Context {
|
||||
}
|
||||
}
|
||||
}
|
||||
kit.If(sub == SELECT, func() { cmd.Name = kit.Select(action.Name, cmd.Name) })
|
||||
// kit.If(sub == SELECT, func() { cmd.Name = kit.Select(action.Name, cmd.Name) })
|
||||
if help := kit.Split(action.Help, " ::"); len(help) > 0 {
|
||||
if kit.Value(cmd.Meta, kit.Keys("_trans", strings.TrimPrefix(sub, "_")), help[0]); len(help) > 1 {
|
||||
kit.Value(cmd.Meta, kit.Keys("_title", sub), help[1])
|
||||
@ -176,7 +177,7 @@ func (c *Context) Merge(s *Context) *Context {
|
||||
kit.If(action.List == nil, func() { action.List = SplitCmd(action.Name, nil) })
|
||||
kit.If(len(action.List) > 0, func() { cmd.Meta[sub] = action.List })
|
||||
}
|
||||
kit.If(cmd.Name == "", func() { cmd.Name = "list list" })
|
||||
// kit.If(cmd.Name == "", func() { cmd.Name = "list list" })
|
||||
kit.If(strings.HasPrefix(cmd.Name, LIST), func() { cmd.Name = strings.Replace(cmd.Name, LIST, key, 1) })
|
||||
kit.If(cmd.List == nil, func() { cmd.List = SplitCmd(cmd.Name, cmd.Actions) })
|
||||
}
|
||||
@ -357,7 +358,12 @@ func (m *Message) Search(key string, cb Any) *Message {
|
||||
for _, p := range []*Context{p, m.target, m.source} {
|
||||
for s := p; s != nil; s = s.context {
|
||||
if cmd, ok := s.Commands[key]; ok {
|
||||
cb(s.context, s, key, cmd)
|
||||
func() {
|
||||
_target, _key := m.target, m._key
|
||||
m.target, m._key = s, key
|
||||
cb(s.context, s, key, cmd)
|
||||
m.target, m._key = _target, _key
|
||||
}()
|
||||
return m
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user