1
0
mirror of https://shylinux.com/x/icebergs synced 2025-04-26 01:24:05 +08:00
This commit is contained in:
harveyshao 2022-11-23 00:13:00 +08:00
parent f8a408131d
commit bd503579ad
10 changed files with 53 additions and 55 deletions

View File

@ -32,5 +32,5 @@ func init() {
m.Action(mdb.CREATE)
}
}},
})
})
}

View File

@ -6,4 +6,4 @@ const CLI = "cli"
var Index = &ice.Context{Name: CLI, Help: "命令模块"}
func init() { ice.Index.Register(Index, nil, MIRRORS, RUNTIME, QRCODE, SYSTEM, DAEMON, FOREVER) }
func init() { ice.Index.Register(Index, nil, RUNTIME, SYSTEM, DAEMON, FOREVER, MIRRORS, QRCODE) }

View File

@ -26,12 +26,10 @@ func _runtime_init(m *ice.Message) {
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, "")
for _, k := range ENV_LIST {
switch m.Conf(RUNTIME, kit.Keys(CONF, k), kit.Env(k)); k {
case CTX_PID:
ice.Info.PidPath = kit.Select("var/run/ice.pid", kit.Env(k))
ice.Info.PidPath = kit.Select(path.Join(ice.VAR_RUN, "ice.pid"), kit.Env(k))
case CTX_SHARE:
ice.Info.CtxShare = kit.Env(k)
case CTX_RIVER:
@ -53,6 +51,7 @@ func _runtime_init(m *ice.Message) {
aaa.UserRoot(ice.Pulse, ice.Info.UserName)
bin := _system_find(m, os.Args[0])
m.Conf(RUNTIME, kit.Keys(BOOT, ice.BIN), bin)
m.Conf(RUNTIME, kit.Keys(BOOT, mdb.TIME), m.Time())
if s, e := nfs.StatFile(m, bin); e == nil {
m.Conf(RUNTIME, kit.Keys(BOOT, nfs.SIZE), kit.FmtSize(s.Size()))
if f, e := nfs.OpenFile(m, bin); e == nil {
@ -60,6 +59,8 @@ func _runtime_init(m *ice.Message) {
m.Conf(RUNTIME, kit.Keys(BOOT, mdb.HASH), kit.Hashs(f))
}
}
m.Conf(RUNTIME, mdb.META, "")
m.Conf(RUNTIME, mdb.HASH, "")
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) {

View File

@ -19,37 +19,32 @@ func _system_cmd(m *ice.Message, arg ...string) *exec.Cmd {
bin, env := "", kit.Simple(m.Optionv(CMD_ENV))
for i := 0; i < len(env)-1; i += 2 {
if env[i] == PATH {
if file := _system_find(m, arg[0], strings.Split(env[i+1], ice.DF)...); file != "" {
m.Logs(mdb.SELECT, "env path cmd", file)
bin = file
if bin = _system_find(m, arg[0], strings.Split(env[i+1], ice.DF)...); bin != "" {
m.Logs(mdb.SELECT, "env path cmd", bin)
}
}
}
if bin == "" {
if text := kit.ReadFile(ice.ETC_PATH); len(text) > 0 {
if file := _system_find(m, arg[0], strings.Split(text, ice.NL)...); file != "" {
m.Logs(mdb.SELECT, "etc path cmd", file)
bin = file
if bin = _system_find(m, arg[0], strings.Split(text, ice.NL)...); bin != "" {
m.Logs(mdb.SELECT, "etc path cmd", bin)
}
}
}
if bin == "" {
if file := _system_find(m, arg[0], ice.BIN, nfs.PWD); file != "" {
m.Logs(mdb.SELECT, "contexts cmd", file)
bin = file
if bin = _system_find(m, arg[0], ice.BIN, nfs.PWD); bin != "" {
m.Logs(mdb.SELECT, "contexts cmd", bin)
}
}
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 = _system_find(m, arg[0]); bin != "" {
m.Logs(mdb.SELECT, "systems cmd", bin)
}
}
if bin == "" && !strings.Contains(arg[0], ice.PS) {
m.Cmd(MIRRORS, CMD, arg[0])
if file := _system_find(m, arg[0]); file != "" {
m.Logs(mdb.SELECT, "mirrors cmd", file)
bin = file
if bin = _system_find(m, arg[0]); bin != "" {
m.Logs(mdb.SELECT, "mirrors cmd", bin)
}
}
cmd := exec.Command(bin, arg[1:]...)
@ -92,11 +87,7 @@ func _system_exec(m *ice.Message, cmd *exec.Cmd) {
err := bytes.NewBuffer(make([]byte, 0, ice.MOD_BUFS))
cmd.Stdout, cmd.Stderr = out, err
defer func() {
m.Push(CMD_OUT, out.String())
m.Push(CMD_ERR, err.String())
if IsSuccess(m) && err.String() == "" {
m.SetAppend()
}
m.Push(CMD_OUT, out.String()).Push(CMD_ERR, err.String())
m.Echo(strings.TrimRight(out.String(), ice.NL))
}()
}

View File

@ -36,9 +36,7 @@ func _command_list(m *ice.Message, name string) {
if k[0] == '/' || k[0] == '_' {
continue
}
m.Push(mdb.KEY, k)
m.Push(mdb.NAME, v.Name)
m.Push(mdb.HELP, v.Help)
m.Push(mdb.KEY, k).Push(mdb.NAME, v.Name).Push(mdb.HELP, v.Help)
}
m.Sort(mdb.KEY)
return
@ -95,17 +93,12 @@ func init() {
_command_search(m, arg[0], kit.Select("", arg, 1), kit.Select("", arg, 2))
}
}},
"tags": {Hand: func(m *ice.Message, arg ...string) {
mdb.EXPORT: {Hand: func(m *ice.Message, arg ...string) {
TravelCmd(m, func(key, file, line string) {
m.Push("name", key)
m.Push("file", file)
m.Push("line", line)
})
m.Sort("name")
m.Tables(func(value ice.Maps) {
m.Echo("%s\t%s\t%s;\" f\n", value["name"], value["file"], value["line"])
})
m.Cmd("nfs.save", "tags", m.Result())
m.Push(mdb.NAME, key).Push(nfs.FILE, file).Push(nfs.LINE, line)
}).Sort(mdb.NAME).Tables(func(value ice.Maps) {
m.Echo(`%s %s %s;" f`+ice.NL, value[mdb.NAME], value[nfs.FILE], value[nfs.LINE])
}).Cmd(nfs.SAVE, "tags", m.Result())
}},
}, aaa.RoleAction()), Hand: func(m *ice.Message, arg ...string) {
if len(arg) == 0 {
@ -130,7 +123,7 @@ func init() {
m.Cmd(CONFIG, mdb.REMOVE, cmd)
return true
case mdb.SELECT:
m.Cmdy(CONFIG, cmd)
ProcessFloat(m, CONFIG, cmd)
return true
default:
return false
@ -178,7 +171,7 @@ func FileURI(dir string) string {
return ""
}
if strings.Contains(dir, "/go/pkg/mod/") {
return path.Join("/require", strings.Split(dir, "/go/pkg/mod/")[1])
return path.Join(ice.PS, ice.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)
@ -187,13 +180,13 @@ func FileURI(dir string) string {
dir = strings.TrimPrefix(dir, kit.Path("")+ice.PS)
}
if strings.HasPrefix(dir, ice.USR) {
return path.Join("/require", dir)
return path.Join(ice.PS, ice.REQUIRE, dir)
}
if strings.HasPrefix(dir, ice.SRC) {
return path.Join("/require", dir)
return path.Join(ice.PS, ice.REQUIRE, dir)
}
if nfs.ExistsFile(ice.Pulse, path.Join(ice.SRC, dir)) {
return path.Join("/require/src/", dir)
return path.Join(ice.PS, ice.REQUIRE, ice.SRC, dir)
}
return dir
}
@ -205,17 +198,17 @@ func AddFileCmd(dir, key string) {
}
func GetFileCmd(dir string) string {
if strings.HasPrefix(dir, ice.ISH_PLUGED) {
dir = path.Join("/require", strings.TrimPrefix(dir, ice.ISH_PLUGED))
dir = path.Join(ice.PS, ice.REQUIRE, strings.TrimPrefix(dir, ice.ISH_PLUGED))
}
if strings.HasPrefix(dir, "require/") {
if strings.HasPrefix(dir, ice.REQUIRE+ice.PS) {
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(ice.PS, ice.REQUIRE, ice.Info.Make.Module, dir), path.Join(ice.PS, ice.REQUIRE, ice.Info.Make.Module, ice.SRC, dir)} {
if cmd, ok := ice.Info.File[FileCmd(dir)]; ok {
return cmd
}
p := path.Dir(dir)
if cmd, ok := ice.Info.File[FileCmd(path.Join(p, path.Base(p)+".go"))]; ok {
if cmd, ok := ice.Info.File[FileCmd(path.Join(p, path.Base(p)+ice.PT+nfs.GO))]; ok {
return cmd
}
}
@ -225,6 +218,7 @@ 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), ice.DF)[0]
file = strings.TrimPrefix(file, kit.Path("")+ice.PS)
} else {
for k, v := range ice.Info.File {
if v == cmds {
@ -236,16 +230,16 @@ func GetCmdFile(m *ice.Message, cmds string) (file string) {
})
return
}
func TravelCmd(m *ice.Message, cb func(key, file, line string)) {
func TravelCmd(m *ice.Message, cb func(key, file, line string)) *ice.Message {
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(), ice.DF)
if len(ls) > 1 {
if ls := kit.Split(cmd.GetFileLine(), ice.DF); 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 found", cmd.Name, cmd.GetFileLine())
}
})
return m
}

View File

@ -48,7 +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 {
m.Option(ice.MSG_DISPLAY, kit.MergeURL(kit.ExtChange(file, nfs.JS), arg...))
m.Option(ice.MSG_DISPLAY, kit.MergeURL(kit.Select(kit.ExtChange(file, nfs.JS), file, strings.Contains(file, "?")), arg...))
return m
}
func Toolkit(m *ice.Message, arg ...string) {

View File

@ -136,7 +136,7 @@ func _autogen_git(m *ice.Message, arg ...string) ice.Map {
"Remote", strings.TrimSpace(m.Cmdx(cli.SYSTEM, GIT, "config", "remote.origin.url")),
"Branch", strings.TrimSpace(m.Cmdx(cli.SYSTEM, GIT, "rev-parse", "--abbrev-ref", "HEAD")),
"Version", strings.TrimSpace(m.Cmdx(cli.SYSTEM, GIT, "describe", "--tags")),
"Domain", m.Option(ice.MSG_USERWEB),
"Domain", kit.Split(m.Option(ice.MSG_USERWEB), "?")[0],
)
}
func _autogen_mod(m *ice.Message, file string) (mod string) {

View File

@ -162,14 +162,25 @@ func init() {
}},
})
ctx.AddRunChecker(func(m *ice.Message, cmd, check string, arg ...string) bool {
process := func(m *ice.Message, file string) {
ls, n := kit.Split(file, ice.PS), kit.Int(kit.Select("2", "1", strings.HasPrefix(file, ice.SRC+ice.PS)))
ctx.ProcessFloat(m, web.CODE_INNER, kit.Join(kit.Slice(ls, 0, n), ice.PS)+ice.PS, kit.Join(kit.Slice(ls, n), ice.PS))
}
switch check {
case nfs.SCRIPT:
if file := kit.ExtChange(ctx.GetCmdFile(m, cmd), nfs.JS); nfs.ExistsFile(m, file) {
ctx.ProcessFloat(m, web.CODE_INNER, file)
process(m, file)
return true
} else if strings.HasPrefix(file, path.Join(ice.USR_ICEBERGS, ice.CORE)) {
if file := strings.Replace(file, path.Join(ice.USR_ICEBERGS, ice.CORE), path.Join(ice.USR_VOLCANOS, "plugin/local"), 1); nfs.ExistsFile(m, file) {
process(m, file)
return true
}
}
case nfs.SOURCE:
if file := ctx.GetCmdFile(m, cmd); nfs.ExistsFile(m, file) {
ctx.ProcessFloat(m, web.CODE_INNER, file)
process(m, file)
return true
}
}
return false

1
core/team/plan.shy Normal file
View File

@ -0,0 +1 @@
chapter "plan"

View File

@ -334,7 +334,7 @@ func init() {
}
m.Push(mdb.TEXT, strings.Join(text, ", "))
}},
}, gdb.EventAction(web.DREAM_TABLES), aaa.RoleAction()), Hand: func(m *ice.Message, arg ...string) {
}, gdb.EventAction(web.DREAM_TABLES), ctx.CmdAction(), aaa.RoleAction()), Hand: func(m *ice.Message, arg ...string) {
if _configs_get(m, "user.email") == "" {
m.Echo("please config user.email")
m.Action(CONFIGS)