From 4cfa425690279abd0f7d4eaf298801132eeb181f Mon Sep 17 00:00:00 2001 From: shylinux Date: Tue, 28 Feb 2023 14:08:09 +0800 Subject: [PATCH] opt some --- base/cli/forever.go | 10 +++++++++- base/cli/runtime.go | 2 +- base/cli/system.go | 21 +++++++++++++++++++-- base/ssh/script.go | 2 +- init.go | 7 +++++-- 5 files changed, 35 insertions(+), 7 deletions(-) diff --git a/base/cli/forever.go b/base/cli/forever.go index b10b2777..587d858b 100644 --- a/base/cli/forever.go +++ b/base/cli/forever.go @@ -2,6 +2,7 @@ package cli import ( "os" + "strings" ice "shylinux.com/x/icebergs" "shylinux.com/x/icebergs/base/gdb" @@ -10,8 +11,11 @@ import ( "shylinux.com/x/toolkits/logs" ) +func _path_sep() string { + return kit.Select(":", ";", strings.Contains(os.Getenv(PATH), ";")) +} func BinPath(arg ...string) string { - return kit.Join(kit.Simple(arg, kit.Path(ice.BIN), kit.Path(ice.USR_PUBLISH), kit.Path(ice.USR_LOCAL_BIN), kit.Path(ice.USR_LOCAL_GO_BIN), kit.Env(PATH)), ice.DF) + return kit.Join(kit.Simple(arg, kit.Path(""), kit.Path(ice.BIN), kit.Path(ice.USR_PUBLISH), kit.Path(ice.USR_LOCAL_BIN), kit.Path(ice.USR_LOCAL_GO_BIN), kit.Env(PATH)), _path_sep()) } const FOREVER = "forever" @@ -55,9 +59,13 @@ func init() { } for { if logs.Println("run %s", kit.Join(arg, ice.SP)); IsSuccess(m.Cmd(SYSTEM, arg)) { + logs.Println("what %v", 123) logs.Println(ice.EXIT) break } + logs.Println("what %v", 123) + m.Debug("what %v", arg) + m.Sleep("1s") if logs.Println(); m.Config("log.save") == ice.TRUE { back := kit.Format("var/log.%s", logs.Now().Format("20060102_150405")) m.Cmd(SYSTEM, "cp", "-r", "var/log", back, ice.Maps{CMD_OUTPUT: ""}) diff --git a/base/cli/runtime.go b/base/cli/runtime.go index f1e949e2..0ab944d8 100644 --- a/base/cli/runtime.go +++ b/base/cli/runtime.go @@ -202,7 +202,7 @@ func init() { } }}, nfs.PATH: {Hand: func(m *ice.Message, arg ...string) { - for _, p := range strings.Split(os.Getenv(PATH), ice.DF) { + for _, p := range _path_split(os.Getenv(PATH)) { m.Push(nfs.PATH, p) } }}, diff --git a/base/cli/system.go b/base/cli/system.go index f3127dc8..52b116bf 100644 --- a/base/cli/system.go +++ b/base/cli/system.go @@ -14,41 +14,52 @@ import ( "shylinux.com/x/icebergs/base/nfs" kit "shylinux.com/x/toolkits" "shylinux.com/x/toolkits/file" + "shylinux.com/x/toolkits/logs" ) +func _path_split(ps string) []string { + ps = strings.ReplaceAll(ps, "\\", "/") + return kit.Split(ps, "\n"+kit.Select(":", ";", strings.Contains(ps, ";")), "\n") +} 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 bin = _system_find(m, arg[0], strings.Split(env[i+1], ice.DF)...); bin != "" { + logs.Println("what") + if bin = _system_find(m, arg[0], _path_split(env[i+1])...); bin != "" { m.Logs(mdb.SELECT, "envpath cmd", bin) } } } if bin == "" { if text := kit.ReadFile(ice.ETC_PATH); len(text) > 0 { + logs.Println("what") if bin = _system_find(m, arg[0], strings.Split(text, ice.NL)...); bin != "" { m.Logs(mdb.SELECT, "etcpath cmd", bin) } } } if bin == "" { + logs.Println("what") if bin = _system_find(m, arg[0], ice.BIN, m.Option(CMD_DIR)); bin != "" { m.Logs(mdb.SELECT, "contexts cmd", bin) } } if bin == "" { + logs.Println("what") 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) { + logs.Println("what %s", arg[0]) 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]) + logs.Println("what") if bin = _system_find(m, arg[0]); bin != "" { m.Logs(mdb.SELECT, "mirrors cmd", bin) } @@ -56,6 +67,7 @@ func _system_cmd(m *ice.Message, arg ...string) *exec.Cmd { if bin == "" && runtime.GOOS == WINDOWS { bin = path.Join("C:/Windows", arg[0]) } + logs.Println("what %s %s", bin, arg) cmd := exec.Command(bin, arg[1:]...) if cmd.Dir = kit.TrimPath(m.Option(CMD_DIR)); len(cmd.Dir) > 0 { if m.Logs(mdb.PARAMS, CMD_DIR, cmd.Dir); !nfs.ExistsFile(m, cmd.Dir) { @@ -119,12 +131,17 @@ func _system_find(m Message, bin string, dir ...string) string { return bin } if len(dir) == 0 { - dir = append(dir, strings.Split(kit.Env(PATH), ice.DF)...) + dir = append(dir, _path_split(kit.Env(PATH))...) } + logs.Println("what %s", dir) for _, p := range dir { + logs.Println("what %s", path.Join(p, bin)) if nfs.ExistsFile(m, path.Join(p, bin)) { return kit.Path(p, bin) } + if nfs.ExistsFile(m, path.Join(p, bin)+".exe") { + return kit.Path(p, bin) + ".exe" + } } return "" } diff --git a/base/ssh/script.go b/base/ssh/script.go index b9add60f..22f5649d 100644 --- a/base/ssh/script.go +++ b/base/ssh/script.go @@ -117,7 +117,7 @@ func (f *Frame) parse(m *ice.Message, h, line string) string { func (f *Frame) scan(m *ice.Message, h, line string) *Frame { f.ps1 = kit.Simple(m.Confv(PROMPT, kit.Keym(PS1))) f.ps2 = kit.Simple(m.Confv(PROMPT, kit.Keym(PS2))) - m.Options(MESSAGE, m, ice.LOG_DISABLE, ice.TRUE) + // m.Options(MESSAGE, m, ice.LOG_DISABLE, ice.TRUE) m.I, m.O = f.stdin, f.stdout ps, bio := f.ps1, bufio.NewScanner(f.stdin) for f.prompt(m, ps...); f.stdin != nil && bio.Scan(); f.prompt(m, ps...) { diff --git a/init.go b/init.go index 1da0df8f..116b4dff 100644 --- a/init.go +++ b/init.go @@ -95,6 +95,9 @@ func Run(arg ...string) string { if len(arg) == 0 && runtime.GOOS == "windows" { arg = append(arg, SERVE, START, DEV, DEV) } + if len(arg) > 0 && arg[0] == "forever" && runtime.GOOS == "windows" { + arg[0] = "serve" + } Pulse.meta[MSG_DETAIL] = arg kit.Fetch(kit.Sort(os.Environ()), func(env string) { if ls := strings.SplitN(env, EQ, 2); strings.ToLower(ls[0]) == ls[0] && ls[0] != "_" { @@ -107,8 +110,8 @@ func Run(arg ...string) string { switch Index.Merge(Index).Begin(Pulse, arg...); kit.Select("", arg, 0) { case SERVE, SPACE: if os.Getenv("ctx_log") == "" { - logs.Disable(true) - os.Stderr.Close() + // logs.Disable(true) + // os.Stderr.Close() } if Index.Start(Pulse, arg...) { conf.Wait()