forked from x/icebergs
opt some
This commit is contained in:
parent
bd25fad239
commit
51f24bbc48
@ -2,7 +2,6 @@ package cli
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
ice "shylinux.com/x/icebergs"
|
ice "shylinux.com/x/icebergs"
|
||||||
@ -25,10 +24,6 @@ func init() {
|
|||||||
Index.MergeCommands(ice.Commands{
|
Index.MergeCommands(ice.Commands{
|
||||||
FOREVER: {Name: "forever auto", Help: "启动", Actions: ice.Actions{
|
FOREVER: {Name: "forever auto", Help: "启动", Actions: ice.Actions{
|
||||||
START: {Hand: func(m *ice.Message, arg ...string) {
|
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))}
|
env := []string{PATH, BinPath(), HOME, kit.Select(kit.Path(""), os.Getenv(HOME))}
|
||||||
for _, k := range ENV_LIST {
|
for _, k := range ENV_LIST {
|
||||||
if kit.Env(k) != "" {
|
if kit.Env(k) != "" {
|
||||||
@ -54,14 +49,9 @@ func init() {
|
|||||||
m.Cmdy(FOREVER, bin, ice.SERVE, START, arg)
|
m.Cmdy(FOREVER, bin, ice.SERVE, START, arg)
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
RESTART: {Hand: func(m *ice.Message, arg ...string) {
|
RESTART: {Hand: func(m *ice.Message, arg ...string) { m.Cmd(gdb.SIGNAL, gdb.RESTART) }},
|
||||||
if runtime.GOOS == WINDOWS {
|
STOP: {Hand: func(m *ice.Message, arg ...string) { m.Cmd(gdb.SIGNAL, gdb.STOP) }},
|
||||||
return
|
DELAY: {Hand: func(m *ice.Message, arg ...string) { m.Sleep(arg[0]).Cmdy(arg[1:]) }},
|
||||||
}
|
|
||||||
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) {
|
}, Hand: func(m *ice.Message, arg ...string) {
|
||||||
if len(arg) == 0 {
|
if len(arg) == 0 {
|
||||||
m.Cmdy(RUNTIME, BOOTINFO)
|
m.Cmdy(RUNTIME, BOOTINFO)
|
||||||
@ -69,12 +59,9 @@ func init() {
|
|||||||
}
|
}
|
||||||
for {
|
for {
|
||||||
if logs.Println("run %s", kit.Join(arg, ice.SP)); IsSuccess(m.Cmd(SYSTEM, arg)) {
|
if logs.Println("run %s", kit.Join(arg, ice.SP)); IsSuccess(m.Cmd(SYSTEM, arg)) {
|
||||||
logs.Println("what %v", 123)
|
defer logs.Println(ice.EXIT)
|
||||||
logs.Println(ice.EXIT)
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
logs.Println("what %v", 123)
|
|
||||||
m.Debug("what %v", arg)
|
|
||||||
m.Sleep("1s")
|
m.Sleep("1s")
|
||||||
if logs.Println(); m.Config("log.save") == ice.TRUE {
|
if logs.Println(); m.Config("log.save") == ice.TRUE {
|
||||||
back := kit.Format("var/log.%s", logs.Now().Format("20060102_150405"))
|
back := kit.Format("var/log.%s", logs.Now().Format("20060102_150405"))
|
||||||
|
@ -3,6 +3,8 @@ package cli
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io"
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
"runtime"
|
"runtime"
|
||||||
@ -58,7 +60,12 @@ func _system_cmd(m *ice.Message, arg ...string) *exec.Cmd {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if bin == "" && runtime.GOOS == WINDOWS {
|
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:]...)
|
cmd := exec.Command(bin, arg[1:]...)
|
||||||
if cmd.Dir = kit.TrimPath(m.Option(CMD_DIR)); len(cmd.Dir) > 0 {
|
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() {
|
defer func() {
|
||||||
m.Push(CMD_OUT, out.String()).Push(CMD_ERR, err.String())
|
m.Push(CMD_OUT, out.String()).Push(CMD_ERR, err.String())
|
||||||
m.Echo(strings.TrimRight(out.String(), ice.NL))
|
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.Cost(CODE, _system_code(cmd), ctx.ARGS, cmd.Args)
|
||||||
}
|
}
|
||||||
m.Push(mdb.TIME, m.Time()).Push(CODE, _system_code(cmd))
|
m.Push(mdb.TIME, m.Time()).Push(CODE, _system_code(cmd))
|
||||||
|
@ -27,12 +27,14 @@ func _broad_send(m *ice.Message, host, port string, remote_host, remote_port str
|
|||||||
s.Write([]byte(msg.FormatMeta()))
|
s.Write([]byte(msg.FormatMeta()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func _broad_serve(m *ice.Message, host, port string) {
|
func _broad_serve(m *ice.Message, port string) {
|
||||||
m.Go(func() {
|
if s, e := net.ListenUDP("udp4", _broad_addr(m, "0.0.0.0", port)); m.Assert(e) {
|
||||||
_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) {
|
|
||||||
defer s.Close()
|
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)
|
buf := make([]byte, ice.MOD_BUFS)
|
||||||
for {
|
for {
|
||||||
n, from, e := s.ReadFromUDP(buf[:])
|
n, from, e := s.ReadFromUDP(buf[:])
|
||||||
@ -91,9 +93,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
SERVE: {Name: "serve port=9020", Hand: func(m *ice.Message, arg ...string) {
|
SERVE: {Name: "serve port=9020", Hand: func(m *ice.Message, arg ...string) {
|
||||||
m.Cmd(tcp.HOST).TableGo(func(values ice.Maps) {
|
_broad_serve(m, m.Option(tcp.PORT))
|
||||||
_broad_serve(m, values[aaa.IP], m.Option(tcp.PORT))
|
|
||||||
})
|
|
||||||
}},
|
}},
|
||||||
OPEN: {Hand: func(m *ice.Message, arg ...string) {
|
OPEN: {Hand: func(m *ice.Message, arg ...string) {
|
||||||
ctx.ProcessOpen(m, kit.Format("http://%s:%s", m.Option(tcp.HOST), m.Option(tcp.PORT)))
|
ctx.ProcessOpen(m, kit.Format("http://%s:%s", m.Option(tcp.HOST), m.Option(tcp.PORT)))
|
||||||
|
@ -45,7 +45,9 @@ func Render(m *ice.Message, cmd string, args ...ice.Any) bool {
|
|||||||
RenderCookie(m, arg[0], arg[1:]...)
|
RenderCookie(m, arg[0], arg[1:]...)
|
||||||
|
|
||||||
case STATUS, ice.RENDER_STATUS: // [code [text]]
|
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...]
|
case ice.RENDER_REDIRECT: // url [arg...]
|
||||||
http.Redirect(m.W, m.R, kit.MergeURL(arg[0], arg[1:]), http.StatusTemporaryRedirect)
|
http.Redirect(m.W, m.R, kit.MergeURL(arg[0], arg[1:]), http.StatusTemporaryRedirect)
|
||||||
|
@ -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.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)...)
|
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)) {
|
for _, v := range kit.Split(m.Option(ice.DEV)) {
|
||||||
m.Cmd(SPACE, tcp.DIAL, ice.DEV, v, mdb.NAME, ice.Info.NodeName)
|
m.Cmd(SPACE, tcp.DIAL, ice.DEV, v, mdb.NAME, ice.Info.NodeName)
|
||||||
}
|
}
|
||||||
@ -187,11 +187,11 @@ func init() {
|
|||||||
_serve_start(m)
|
_serve_start(m)
|
||||||
}},
|
}},
|
||||||
SERVE_START: {Hand: func(m *ice.Message, arg ...string) {
|
SERVE_START: {Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
m.Go(func() { m.Cmd(BROAD, SERVE, m.OptionSimple(tcp.PORT)) })
|
||||||
go func() {
|
go func() {
|
||||||
m.Option(ice.LOG_DISABLE, ice.TRUE)
|
|
||||||
opened := false
|
opened := false
|
||||||
for i := 0; i < 3 && !opened; i++ {
|
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 {
|
if values[mdb.TYPE] == CHROME {
|
||||||
opened = true
|
opened = true
|
||||||
}
|
}
|
||||||
@ -202,7 +202,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
switch host := "http://localhost:" + m.Option(tcp.PORT); runtime.GOOS {
|
switch host := "http://localhost:" + m.Option(tcp.PORT); runtime.GOOS {
|
||||||
case cli.WINDOWS:
|
case cli.WINDOWS:
|
||||||
m.Cmd(cli.SYSTEM, "explorer.exe", host)
|
m.Cmd(cli.SYSTEM, "explorer", host)
|
||||||
case cli.DARWIN:
|
case cli.DARWIN:
|
||||||
m.Cmd(cli.SYSTEM, "open", host)
|
m.Cmd(cli.SYSTEM, "open", host)
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ func _spide_create(m *ice.Message, name, address string) {
|
|||||||
dir, file := path.Split(uri.EscapedPath())
|
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,
|
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,
|
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,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -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) {
|
}, 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())
|
_autogen_version(m.Spawn())
|
||||||
main, file, goos, arch := _compile_target(m, arg...)
|
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") {
|
if !strings.Contains(m.Cmdx(nfs.CAT, ice.GO_MOD), "shylinux.com/x/ice") {
|
||||||
m.Cmd(cli.SYSTEM, GO, "get", "shylinux.com/x/ice")
|
m.Cmd(cli.SYSTEM, GO, "get", "shylinux.com/x/ice")
|
||||||
}
|
}
|
||||||
|
@ -87,13 +87,6 @@ func init() {
|
|||||||
Index.MergeCommands(ice.Commands{
|
Index.MergeCommands(ice.Commands{
|
||||||
PUBLISH: {Name: "publish path auto create volcanos icebergs intshell", Help: "发布", Actions: ice.MergeActions(ice.Actions{
|
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) }},
|
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) {
|
ice.VOLCANOS: {Help: "火山架", Hand: func(m *ice.Message, arg ...string) {
|
||||||
defer func() { m.EchoQRCode(m.Option(ice.MSG_USERWEB)) }()
|
defer func() { m.EchoQRCode(m.Option(ice.MSG_USERWEB)) }()
|
||||||
defer func() { m.Cmdy(PUBLISH, ice.CONTEXTS, ice.MISC) }()
|
defer func() { m.Cmdy(PUBLISH, ice.CONTEXTS, ice.MISC) }()
|
||||||
@ -108,6 +101,7 @@ func init() {
|
|||||||
_publish_list(m, kit.ExtReg(`(sh|vim|conf)`))
|
_publish_list(m, kit.ExtReg(`(sh|vim|conf)`))
|
||||||
}},
|
}},
|
||||||
ice.CONTEXTS: {Hand: func(m *ice.Message, arg ...string) { _publish_contexts(m, arg...) }},
|
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)) }},
|
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))) }},
|
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) {
|
}, ctx.ConfAction(ice.CONTEXTS, _contexts), aaa.RoleAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
9
init.go
9
init.go
@ -95,9 +95,6 @@ func Run(arg ...string) string {
|
|||||||
if len(arg) == 0 && runtime.GOOS == "windows" {
|
if len(arg) == 0 && runtime.GOOS == "windows" {
|
||||||
arg = append(arg, SERVE, START, DEV, DEV)
|
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
|
Pulse.meta[MSG_DETAIL] = arg
|
||||||
kit.Fetch(kit.Sort(os.Environ()), func(env string) {
|
kit.Fetch(kit.Sort(os.Environ()), func(env string) {
|
||||||
if ls := strings.SplitN(env, EQ, 2); strings.ToLower(ls[0]) == ls[0] && ls[0] != "_" {
|
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)))
|
os.Exit(kit.Int(Pulse.Option(EXIT)))
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
if logs.Disable(true); len(arg) == 0 {
|
// if logs.Disable(true); len(arg) == 0 {
|
||||||
arg = append(arg, HELP)
|
// arg = append(arg, HELP)
|
||||||
}
|
// }
|
||||||
if Pulse.Cmdy(INIT).Cmdy(arg); Pulse.IsErrNotFound() {
|
if Pulse.Cmdy(INIT).Cmdy(arg); Pulse.IsErrNotFound() {
|
||||||
Pulse.SetAppend().SetResult().Cmdy(SYSTEM, arg)
|
Pulse.SetAppend().SetResult().Cmdy(SYSTEM, arg)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user