mirror of
https://shylinux.com/x/icebergs
synced 2025-04-26 01:24:05 +08:00
opt some
This commit is contained in:
parent
ef8367a7af
commit
8d3bb899b1
@ -59,12 +59,14 @@ func init() {
|
||||
|
||||
for {
|
||||
logs.Println("run %s", kit.Join(arg, ice.SP))
|
||||
if m.Sleep300ms(); IsSuccess(m.Cmd(SYSTEM, arg)) {
|
||||
msg := m.Cmd(SYSTEM, arg)
|
||||
if m.Sleep300ms(); IsSuccess(msg) {
|
||||
logs.Println()
|
||||
logs.Println(ice.EXIT) // 正常退出
|
||||
break
|
||||
} else {
|
||||
logs.Println()
|
||||
m.Sleep("10s")
|
||||
logs.Println("what %v", msg.FormatMeta())
|
||||
}
|
||||
}
|
||||
}},
|
||||
|
@ -39,6 +39,18 @@ func _system_cmd(m *ice.Message, arg ...string) *exec.Cmd {
|
||||
// bin = file // 当前目录
|
||||
// }
|
||||
// }
|
||||
if bin == "" {
|
||||
if file := _system_find(m, arg[0], ice.BIN, nfs.PWD); file != "" {
|
||||
m.Logs(mdb.SELECT, "mirrors cmd", file)
|
||||
bin = file // 当前目录
|
||||
}
|
||||
}
|
||||
if bin == "" && !strings.Contains(arg[0], ice.PS) {
|
||||
if file := _system_find(m, arg[0]); file != "" {
|
||||
m.Logs(mdb.SELECT, "systems cmd", file)
|
||||
bin = file // 系统命令
|
||||
}
|
||||
}
|
||||
if bin == "" && !strings.Contains(arg[0], ice.PS) {
|
||||
m.Cmd(MIRRORS, CMD, arg[0])
|
||||
if file := _system_find(m, arg[0]); file != "" {
|
||||
@ -46,6 +58,7 @@ func _system_cmd(m *ice.Message, arg ...string) *exec.Cmd {
|
||||
bin = file // 软件镜像
|
||||
}
|
||||
}
|
||||
|
||||
cmd := exec.Command(bin, arg[1:]...)
|
||||
|
||||
// 运行目录
|
||||
@ -155,6 +168,9 @@ func init() {
|
||||
m.Cmdy(nfs.CAT, ice.ETC_PATH)
|
||||
}},
|
||||
MAN: {Name: "man", Help: "文档", Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 1 {
|
||||
arg = append(arg, "")
|
||||
}
|
||||
m.Option(CMD_ENV, "COLUMNS", kit.Int(kit.Select("1920", m.Option("width")))/12)
|
||||
m.Cmdy(SYSTEM, "sh", "-c", kit.Format("man %s %s|col -b", kit.Select("", arg[1], arg[1] != "1"), arg[0]))
|
||||
if IsSuccess(m) && m.Append(CMD_ERR) == "" {
|
||||
|
@ -98,32 +98,14 @@ func init() {
|
||||
}
|
||||
}},
|
||||
"tags": {Name: "tags", Help: "索引", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Travel(func(p *ice.Context, s *ice.Context, key string, cmd *ice.Command) {
|
||||
if key[0] == '/' || key[0] == '_' {
|
||||
return // 内部命令
|
||||
}
|
||||
|
||||
var ls []string
|
||||
if cmd.RawHand != nil {
|
||||
switch h := cmd.RawHand.(type) {
|
||||
case string:
|
||||
ls = kit.Split(h, ":")
|
||||
default:
|
||||
ls = kit.Split(kit.FileLine(cmd.RawHand, 100), ":")
|
||||
}
|
||||
} else if cmd.Hand != nil {
|
||||
return
|
||||
ls = kit.Split(kit.FileLine(cmd.Hand, 100), ":")
|
||||
} else {
|
||||
return
|
||||
}
|
||||
TravelCmd(m, func(key, file, line string) {
|
||||
m.Push("name", key)
|
||||
m.Push("file", strings.TrimPrefix(ls[0], kit.Path("")+ice.PS))
|
||||
m.Push("line", ls[1])
|
||||
m.Push("file", file)
|
||||
m.Push("line", line)
|
||||
})
|
||||
m.Sort("name")
|
||||
m.Tables(func(value ice.Maps) {
|
||||
m.Echo("%s\t%s\t%s;\" m\n", value["name"], value["file"], value["line"])
|
||||
m.Echo("%s\t%s\t%s;\" f\n", value["name"], value["file"], value["line"])
|
||||
})
|
||||
m.Cmd("nfs.save", "tags", m.Result())
|
||||
}},
|
||||
@ -154,15 +136,15 @@ func CmdAction(args ...ice.Any) ice.Actions {
|
||||
m.Cmd(CONFIG, "reset", arg[0])
|
||||
case "help":
|
||||
if file := strings.ReplaceAll(GetCmdFile(m, arg[0]), ".go", ".shy"); nfs.ExistsFile(m, file) {
|
||||
m.ProcessStory("web.wiki.word", file)
|
||||
ProcessFloat(m, "web.wiki.word", file)
|
||||
}
|
||||
case "script":
|
||||
if file := strings.ReplaceAll(GetCmdFile(m, arg[0]), ".go", ".js"); nfs.ExistsFile(m, file) {
|
||||
m.ProcessStory("web.code.inner", file)
|
||||
ProcessFloat(m, "web.code.inner", file)
|
||||
}
|
||||
case "source":
|
||||
if file := GetCmdFile(m, arg[0]); nfs.ExistsFile(m, file) {
|
||||
m.ProcessStory("web.code.inner", file)
|
||||
ProcessFloat(m, "web.code.inner", file)
|
||||
}
|
||||
}
|
||||
return
|
||||
@ -173,6 +155,11 @@ func CmdAction(args ...ice.Any) ice.Actions {
|
||||
}},
|
||||
}
|
||||
}
|
||||
func ProcessFloat(m *ice.Message, arg ...string) {
|
||||
m.Option(ice.MSG_PROCESS, "_float")
|
||||
m.Option(ice.PROCESS_ARG, arg)
|
||||
m.Cmdy(COMMAND, arg[0])
|
||||
}
|
||||
func ProcessField(m *ice.Message, cmd string, args []string, arg ...string) {
|
||||
if len(arg) > 0 && arg[0] == ice.RUN {
|
||||
m.Cmdy(cmd, arg[1:])
|
||||
@ -266,3 +253,13 @@ func GetCmdFile(m *ice.Message, cmds string) (file string) {
|
||||
})
|
||||
return
|
||||
}
|
||||
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 // 内部命令
|
||||
}
|
||||
|
||||
ls := kit.Split(cmd.GetFileLine(), ":")
|
||||
cb(key, strings.TrimPrefix(ls[0], kit.Path("")+ice.PS), ls[1])
|
||||
})
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
@ -116,6 +117,26 @@ func init() {
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
list := map[string]bool{}
|
||||
ctx.TravelCmd(m, func(key, file, line string) {
|
||||
dir := path.Dir(file)
|
||||
if strings.HasPrefix(dir, ice.SRC) {
|
||||
return
|
||||
}
|
||||
if list[dir] {
|
||||
return
|
||||
}
|
||||
list[dir] = true
|
||||
|
||||
m.Cmd(nfs.DIR, dir, nfs.PATH, kit.Dict(nfs.DIR_ROOT, nfs.PWD, nfs.DIR_REG, ".*.(shy|js)")).Tables(func(value ice.Maps) {
|
||||
if list[value[nfs.PATH]] {
|
||||
return
|
||||
}
|
||||
list[value[nfs.PATH]] = true
|
||||
_binpack_file(m, w, value[nfs.PATH])
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -186,7 +186,9 @@ func init() {
|
||||
m.StatusTimeCount(mdb.INDEX, 0)
|
||||
}},
|
||||
nfs.TAGS: {Name: "tags", Help: "索引", Hand: func(m *ice.Message, arg ...string) {
|
||||
_inner_tags(m, m.Option(nfs.PATH), arg[0])
|
||||
if _inner_tags(m, m.Option(nfs.PATH), arg[0]); m.Length() == 0 {
|
||||
_inner_tags(m, "", arg[0])
|
||||
}
|
||||
}},
|
||||
cli.MAKE: {Name: "make", Help: "构建", Hand: func(m *ice.Message, arg ...string) {
|
||||
_inner_make(m, m.Cmd(cli.SYSTEM, cli.MAKE, arg))
|
||||
|
9
init.go
9
init.go
@ -70,6 +70,15 @@ var Index = &Context{Name: ICE, Help: "冰山模块", Configs: Configs{
|
||||
QUIT: {Name: "quit", Help: "结束", Hand: func(m *Message, arg ...string) {
|
||||
os.Exit(0)
|
||||
}},
|
||||
"some": {Name: "quit", Help: "结束", Hand: func(m *Message, arg ...string) {
|
||||
m.OptionFields("detail")
|
||||
m.Push("modpath", kit.ModPath(m.root.Travel))
|
||||
m.Push("modname", kit.ModName(m.root.Travel))
|
||||
m.Push("pathname", kit.PathName(m.root.Travel))
|
||||
m.Push("filename", kit.FileName(m.root.Travel))
|
||||
m.Push("funcname", kit.FuncName(m.root.Travel))
|
||||
m.Push("fileline", kit.FileLine(m.root.Travel, 100))
|
||||
}},
|
||||
EXIT: {Name: "exit", Help: "退出", Hand: func(m *Message, arg ...string) {
|
||||
defer m.Target().Close(m.root.Spawn(), arg...)
|
||||
m.root.Option(EXIT, kit.Select("0", arg, 0))
|
||||
|
8
misc.go
8
misc.go
@ -260,9 +260,7 @@ func (c *Context) _command(m *Message, cmd *Command, key string, arg ...string)
|
||||
}
|
||||
}
|
||||
|
||||
m._target = kit.FileLine(cmd.Hand, 3)
|
||||
if cmd.RawHand != nil {
|
||||
// m._target = kit.FileLine(cmd.RawHand, 3)
|
||||
if m._target = kit.FileLine(cmd.Hand, 3); cmd.RawHand != nil {
|
||||
m._target = kit.Format(cmd.RawHand)
|
||||
}
|
||||
if key == "select" {
|
||||
@ -307,9 +305,7 @@ func (c *Context) _action(m *Message, cmd *Command, key string, sub string, h *A
|
||||
}
|
||||
}
|
||||
|
||||
m._target = kit.FileLine(h.Hand, 3)
|
||||
if cmd.RawHand != nil {
|
||||
// m._target = kit.FileLine(cmd.RawHand, 3)
|
||||
if m._target = kit.FileLine(h.Hand, 3); cmd.RawHand != nil {
|
||||
m._target = kit.Format(cmd.RawHand)
|
||||
}
|
||||
m.Log(LOG_CMDS, "%s.%s %s %d %v", c.Name, key, sub, len(arg), arg,
|
||||
|
@ -111,7 +111,8 @@ func _status_each(m *ice.Message, title string, cmds ...string) {
|
||||
m.ProcessHold()
|
||||
}
|
||||
func _status_stat(m *ice.Message, files, adds, dels int) (int, int, int) {
|
||||
for _, v := range kit.Split(_git_cmds(m, DIFF, "--shortstat"), ice.FS) {
|
||||
res := _git_cmds(m, DIFF, "--shortstat")
|
||||
for _, v := range kit.Split(res, ice.FS, ice.FS) {
|
||||
n := kit.Int(kit.Split(strings.TrimSpace(v))[0])
|
||||
switch {
|
||||
case strings.Contains(v, "file"):
|
||||
|
@ -127,10 +127,6 @@ func (m *Message) ProcessDisplay(arg ...Any) {
|
||||
m.Option(MSG_DISPLAY, arg...)
|
||||
}
|
||||
|
||||
func (m *Message) ProcessStory(arg ...Any) {
|
||||
m.Option(MSG_PROCESS, "_story")
|
||||
m.Option(PROCESS_ARG, arg...)
|
||||
}
|
||||
func (m *Message) ProcessField(arg ...Any) {
|
||||
m.Process(PROCESS_FIELD)
|
||||
m.Option(FIELD_PREFIX, arg...)
|
||||
|
Loading…
x
Reference in New Issue
Block a user