diff --git a/base/cli/forever.go b/base/cli/forever.go index db3152b0..0857abcd 100644 --- a/base/cli/forever.go +++ b/base/cli/forever.go @@ -2,7 +2,6 @@ package cli import ( "os" - "runtime" "strings" ice "shylinux.com/x/icebergs" @@ -25,10 +24,6 @@ func init() { Index.MergeCommands(ice.Commands{ FOREVER: {Name: "forever auto", Help: "启动", Actions: ice.Actions{ START: {Hand: func(m *ice.Message, arg ...string) { - if runtime.GOOS == WINDOWS { - m.Cmdy("serve", "start", arg) - return - } env := []string{PATH, BinPath(), HOME, kit.Select(kit.Path(""), os.Getenv(HOME))} for _, k := range ENV_LIST { if kit.Env(k) != "" { @@ -54,14 +49,9 @@ func init() { m.Cmdy(FOREVER, bin, ice.SERVE, START, arg) } }}, - RESTART: {Hand: func(m *ice.Message, arg ...string) { - if runtime.GOOS == WINDOWS { - return - } - m.Cmd(gdb.SIGNAL, gdb.RESTART) - }}, - STOP: {Hand: func(m *ice.Message, arg ...string) { m.Cmd(gdb.SIGNAL, gdb.STOP) }}, - DELAY: {Hand: func(m *ice.Message, arg ...string) { m.Sleep(arg[0]).Cmdy(arg[1:]) }}, + RESTART: {Hand: func(m *ice.Message, arg ...string) { m.Cmd(gdb.SIGNAL, gdb.RESTART) }}, + STOP: {Hand: func(m *ice.Message, arg ...string) { m.Cmd(gdb.SIGNAL, gdb.STOP) }}, + DELAY: {Hand: func(m *ice.Message, arg ...string) { m.Sleep(arg[0]).Cmdy(arg[1:]) }}, }, Hand: func(m *ice.Message, arg ...string) { if len(arg) == 0 { m.Cmdy(RUNTIME, BOOTINFO) @@ -69,12 +59,9 @@ 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) + defer 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")) diff --git a/base/cli/system.go b/base/cli/system.go index abaf987d..b5141fd2 100644 --- a/base/cli/system.go +++ b/base/cli/system.go @@ -3,6 +3,8 @@ package cli import ( "bytes" "io" + "net/http" + "os" "os/exec" "path" "runtime" @@ -58,7 +60,12 @@ func _system_cmd(m *ice.Message, arg ...string) *exec.Cmd { } } if bin == "" && runtime.GOOS == WINDOWS { - bin = path.Join("C:/Windows", arg[0]) + if bin = _system_find(m, arg[0], path.Join(os.Getenv("ProgramFiles"), "Git/bin"), path.Join(os.Getenv("ProgramFiles"), "Go/bin")); bin != "" { + m.Logs(mdb.SELECT, "systems cmd", bin) + } + } + if bin == "" { + bin = arg[0] } cmd := exec.Command(bin, arg[1:]...) if cmd.Dir = kit.TrimPath(m.Option(CMD_DIR)); len(cmd.Dir) > 0 { @@ -102,9 +109,14 @@ func _system_exec(m *ice.Message, cmd *exec.Cmd) { defer func() { m.Push(CMD_OUT, out.String()).Push(CMD_ERR, err.String()) m.Echo(strings.TrimRight(out.String(), ice.NL)) + if m.IsErr() { + m.Option(ice.MSG_ARGS, kit.Simple(http.StatusBadRequest, cmd.Args, err.String())) + m.Echo(strings.TrimRight(err.String(), ice.NL)) + m.Debug("what %v", m.FormatMeta()) + } }() } - if e := cmd.Run(); !m.Warn(e, ice.ErrNotFound, cmd.Args) { + if e := cmd.Run(); !m.Warn(e, ice.ErrNotValid, cmd.Args) { m.Cost(CODE, _system_code(cmd), ctx.ARGS, cmd.Args) } m.Push(mdb.TIME, m.Time()).Push(CODE, _system_code(cmd)) diff --git a/base/web/broad.go b/base/web/broad.go index 44097644..574b790d 100644 --- a/base/web/broad.go +++ b/base/web/broad.go @@ -27,12 +27,14 @@ func _broad_send(m *ice.Message, host, port string, remote_host, remote_port str s.Write([]byte(msg.FormatMeta())) } } -func _broad_serve(m *ice.Message, host, port string) { - m.Go(func() { - _broad_send(m.Sleep("100ms"), host, port, "255.255.255.255", "9020", mdb.TYPE, ice.Info.NodeType, mdb.NAME, ice.Info.NodeName) - }) - if s, e := net.ListenUDP("udp4", _broad_addr(m, host, port)); m.Assert(e) { +func _broad_serve(m *ice.Message, port string) { + if s, e := net.ListenUDP("udp4", _broad_addr(m, "0.0.0.0", port)); m.Assert(e) { defer s.Close() + m.Go(func() { + m.Sleep("10ms").Cmd(tcp.HOST, func(values ice.Maps) { + _broad_send(m, values[aaa.IP], port, "255.255.255.255", "9020", mdb.TYPE, ice.Info.NodeType, mdb.NAME, ice.Info.NodeName) + }) + }) buf := make([]byte, ice.MOD_BUFS) for { n, from, e := s.ReadFromUDP(buf[:]) @@ -91,9 +93,7 @@ func init() { } }}, SERVE: {Name: "serve port=9020", Hand: func(m *ice.Message, arg ...string) { - m.Cmd(tcp.HOST).TableGo(func(values ice.Maps) { - _broad_serve(m, values[aaa.IP], m.Option(tcp.PORT)) - }) + _broad_serve(m, m.Option(tcp.PORT)) }}, OPEN: {Hand: func(m *ice.Message, arg ...string) { ctx.ProcessOpen(m, kit.Format("http://%s:%s", m.Option(tcp.HOST), m.Option(tcp.PORT))) diff --git a/base/web/render.go b/base/web/render.go index fd4a6fcd..46663b92 100644 --- a/base/web/render.go +++ b/base/web/render.go @@ -45,7 +45,9 @@ func Render(m *ice.Message, cmd string, args ...ice.Any) bool { RenderCookie(m, arg[0], arg[1:]...) case STATUS, ice.RENDER_STATUS: // [code [text]] - RenderStatus(m.W, kit.Int(kit.Select("200", arg, 0)), kit.Select("", arg, 1)) + m.Debug("what %v", m.FormatStack(1, 10)) + m.Debug("what %v", arg) + RenderStatus(m.W, kit.Int(kit.Select("200", arg, 0)), strings.Join(kit.Slice(arg, 1), " ")) case ice.RENDER_REDIRECT: // url [arg...] http.Redirect(m.W, m.R, kit.MergeURL(arg[0], arg[1:]), http.StatusTemporaryRedirect) diff --git a/base/web/serve.go b/base/web/serve.go index 54b454b9..32ba4b1f 100644 --- a/base/web/serve.go +++ b/base/web/serve.go @@ -30,7 +30,7 @@ func _serve_start(m *ice.Message) { m.Cmd(SPIDE, ice.OPS, kit.Format("http://localhost:%s/exit", m.Option(tcp.PORT))).Sleep("100ms") } m.Target().Start(m, m.OptionSimple(tcp.HOST, tcp.PORT)...) - defer m.Go(func() { m.Cmd(BROAD, SERVE, m.OptionSimple(tcp.PORT)) }) + m.Sleep("300ms") for _, v := range kit.Split(m.Option(ice.DEV)) { m.Cmd(SPACE, tcp.DIAL, ice.DEV, v, mdb.NAME, ice.Info.NodeName) } @@ -187,11 +187,11 @@ func init() { _serve_start(m) }}, SERVE_START: {Hand: func(m *ice.Message, arg ...string) { + m.Go(func() { m.Cmd(BROAD, SERVE, m.OptionSimple(tcp.PORT)) }) go func() { - m.Option(ice.LOG_DISABLE, ice.TRUE) opened := false for i := 0; i < 3 && !opened; i++ { - m.Sleep("1s").Cmd(SPACE, func(values ice.Maps) { + m.Sleep("1s").Cmd(SPACE, kit.Dict(ice.LOG_DISABLE, ice.TRUE), func(values ice.Maps) { if values[mdb.TYPE] == CHROME { opened = true } @@ -202,7 +202,7 @@ func init() { } switch host := "http://localhost:" + m.Option(tcp.PORT); runtime.GOOS { case cli.WINDOWS: - m.Cmd(cli.SYSTEM, "explorer.exe", host) + m.Cmd(cli.SYSTEM, "explorer", host) case cli.DARWIN: m.Cmd(cli.SYSTEM, "open", host) } diff --git a/base/web/spide.go b/base/web/spide.go index b10f03f5..04e13079 100644 --- a/base/web/spide.go +++ b/base/web/spide.go @@ -28,7 +28,7 @@ func _spide_create(m *ice.Message, name, address string) { dir, file := path.Split(uri.EscapedPath()) value[SPIDE_CLIENT] = kit.Dict(mdb.NAME, name, SPIDE_METHOD, http.MethodPost, "url", address, "origin", uri.Scheme+"://"+uri.Host, tcp.PROTOCOL, uri.Scheme, tcp.HOSTNAME, uri.Hostname(), tcp.HOST, uri.Host, nfs.PATH, dir, nfs.FILE, file, "query", uri.RawQuery, - cli.TIMEOUT, "30s", LOGHEADERS, ice.FALSE, + cli.TIMEOUT, "300ms", LOGHEADERS, ice.FALSE, ) }) } diff --git a/core/code/compile.go b/core/code/compile.go index 3058a716..93df12e2 100644 --- a/core/code/compile.go +++ b/core/code/compile.go @@ -53,7 +53,12 @@ func init() { }, ctx.ConfAction(cli.ENV, kit.Dict("GOPRIVATE", "shylinux.com,github.com", "GOPROXY", "https://goproxy.cn,direct", "CGO_ENABLED", "0"))), Hand: func(m *ice.Message, arg ...string) { _autogen_version(m.Spawn()) main, file, goos, arch := _compile_target(m, arg...) - m.Optionv(cli.CMD_ENV, kit.Simple(cli.PATH, kit.Env(cli.PATH), cli.HOME, kit.Env(cli.HOME), m.Configv(cli.ENV), m.Optionv(cli.ENV), cli.GOOS, goos, cli.GOARCH, arch)) + env := kit.Simple(cli.PATH, kit.Env(cli.PATH), cli.HOME, kit.Select(kit.Path(""), kit.Env(cli.HOME)), m.Configv(cli.ENV), m.Optionv(cli.ENV), cli.GOOS, goos, cli.GOARCH, arch) + if runtime.GOOS == cli.WINDOWS { + env = append(env, "GOPATH", kit.HomePath("go")) + env = append(env, "GOCACHE", kit.HomePath("go/go-build")) + } + m.Optionv(cli.CMD_ENV, env) if !strings.Contains(m.Cmdx(nfs.CAT, ice.GO_MOD), "shylinux.com/x/ice") { m.Cmd(cli.SYSTEM, GO, "get", "shylinux.com/x/ice") } diff --git a/core/code/publish.go b/core/code/publish.go index 7de2a8b4..f6678f0a 100644 --- a/core/code/publish.go +++ b/core/code/publish.go @@ -87,13 +87,6 @@ func init() { Index.MergeCommands(ice.Commands{ PUBLISH: {Name: "publish path auto create volcanos icebergs intshell", Help: "发布", Actions: ice.MergeActions(ice.Actions{ ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { m.Config(ice.CONTEXTS, _contexts) }}, - mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(nfs.DIR, arg[1:]).Cut("path,size,time").ProcessAgain() }}, - web.SERVE_START: {Hand: func(m *ice.Message, arg ...string) { - if runtime.GOOS == cli.WINDOWS { - return - } - // _publish_file(m, ice.ICE_BIN) - }}, ice.VOLCANOS: {Help: "火山架", Hand: func(m *ice.Message, arg ...string) { defer func() { m.EchoQRCode(m.Option(ice.MSG_USERWEB)) }() defer func() { m.Cmdy(PUBLISH, ice.CONTEXTS, ice.MISC) }() @@ -108,6 +101,7 @@ func init() { _publish_list(m, kit.ExtReg(`(sh|vim|conf)`)) }}, ice.CONTEXTS: {Hand: func(m *ice.Message, arg ...string) { _publish_contexts(m, arg...) }}, + mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(nfs.DIR, arg[1:]).Cut("path,size,time").ProcessAgain() }}, mdb.CREATE: {Name: "create file", Help: "添加", Hand: func(m *ice.Message, arg ...string) { _publish_file(m, m.Option(nfs.FILE)) }}, nfs.TRASH: {Hand: func(m *ice.Message, arg ...string) { nfs.Trash(m, path.Join(ice.USR_PUBLISH, m.Option(nfs.PATH))) }}, }, ctx.ConfAction(ice.CONTEXTS, _contexts), aaa.RoleAction()), Hand: func(m *ice.Message, arg ...string) { diff --git a/init.go b/init.go index 2da457d7..27f246a5 100644 --- a/init.go +++ b/init.go @@ -95,9 +95,6 @@ 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] != "_" { @@ -120,9 +117,9 @@ func Run(arg ...string) string { os.Exit(kit.Int(Pulse.Option(EXIT))) } default: - if logs.Disable(true); len(arg) == 0 { - arg = append(arg, HELP) - } + // if logs.Disable(true); len(arg) == 0 { + // arg = append(arg, HELP) + // } if Pulse.Cmdy(INIT).Cmdy(arg); Pulse.IsErrNotFound() { Pulse.SetAppend().SetResult().Cmdy(SYSTEM, arg) }