diff --git a/base/cli/forever.go b/base/cli/forever.go index ef9c486a..0dfae6bf 100644 --- a/base/cli/forever.go +++ b/base/cli/forever.go @@ -13,7 +13,7 @@ import ( ) func BinPath(arg ...string) string { - return kit.Join(kit.Simple(arg, kit.Path(ice.BIN), 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(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) } const FOREVER = "forever" diff --git a/base/cli/runtime.go b/base/cli/runtime.go index a187b41b..abf786a1 100644 --- a/base/cli/runtime.go +++ b/base/cli/runtime.go @@ -149,7 +149,7 @@ const RUNTIME = "runtime" func init() { Index.MergeCommands(ice.Commands{ - RUNTIME: {Name: "runtime info=bootinfo,ifconfig,hostinfo,hostname,userinfo,procinfo,diskinfo,api,cli,cmd,env,chain auto upgrade", Help: "运行环境", Actions: ice.MergeActions(ice.Actions{ + RUNTIME: {Name: "runtime info=bootinfo,ifconfig,hostinfo,hostname,userinfo,procinfo,diskinfo,api,cli,cmd,env,path,chain auto upgrade", Help: "运行环境", Actions: ice.MergeActions(ice.Actions{ ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { _runtime_init(m) }}, ice.CTX_EXIT: {Hand: func(m *ice.Message, arg ...string) { m.Conf("", "", nil) }}, IFCONFIG: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy("tcp.host") }}, @@ -200,6 +200,11 @@ func init() { m.Echo(kit.MergePOD(os.Getenv(CTX_DEV), os.Getenv(CTX_POD))) } }}, + nfs.PATH: {Hand: func(m *ice.Message, arg ...string) { + for _, p := range strings.Split(os.Getenv(PATH), ice.DF) { + m.Push(nfs.PATH, p) + } + }}, "chain": {Hand: func(m *ice.Message, arg ...string) { m.Echo(m.FormatChain()) }}, "upgrade": {Hand: func(m *ice.Message, arg ...string) { file := kit.Keys("ice", runtime.GOOS, runtime.GOARCH) diff --git a/conf.go b/conf.go index b70a1c26..30f10209 100644 --- a/conf.go +++ b/conf.go @@ -35,7 +35,6 @@ const ( CAN = "can" POD = "pod" - CTX = "ctx" CMD = "cmd" ARG = "arg" @@ -289,17 +288,6 @@ const ( // ctx STYLE = "style" INDEX = "index" ) -const ( // web - SERVE = "serve" - SPACE = "space" - - THEME = "theme" - TITLE = "title" -) -const ( // nfs - SOURCE = "source" - SCRIPT = "script" -) const ( // mdb SEARCH = "search" SELECT = "select" @@ -316,9 +304,32 @@ const ( // mdb TEXT = "text" LINK = "link" ) -const ( // ice - MDB = "mdb" - GDB = "gdb" - AAA = "aaa" - CLI = "cli" +const ( // web + SERVE = "serve" + SPACE = "space" + + THEME = "theme" + TITLE = "title" +) +const ( // nfs + SOURCE = "source" + SCRIPT = "script" +) +const ( // cli + SYSTEM = "system" + START = "start" +) +const ( // ice + CTX = "ctx" + MDB = "mdb" + WEB = "web" + AAA = "aaa" + LEX = "lex" + YAC = "yac" + SSH = "ssh" + GDB = "gdb" + TCP = "tcp" + NFS = "nfs" + CLI = "cli" + LOG = "log" ) diff --git a/core/code/go.go b/core/code/go.go index c62b281d..33b31086 100644 --- a/core/code/go.go +++ b/core/code/go.go @@ -123,8 +123,13 @@ func init() { }, PlugAction())}, GO: {Name: "go path auto", Help: "后端编程", Actions: ice.MergeActions(ice.Actions{ ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { m.Cmd(NAVIGATE, mdb.CREATE, GODOC, m.PrefixKey()) }}, - mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { _go_show(m, arg...) }}, - mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { _go_exec(m, arg...) }}, + mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { + cmds, text := "ice.bin space dial dev ops", ctx.GetFileCmd(path.Join(arg[2], arg[1])) + _xterm_show(m, cmds, text) + }}, + mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { + _go_exec(m, arg...) + }}, COMPLETE: {Hand: func(m *ice.Message, arg ...string) { kit.If(len(arg) == 0 || arg[0] != mdb.FOREACH, func() { _go_complete(m, arg...) }) }}, diff --git a/core/code/js.go b/core/code/js.go index 959276ff..4ec600fb 100644 --- a/core/code/js.go +++ b/core/code/js.go @@ -99,8 +99,13 @@ const JSON = "json" func init() { Index.MergeCommands(ice.Commands{ JS: {Name: "js path auto", Help: "前端", Actions: ice.MergeActions(ice.Actions{ - mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { _js_exec(m, arg...) }}, - mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { _js_exec(m, arg...) }}, + mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { + cmds, text := "node", kit.Format(`require("./usr/volcanos/proto.js"), require("./usr/volcanos/publish/client/nodejs/proto.js"), Volcanos.meta._main("%s")`, path.Join(ice.PS, arg[2], arg[1])) + _xterm_show(m, cmds, text) + }}, + mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { + _js_exec(m, arg...) + }}, TEMPLATE: {Hand: func(m *ice.Message, arg ...string) { m.Echo(_js_template) }}, COMPLETE: {Hand: func(m *ice.Message, arg ...string) { diff --git a/core/code/py.go b/core/code/py.go index fa9d2527..3c6efa06 100644 --- a/core/code/py.go +++ b/core/code/py.go @@ -29,6 +29,10 @@ func init() { cli.IsAlpine(m, "python2") cli.IsAlpine(m, "python3") }}, + mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { + cmds, text := "python -i "+path.Join(arg[2], arg[1]), "" + _xterm_show(m, cmds, text) + }}, mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { _py_exec(m, arg...) }}, TEMPLATE: {Hand: func(m *ice.Message, arg ...string) { m.Echo(`print "hello world"`) }}, }, PlugAction())}, diff --git a/core/code/sh.go b/core/code/sh.go index 4e23b862..e6a768db 100644 --- a/core/code/sh.go +++ b/core/code/sh.go @@ -2,26 +2,17 @@ package code import ( "path" + "strings" ice "shylinux.com/x/icebergs" "shylinux.com/x/icebergs/base/cli" - "shylinux.com/x/icebergs/base/ctx" "shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/nfs" kit "shylinux.com/x/toolkits" ) -func _sh_exec(m *ice.Message, arg ...string) (res []string) { - if cmd := ctx.GetFileCmd(path.Join(arg[2], arg[1])); cmd != "" { - res = append(res, kit.Format(_sh_template, "http://localhost:9020", m.Option(ice.MSG_USERPOD), cmd)) - } - if _, e := nfs.DiskFile.StatFile(path.Join(arg[2], arg[1])); e == nil { - res = append(res, kit.Format("source %s", kit.Path(arg[2], arg[1]))) - } else if b, e := nfs.ReadFile(m, path.Join(arg[2], arg[1])); e == nil { - res = append(res, string(b)) - } - m.Cmdy(cli.SYSTEM, SH, "-c", kit.Join(res, ice.NL)).StatusTime() - return +func _sh_exec(m *ice.Message, arg ...string) { + m.Cmdy(cli.SYSTEM, SH, "-c", kit.Format(_sh_template, m.Option(ice.MSG_USERHOST), m.Option(ice.MSG_USERPOD), path.Join(arg[2], arg[1]))).StatusTime() } const SH = nfs.SH @@ -29,25 +20,22 @@ const SH = nfs.SH func init() { Index.MergeCommands(ice.Commands{ SH: {Name: "sh path auto", Help: "命令", Actions: ice.MergeActions(ice.Actions{ - mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { _c_show(m, arg...) }}, - mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { _sh_exec(m, arg...) }}, - NAVIGATE: {Hand: func(m *ice.Message, arg ...string) { _c_tags(m, MAN, "ctags", "-a", "-R", nfs.PWD) }}, + mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { + cmds, text := SH, kit.Format(_sh_template, m.Option(ice.MSG_USERHOST), m.Option(ice.MSG_USERPOD), path.Join(arg[2], arg[1])) + if strings.HasPrefix(text, "#!") { + cmds = strings.TrimSpace(strings.SplitN(text, ice.NL, 2)[0][2:]) + } + _xterm_show(m, cmds, text) + }}, + mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { + _sh_exec(m, arg...) + }}, + NAVIGATE: {Hand: func(m *ice.Message, arg ...string) { _c_tags(m, MAN, "ctags", "-a", "-R", nfs.PWD) }}, }, PlugAction())}, }) } -var _sh_template = `#! /bin/sh -export ctx_dev=%s; ctx_pod=%s ctx_temp=$(mktemp); curl -fsSL $ctx_dev -o $ctx_temp; source $ctx_temp &>/dev/null -_done="" -_list() { - if [ "$_done" = "" ]; then - ish_sys_dev_run %s "$@" - else - ish_sys_dev_run_command "$@" - fi - _done=done -} -_action() { - _list action "$@" -} +var _sh_template = `#!/bin/sh +export ctx_dev=%s ctx_pod=%s ctx_mod=%s +temp=$(mktemp); if curl -h &>/dev/null; then curl -o $temp -fsSL $ctx_dev; else wget -O $temp -q $ctx_dev; fi && source $temp $ctx_mod ` diff --git a/core/code/xterm.go b/core/code/xterm.go index 970f94a2..b545706f 100644 --- a/core/code/xterm.go +++ b/core/code/xterm.go @@ -118,3 +118,7 @@ func init() { }}, }) } + +func _xterm_show(m *ice.Message, cmds, text string) { + m.Cmdy(ctx.COMMAND, XTERM).Push(ctx.ARGS, kit.Format([]string{m.Cmdx(XTERM, mdb.CREATE, mdb.TYPE, cmds, mdb.TEXT, text)})).ProcessField(XTERM) +} diff --git a/init.go b/init.go index 872d589b..a038417b 100644 --- a/init.go +++ b/init.go @@ -92,6 +92,11 @@ func Run(arg ...string) string { if len(arg) == 0 && len(os.Args) > 1 { arg = kit.Simple(os.Args[1:], kit.Split(kit.Env(CTX_ARG))) } + if len(arg) == 0 && runtime.GOOS == "windows" { + arg = append(arg, SERVE, START, DEV, SHY) + logs.Disable(true) + os.Stderr.Close() + } 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] != "_" { @@ -101,11 +106,6 @@ func Run(arg ...string) string { if Pulse._cmd == nil { Pulse._cmd = &Command{RawHand: logs.FileLines(3)} } - if len(arg) == 0 && runtime.GOOS == "windows" { - arg = append(arg, SERVE, "start", "dev", "shy") - logs.Disable(true) - os.Stderr.Close() - } switch Index.Merge(Index).Begin(Pulse, arg...); kit.Select("", arg, 0) { case SERVE, SPACE: if Index.Start(Pulse, arg...) { @@ -116,7 +116,10 @@ func Run(arg ...string) string { if logs.Disable(true); len(arg) == 0 { arg = append(arg, HELP) } - if Pulse.Cmd(INIT).Cmdy(arg); strings.TrimSpace(Pulse.Result()) == "" { + if Pulse.Cmdy(INIT).Cmdy(arg); Pulse.IsErrNotFound() { + Pulse.SetAppend().SetResult().Cmdy(SYSTEM, arg) + } + if strings.TrimSpace(Pulse.Result()) == "" { Pulse.Table() } if !strings.HasSuffix(Pulse.Result(), NL) {