forked from x/icebergs
opt code
This commit is contained in:
parent
70f50b91c1
commit
8ea2beab9d
@ -2,6 +2,7 @@ package lex
|
||||
|
||||
const (
|
||||
PATTERN = "pattern"
|
||||
EXTREG = "extreg"
|
||||
REGEXP = "regexp"
|
||||
PREFIX = "prefix"
|
||||
SUFFIX = "suffix"
|
||||
|
@ -31,10 +31,10 @@ func _autogen_source(m *ice.Message, main, file string) {
|
||||
m.Cmd(nfs.PUSH, main, lex.NL+ssh.SOURCE+lex.SP+strings.TrimPrefix(file, nfs.SRC)+lex.NL)
|
||||
}
|
||||
func _autogen_script(m *ice.Message, file string) {
|
||||
m.Cmd(nfs.DEFS, file, nfs.Template(m, "demo.shy"))
|
||||
m.Cmd(nfs.DEFS, file, nfs.Template(m, DEMO_SHY))
|
||||
}
|
||||
func _autogen_module(m *ice.Message, file string) {
|
||||
m.Cmd(nfs.DEFS, file, nfs.Template(m, "demo.go"))
|
||||
m.Cmd(nfs.DEFS, file, nfs.Template(m, DEMO_GO))
|
||||
}
|
||||
func _autogen_import(m *ice.Message, main string, ctx string, mod string) {
|
||||
m.Cmd(nfs.DEFS, ice.ETC_MISS_SH, m.Cmdx(nfs.CAT, ice.ETC_MISS_SH))
|
||||
@ -52,26 +52,26 @@ func _autogen_import(m *ice.Message, main string, ctx string, mod string) {
|
||||
}
|
||||
if strings.HasPrefix(line, "import (") {
|
||||
begin = true
|
||||
} else if strings.HasPrefix(line, "import") {
|
||||
} else if strings.HasPrefix(line, IMPORT) {
|
||||
done, list = true, append(list, kit.Format(`import _ "%s/src/%s"`, mod, ctx))
|
||||
}
|
||||
})
|
||||
m.Cmd(nfs.SAVE, main, kit.Join(list, lex.NL))
|
||||
m.Cmd(cli.SYSTEM, "goimports", "-w", main)
|
||||
GoImports(m, main)
|
||||
}
|
||||
func _autogen_version(m *ice.Message) string {
|
||||
if mod := _autogen_mod(m, ice.GO_MOD); !nfs.Exists(m, ".git") {
|
||||
m.Cmd(REPOS, "init", nfs.ORIGIN, strings.Split(kit.MergeURL2(kit.Select(m.Option(ice.MSG_USERWEB), ice.Info.Make.Remote), "/x/"+path.Base(mod)), mdb.QS)[0], mdb.NAME, path.Base(mod), nfs.PATH, nfs.PWD)
|
||||
defer m.Cmd(REPOS, "add", kit.Dict(nfs.REPOS, path.Base(mod), nfs.FILE, ice.GO_MOD))
|
||||
defer m.Cmd(REPOS, "add", kit.Dict(nfs.REPOS, path.Base(mod), nfs.FILE, nfs.SRC))
|
||||
m.Cmd(REPOS, INIT, nfs.ORIGIN, strings.Split(kit.MergeURL2(kit.Select(m.Option(ice.MSG_USERWEB), ice.Info.Make.Remote), "/x/"+path.Base(mod)), mdb.QS)[0], mdb.NAME, path.Base(mod), nfs.PATH, nfs.PWD)
|
||||
defer m.Cmd(REPOS, ADD, kit.Dict(nfs.REPOS, path.Base(mod), nfs.FILE, ice.GO_MOD))
|
||||
defer m.Cmd(REPOS, ADD, kit.Dict(nfs.REPOS, path.Base(mod), nfs.FILE, nfs.SRC))
|
||||
}
|
||||
m.Cmd(nfs.DEFS, ".gitignore", nfs.Template(m, "gitignore"))
|
||||
m.Cmd(nfs.DEFS, ice.SRC_BINPACK_GO, nfs.Template(m, ice.SRC_BINPACK_GO))
|
||||
m.Cmd(nfs.SAVE, ice.SRC_VERSION_GO, kit.Format(nfs.Template(m, ice.SRC_VERSION_GO), _autogen_gits(m)))
|
||||
m.Cmd(cli.SYSTEM, "gofmt", "-w", ice.SRC_VERSION_GO)
|
||||
m.Cmdy(nfs.DIR, ice.SRC_BINPACK_GO)
|
||||
m.Cmdy(nfs.DIR, ice.SRC_VERSION_GO)
|
||||
m.Cmdy(nfs.DIR, ice.SRC_MAIN_GO)
|
||||
GoFmt(m, ice.SRC_VERSION_GO)
|
||||
return ice.SRC_VERSION_GO
|
||||
}
|
||||
func _autogen_gits(m *ice.Message, arg ...string) string {
|
||||
@ -82,16 +82,16 @@ func _autogen_gits(m *ice.Message, arg ...string) string {
|
||||
return kit.Join(res, lex.NL)
|
||||
}
|
||||
func _autogen_git(m *ice.Message, arg ...string) ice.Map {
|
||||
msg := m.Cmd("web.code.git.repos", "remote")
|
||||
msg := m.Cmd(REPOS, REMOTE)
|
||||
return kit.Dict(arg, aaa.USERNAME, ice.Info.Username, tcp.HOSTNAME, ice.Info.Hostname, nfs.PATH, kit.Path("")+nfs.PS, mdb.TIME, m.Time(),
|
||||
GIT, m.Cmdx(cli.SYSTEM, GIT, VERSION), GO, m.Cmdx(cli.SYSTEM, GO, VERSION), nfs.MODULE, _autogen_mod(m, ice.GO_MOD),
|
||||
GIT, GitVersion(m), GO, GoVersion(m), nfs.MODULE, _autogen_mod(m, ice.GO_MOD),
|
||||
msg.AppendSimple("remote,branch,version,forword,author,email,hash,when,message"),
|
||||
web.DOMAIN, strings.ReplaceAll(tcp.PublishLocalhost(m, m.Option(ice.MSG_USERWEB)), "%2F", nfs.PS),
|
||||
cli.SYSTEM, ice.Info.System,
|
||||
)
|
||||
}
|
||||
func _autogen_mod(m *ice.Message, file string) (mod string) {
|
||||
host := kit.ParseURL(kit.Select(m.Option(ice.MSG_USERHOST), ice.Info.Make.Remote, m.Cmdx("web.code.git.repos", "remoteURL"))).Hostname()
|
||||
host := kit.ParseURL(kit.Select(m.Option(ice.MSG_USERHOST), ice.Info.Make.Remote, m.Cmdx(REPOS, REMOTE_URL))).Hostname()
|
||||
if host == "" {
|
||||
host = path.Base(kit.Path(""))
|
||||
} else {
|
||||
@ -104,14 +104,11 @@ func _autogen_mod(m *ice.Message, file string) (mod string) {
|
||||
return
|
||||
}
|
||||
|
||||
const (
|
||||
VERSION = "version"
|
||||
)
|
||||
const AUTOGEN = "autogen"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
AUTOGEN: {Name: "autogen path auto script module version", Help: "生成", Actions: ice.Actions{
|
||||
AUTOGEN: {Name: "autogen path auto script module devpack webpack binpack version", Help: "生成", Actions: ice.Actions{
|
||||
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) {
|
||||
switch arg[0] {
|
||||
case cli.MAIN:
|
||||
|
@ -9,7 +9,6 @@ import (
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/lex"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
@ -34,7 +33,7 @@ func _binpack_file(m *ice.Message, w io.Writer, arg ...string) {
|
||||
if f, e := nfs.OpenFile(m, arg[0]); !m.Warn(e, ice.ErrNotFound, arg[0]) {
|
||||
defer f.Close()
|
||||
if b, e := ioutil.ReadAll(f); !m.Warn(e, ice.ErrNotValid, arg[0]) {
|
||||
kit.If(len(b) > 1<<20, func() { m.Warn("too larger %s %s", arg[0], len(b)) })
|
||||
kit.If(len(b) > 1<<20, func() { m.Warn("too large %s %s", arg[0], len(b)) })
|
||||
fmt.Fprintf(w, " \"%s\": \"%s\",\n", kit.Select(arg[0], arg, 1), base64.StdEncoding.EncodeToString(b))
|
||||
}
|
||||
}
|
||||
@ -69,7 +68,7 @@ func _binpack_all(m *ice.Message) {
|
||||
}
|
||||
for _, k := range kit.SortedKey(list) {
|
||||
v := kit.Select(k, list[k])
|
||||
m.Cmd(nfs.DIR, nfs.PWD, nfs.PATH, kit.Dict(nfs.DIR_ROOT, v, nfs.DIR_REG, kit.ExtReg(kit.Split(mdb.Config(m, "extreg"))...))).Table(func(value ice.Maps) {
|
||||
m.Cmd(nfs.DIR, nfs.PWD, nfs.PATH, kit.Dict(nfs.DIR_ROOT, v, nfs.DIR_REG, kit.ExtReg(kit.Split(mdb.Config(m, lex.EXTREG))...))).Table(func(value ice.Maps) {
|
||||
if kit.HasPrefix(k, ice.USR_ICEBERGS) && !nfs.Exists(m, ice.USR_ICEBERGS) || m.Option(ice.MSG_USERPOD) != "" {
|
||||
return
|
||||
}
|
||||
@ -96,15 +95,13 @@ func init() {
|
||||
BINPACK: {Name: "binpack path auto create insert", Help: "打包", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.CREATE: {Hand: func(m *ice.Message, arg ...string) { _binpack_all(m) }},
|
||||
mdb.INSERT: {Name: "insert path*", Hand: func(m *ice.Message, arg ...string) { mdb.HashCreate(m) }},
|
||||
}, mdb.HashAction(mdb.SHORT, nfs.PATH, mdb.FIELD, "time,path", "extreg", "sh,shy,py,js,css,html,png,jpg"))},
|
||||
}, mdb.HashAction(mdb.SHORT, nfs.PATH, mdb.FIELD, "time,path", lex.EXTREG, "sh,shy,py,js,css,html,png,jpg"))},
|
||||
})
|
||||
}
|
||||
func GoCache(m *ice.Message) string {
|
||||
return kit.GetValid(
|
||||
func() string { return m.Cmdx(cli.SYSTEM, GO, "env", "GOMODCACHE") },
|
||||
func() string {
|
||||
return kit.Select(kit.HomePath("go")+nfs.PS, m.Cmdx(cli.SYSTEM, GO, "env", "GOPATH")) + "/pkg/mod/"
|
||||
},
|
||||
func() string { return GoEnv(m, GOMODCACHE) },
|
||||
func() string { return kit.Select(kit.HomePath(GO)+nfs.PS, GoEnv(m, GOPATH)) + "/pkg/mod/" },
|
||||
func() string { return ice.USR_REQUIRE },
|
||||
)
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
|
||||
func _c_show(m *ice.Message, arg ...string) {
|
||||
target := path.Join(ice.BIN, kit.TrimExt(arg[1], arg[0]))
|
||||
if msg := m.Cmd(cli.SYSTEM, "gcc", "-o", target, path.Join(arg[2], arg[1])); cli.IsSuccess(msg) {
|
||||
if msg := Gcc(m.Spawn(), target, path.Join(arg[2], arg[1])); cli.IsSuccess(msg) {
|
||||
ProcessXterm(m, nfs.SH, target, path.Join(arg[2], arg[1]))
|
||||
} else {
|
||||
_vimer_make(m, arg[2], msg)
|
||||
@ -20,7 +20,7 @@ func _c_show(m *ice.Message, arg ...string) {
|
||||
}
|
||||
func _c_exec(m *ice.Message, arg ...string) {
|
||||
target := path.Join(ice.BIN, kit.TrimExt(arg[1], arg[0]))
|
||||
if msg := m.Cmd(cli.SYSTEM, "gcc", "-o", target, path.Join(arg[2], arg[1])); cli.IsSuccess(msg) {
|
||||
if msg := Gcc(m.Spawn(), target, path.Join(arg[2], arg[1])); cli.IsSuccess(msg) {
|
||||
m.Cmdy(cli.SYSTEM, target).StatusTime(nfs.PATH, target)
|
||||
} else {
|
||||
_vimer_make(m, arg[2], msg)
|
||||
@ -33,6 +33,10 @@ func _c_tags(m *ice.Message, cmd ...string) {
|
||||
_inner_tags(m, m.Option(nfs.PATH), m.Option(mdb.NAME))
|
||||
}
|
||||
|
||||
const (
|
||||
CTAGS = "ctags"
|
||||
GCC = "gcc"
|
||||
)
|
||||
const H = "h"
|
||||
const C = "c"
|
||||
|
||||
@ -41,11 +45,14 @@ func init() {
|
||||
C: {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) { _c_exec(m, arg...) }},
|
||||
TEMPLATE: {Hand: func(m *ice.Message, arg ...string) { m.Echo(nfs.Template(m, "demo.c")) }},
|
||||
NAVIGATE: {Hand: func(m *ice.Message, arg ...string) { _c_tags(m, "ctags", "-a", "-R", nfs.PWD) }},
|
||||
TEMPLATE: {Hand: func(m *ice.Message, arg ...string) { m.Echo(nfs.Template(m, DEMO_C)) }},
|
||||
NAVIGATE: {Hand: func(m *ice.Message, arg ...string) { _c_tags(m, CTAGS, "-a", "-R", nfs.PWD) }},
|
||||
}, PlugAction())},
|
||||
H: {Actions: ice.MergeActions(ice.Actions{
|
||||
NAVIGATE: {Hand: func(m *ice.Message, arg ...string) { _c_tags(m, "ctags", "-a", "-R", nfs.PWD) }},
|
||||
NAVIGATE: {Hand: func(m *ice.Message, arg ...string) { _c_tags(m, CTAGS, "-a", "-R", nfs.PWD) }},
|
||||
}, PlugAction())},
|
||||
})
|
||||
}
|
||||
func Gcc(m *ice.Message, target, source string) *ice.Message {
|
||||
return m.Cmdy(cli.SYSTEM, GCC, "-o", target, source)
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package code
|
||||
import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/web"
|
||||
"shylinux.com/x/icebergs/base/yac"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
@ -13,16 +12,8 @@ var Index = &ice.Context{Name: CODE, Help: "编程中心"}
|
||||
|
||||
func init() {
|
||||
web.Index.Register(Index, &web.Frame{},
|
||||
INSTALL, UPGRADE, WEBPACK, BINPACK, AUTOGEN, COMPILE, PUBLISH,
|
||||
VIMER, INNER, XTERM, PPROF, BENCH,
|
||||
C, SH, SHY, PY, GO, JS, CSS, HTML,
|
||||
TEMPLATE, COMPLETE, NAVIGATE,
|
||||
WEBPACK, BINPACK, AUTOGEN, COMPILE, PUBLISH, UPGRADE, INSTALL,
|
||||
XTERM, INNER, VIMER, BENCH, PPROF,
|
||||
)
|
||||
}
|
||||
func init() {
|
||||
return
|
||||
ice.Info.Stack[Prefix(Index.Register)] = func(m *ice.Message, key string, arg ...ice.Any) ice.Any {
|
||||
return Index.Register(yac.TransContext(m, Prefix(), arg...), &web.Frame{})
|
||||
}
|
||||
}
|
||||
func Prefix(arg ...ice.Any) string { return web.Prefix(CODE, kit.Keys(arg...)) }
|
||||
|
@ -1,6 +1,5 @@
|
||||
code.go
|
||||
code.shy
|
||||
|
||||
webpack.go
|
||||
binpack.go
|
||||
autogen.go
|
||||
|
@ -37,7 +37,7 @@ func _compile_get(m *ice.Message, main string) {
|
||||
block, list := false, []string{}
|
||||
m.Cmd(lex.SPLIT, main, func(ls []string) {
|
||||
switch ls[0] {
|
||||
case "import":
|
||||
case IMPORT:
|
||||
if ls[1] == "(" {
|
||||
block = true
|
||||
} else {
|
||||
@ -58,16 +58,16 @@ func _compile_get(m *ice.Message, main string) {
|
||||
} else if ls := kit.Slice(strings.Split(p, nfs.PS), 0, 3); _list[path.Join(ls...)] {
|
||||
return
|
||||
}
|
||||
m.Cmd(cli.SYSTEM, GO, "get", p)
|
||||
GoGet(m, p)
|
||||
})
|
||||
}
|
||||
func _compile_mod(m *ice.Message) map[string]bool {
|
||||
block, list := false, map[string]bool{}
|
||||
m.Cmd(lex.SPLIT, ice.GO_MOD, func(ls []string) {
|
||||
switch ls[0] {
|
||||
case "module":
|
||||
case MODULE:
|
||||
list[ls[1]] = true
|
||||
case "require":
|
||||
case REQUIRE:
|
||||
if ls[1] == "(" {
|
||||
block = true
|
||||
} else {
|
||||
@ -76,9 +76,7 @@ func _compile_mod(m *ice.Message) map[string]bool {
|
||||
case ")":
|
||||
block = false
|
||||
default:
|
||||
if block {
|
||||
list[kit.Select("", ls, 0)] = true
|
||||
}
|
||||
kit.If(block, func() { list[kit.Select("", ls, 0)] = true })
|
||||
}
|
||||
})
|
||||
return list
|
||||
@ -87,10 +85,6 @@ func _compile_mod(m *ice.Message) map[string]bool {
|
||||
const COMPILE = "compile"
|
||||
|
||||
func init() {
|
||||
const (
|
||||
SERVICE = "service"
|
||||
VERSION = "version"
|
||||
)
|
||||
Index.MergeCommands(ice.Commands{
|
||||
COMPILE: {Name: "compile arch=amd64,386,arm,arm64,mipsle os=linux,darwin,windows src=src/main.go@key run binpack webpack devpack install", Icon: "go.png", Help: "编译", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { cli.IsAlpine(m, GO, "go git") }},
|
||||
@ -104,7 +98,7 @@ func init() {
|
||||
m.Cmdy(nfs.DIR, ice.SRC, nfs.DIR_CLI_FIELDS, kit.Dict(nfs.DIR_REG, kit.ExtReg(GO)))
|
||||
}
|
||||
}},
|
||||
BINPACK: {Help: "版本", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(AUTOGEN, BINPACK) }},
|
||||
BINPACK: {Help: "发布", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(AUTOGEN, BINPACK) }},
|
||||
WEBPACK: {Help: "打包", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(AUTOGEN, WEBPACK) }},
|
||||
DEVPACK: {Help: "开发", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(AUTOGEN, DEVPACK) }},
|
||||
INSTALL: {Name: "install service*='https://golang.google.cn/dl/' version*=1.13.5", Help: "安装", Hand: func(m *ice.Message, arg ...string) {
|
||||
@ -118,15 +112,15 @@ func init() {
|
||||
})
|
||||
}},
|
||||
web.DREAM_ACTION: {Hand: func(m *ice.Message, arg ...string) { web.DreamProcess(m, []string{}, arg...) }},
|
||||
}, 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) {
|
||||
defer web.ToastProcess(m)()
|
||||
main, file, goos, arch := _compile_target(m, arg...)
|
||||
env := kit.Simple(cli.PATH, cli.BinPath(), cli.HOME, kit.Select(kit.Path(""), kit.Env(cli.HOME)), mdb.Configv(m, cli.ENV), m.Optionv(cli.ENV), cli.GOOS, goos, cli.GOARCH, arch)
|
||||
kit.If(runtime.GOOS == cli.WINDOWS, func() { env = append(env, "GOPATH", kit.HomePath(GO), "GOCACHE", kit.HomePath("go/go-build")) })
|
||||
kit.If(runtime.GOOS == cli.WINDOWS, func() { env = append(env, GOPATH, kit.HomePath(GO), GOCACHE, kit.HomePath("go/go-build")) })
|
||||
m.Options(cli.CMD_ENV, env).Cmd(AUTOGEN, VERSION)
|
||||
_compile_get(m, main)
|
||||
defer m.StatusTime(VERSION, strings.TrimPrefix(m.Cmdx(cli.SYSTEM, GO, VERSION), "go version"))
|
||||
if msg := m.Cmd(cli.SYSTEM, GO, cli.BUILD, "-ldflags", "-w -s", "-o", file, main, ice.SRC_VERSION_GO, ice.SRC_BINPACK_GO); !cli.IsSuccess(msg) {
|
||||
defer m.StatusTime(VERSION, strings.TrimPrefix(GoVersion(m), "go version"))
|
||||
if msg := GoBuild(m.Spawn(), file, main, ice.SRC_VERSION_GO, ice.SRC_BINPACK_GO); !cli.IsSuccess(msg) {
|
||||
m.Copy(msg)
|
||||
} else {
|
||||
m.Logs(nfs.SAVE, nfs.TARGET, file, nfs.SOURCE, main)
|
||||
|
@ -71,7 +71,7 @@ func init() {
|
||||
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { _css_show(m, arg...) }},
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { _css_exec(m, arg...) }},
|
||||
TEMPLATE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Echo(kit.Format(nfs.Template(m, "demo.css"), kit.Select(mdb.PLUGIN, ctx.GetFileCmd(kit.ExtChange(path.Join(arg[2], arg[1]), GO)))))
|
||||
m.Echo(kit.Format(nfs.Template(m, DEMO_CSS), kit.Select(mdb.PLUGIN, ctx.GetFileCmd(kit.ExtChange(path.Join(arg[2], arg[1]), GO)))))
|
||||
}},
|
||||
}, PlugAction())},
|
||||
})
|
||||
|
@ -31,19 +31,10 @@ func _go_trans(m *ice.Message, key string) string {
|
||||
return key
|
||||
}
|
||||
func _go_complete(m *ice.Message, arg ...string) {
|
||||
const (
|
||||
PACKAGE = "package"
|
||||
IMPORT = "import"
|
||||
CONST = "const"
|
||||
TYPE = "type"
|
||||
FUNC = "func"
|
||||
VAR = "var"
|
||||
)
|
||||
if m.Option(mdb.TEXT) == "" {
|
||||
m.Push(mdb.TEXT, PACKAGE, IMPORT, CONST, TYPE, FUNC, VAR)
|
||||
} else if strings.HasSuffix(m.Option(mdb.TEXT), nfs.PT) {
|
||||
msg := m.Cmd(cli.SYSTEM, GO, "doc", _go_trans(m, kit.Slice(kit.Split(m.Option(mdb.TEXT), "\t ."), -1)[0]))
|
||||
for _, l := range strings.Split(kit.Select(msg.Result(), msg.Append(cli.CMD_OUT)), lex.NL) {
|
||||
for _, l := range strings.Split(GoDoc(m, _go_trans(m, kit.Slice(kit.Split(m.Option(mdb.TEXT), "\t ."), -1)[0])), lex.NL) {
|
||||
if ls := kit.Split(l, "\t *", "()"); len(ls) > 1 {
|
||||
kit.Switch(ls[0], []string{CONST, TYPE, FUNC, VAR}, func() {
|
||||
kit.If(ls[1] == "(", func() { m.Push(mdb.NAME, ls[5]) }, func() { m.Push(mdb.NAME, ls[1]) })
|
||||
@ -53,7 +44,7 @@ func _go_complete(m *ice.Message, arg ...string) {
|
||||
}
|
||||
} else {
|
||||
m.Push(mdb.TEXT, "m", "msg", "code", "wiki", "chat", "team", "mall", "arg", "aaa", "cli", "ctx", "mdb", "nfs", "web", "ice", "kit")
|
||||
for _, l := range strings.Split(m.Cmdx(cli.SYSTEM, GO, "list", "std"), lex.NL) {
|
||||
for _, l := range strings.Split(GoStd(m), lex.NL) {
|
||||
m.Push(mdb.TEXT, kit.Slice(kit.Split(l, nfs.PS), -1)[0])
|
||||
}
|
||||
}
|
||||
@ -68,10 +59,10 @@ func _go_navigate(m *ice.Message, arg ...string) {
|
||||
}
|
||||
}
|
||||
}
|
||||
_c_tags(m, "gotags", "-f", nfs.TAGS, "-R", nfs.PWD)
|
||||
_c_tags(m, GOTAGS, "-f", nfs.TAGS, "-R", nfs.PWD)
|
||||
}
|
||||
func _go_show(m *ice.Message, arg ...string) {
|
||||
if arg[1] == "main.go" {
|
||||
if arg[1] == MAIN_GO {
|
||||
ProcessXterm(m, "ish", "", arg[1])
|
||||
} else if cmd := ctx.GetFileCmd(path.Join(arg[2], arg[1])); cmd != "" {
|
||||
ctx.ProcessField(m, cmd, kit.Simple())
|
||||
@ -82,18 +73,12 @@ func _go_show(m *ice.Message, arg ...string) {
|
||||
}
|
||||
}
|
||||
func _mod_show(m *ice.Message, file string) {
|
||||
const (
|
||||
MODULE = "module"
|
||||
REQUIRE = "require"
|
||||
REPLACE = "replace"
|
||||
VERSION = "version"
|
||||
)
|
||||
require, replace, block := ice.Maps{}, ice.Maps{}, ""
|
||||
m.Cmd(nfs.CAT, file, func(ls []string, line string) {
|
||||
switch {
|
||||
case strings.HasPrefix(line, "//"):
|
||||
case strings.HasPrefix(line, MODULE):
|
||||
require[ls[1]], replace[ls[1]] = m.Cmdx(cli.SYSTEM, GIT, "describe", "--tags"), nfs.PWD
|
||||
require[ls[1]], replace[ls[1]] = ice.Info.Make.Versions(), nfs.PWD
|
||||
case strings.HasPrefix(line, REQUIRE+" ("):
|
||||
block = REQUIRE
|
||||
case strings.HasPrefix(line, REPLACE+" ("):
|
||||
@ -117,6 +102,39 @@ func _sum_show(m *ice.Message, file string) {
|
||||
}).StatusTimeCount()
|
||||
}
|
||||
|
||||
const (
|
||||
PACKAGE = "package"
|
||||
IMPORT = "import"
|
||||
CONST = "const"
|
||||
TYPE = "type"
|
||||
FUNC = "func"
|
||||
VAR = "var"
|
||||
)
|
||||
const (
|
||||
MODULE = "module"
|
||||
REQUIRE = "require"
|
||||
REPLACE = "replace"
|
||||
VERSION = "version"
|
||||
SERVICE = "service"
|
||||
)
|
||||
const (
|
||||
GOFMT = "gofmt"
|
||||
GOIMPORTS = "goimports"
|
||||
GOTAGS = "gotags"
|
||||
)
|
||||
const (
|
||||
GOPRIVATE = "GOPRIVATE"
|
||||
GOPROXY = "GOPROXY"
|
||||
GOPATH = "GOPATH"
|
||||
GOCACHE = "GOCACHE"
|
||||
GOMODCACHE = "GOMODCACHE"
|
||||
CGO_ENABLED = "CGO_ENABLED"
|
||||
)
|
||||
const (
|
||||
ENV = "env"
|
||||
DOC = "doc"
|
||||
GET = "get"
|
||||
)
|
||||
const SUM = "sum"
|
||||
const MOD = "mod"
|
||||
const GO = "go"
|
||||
@ -129,8 +147,8 @@ func init() {
|
||||
TEMPLATE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Option(mdb.NAME, kit.TrimExt(path.Base(arg[1]), GO))
|
||||
m.Option(mdb.ZONE, path.Base(path.Dir(path.Join(arg[2], arg[1]))))
|
||||
m.Option(mdb.KEY, kit.Keys("web.code", m.Option(mdb.ZONE), m.Option(mdb.NAME)))
|
||||
m.Echo(nfs.Template(m, "demo.go"))
|
||||
m.Option(mdb.KEY, Prefix(m.Option(mdb.ZONE), m.Option(mdb.NAME)))
|
||||
m.Echo(nfs.Template(m, DEMO_GO))
|
||||
}},
|
||||
COMPLETE: {Hand: func(m *ice.Message, arg ...string) { _go_complete(m, arg...) }},
|
||||
NAVIGATE: {Hand: func(m *ice.Message, arg ...string) { _go_navigate(m, arg...) }},
|
||||
@ -138,8 +156,8 @@ func init() {
|
||||
switch p := path.Join(m.Option(nfs.PATH), m.Option(nfs.FILE)); kit.Ext(m.Option(nfs.FILE)) {
|
||||
case nfs.GO:
|
||||
defer m.Cmdy(nfs.CAT, p)
|
||||
m.Cmd(cli.SYSTEM, "gofmt", "-w", p)
|
||||
m.Cmd(cli.SYSTEM, "goimports", "-w", p)
|
||||
defer GoImports(m, p)
|
||||
defer GoFmt(m, p)
|
||||
}
|
||||
}},
|
||||
}, gdb.EventsAction(VIMER_SAVE), PlugAction())},
|
||||
@ -153,3 +171,16 @@ func init() {
|
||||
}, PlugAction())},
|
||||
})
|
||||
}
|
||||
func GoEnv(m *ice.Message, k string) string { return m.Cmdx(cli.SYSTEM, GO, ENV, k) }
|
||||
func GoDoc(m *ice.Message, k string) string {
|
||||
msg := m.Cmd(cli.SYSTEM, GO, DOC, k)
|
||||
return kit.Select(msg.Result(), msg.Append(cli.CMD_OUT))
|
||||
}
|
||||
func GoStd(m *ice.Message) string { return m.Cmdx(cli.SYSTEM, GO, "list", "std") }
|
||||
func GoGet(m *ice.Message, p string) { m.Cmd(cli.SYSTEM, GO, GET, p) }
|
||||
func GoFmt(m *ice.Message, p string) { m.Cmd(cli.SYSTEM, GOFMT, "-w", p) }
|
||||
func GoImports(m *ice.Message, p string) { m.Cmd(cli.SYSTEM, GOIMPORTS, "-w", p) }
|
||||
func GoVersion(m *ice.Message) string { return m.Cmdx(cli.SYSTEM, GO, VERSION) }
|
||||
func GoBuild(m *ice.Message, target string, arg ...string) *ice.Message {
|
||||
return m.Cmdy(cli.SYSTEM, GO, cli.BUILD, "-ldflags", "-w -s", "-o", target, arg)
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ func init() {
|
||||
m.EchoIFrame(kit.MergeURL(require(arg[2], arg[1]), "_v", kit.Hashs(mdb.UNIQ)))
|
||||
}},
|
||||
TEMPLATE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Echo(nfs.Template(m, "demo.html"))
|
||||
m.Echo(nfs.Template(m, DEMO_HTML))
|
||||
}},
|
||||
}, PlugAction())},
|
||||
})
|
||||
|
@ -158,7 +158,7 @@ func LoadPlug(m *ice.Message, lang ...string) {
|
||||
}
|
||||
}
|
||||
func TagsList(m *ice.Message, cmds ...string) {
|
||||
for _, l := range strings.Split(m.Cmdx(cli.SYSTEM, kit.Default(cmds, "ctags", "--excmd=number", "--sort=no", "-f", "-", path.Join(m.Option(nfs.PATH), m.Option(nfs.FILE)))), lex.NL) {
|
||||
for _, l := range strings.Split(m.Cmdx(cli.SYSTEM, kit.Default(cmds, CTAGS, "--excmd=number", "--sort=no", "-f", "-", path.Join(m.Option(nfs.PATH), m.Option(nfs.FILE)))), lex.NL) {
|
||||
if strings.HasPrefix(l, "!_") {
|
||||
continue
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
func _js_show(m *ice.Message, arg ...string) {
|
||||
if arg[1] == "main.js" {
|
||||
if arg[1] == MAIN_JS {
|
||||
ctx.ProcessField(m, web.CHAT_IFRAME, kit.Simple(web.UserHost(m)))
|
||||
} else if arg[2] == ice.USR_VOLCANOS {
|
||||
if strings.HasPrefix(arg[1], "plugin/local/") {
|
||||
@ -32,7 +32,7 @@ func init() {
|
||||
JS: {Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { _js_show(m, arg...) }},
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { _js_show(m, arg...) }},
|
||||
TEMPLATE: {Hand: func(m *ice.Message, arg ...string) { m.Echo(nfs.Template(m, "demo.js")) }},
|
||||
TEMPLATE: {Hand: func(m *ice.Message, arg ...string) { m.Echo(nfs.Template(m, DEMO_JS)) }},
|
||||
}, PlugAction())},
|
||||
})
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ func _makefile_xterm(m *ice.Message, arg ...string) {
|
||||
if ls := kit.Simple(kit.UnMarshal(m.Option(ctx.ARGS))); len(ls) > 0 {
|
||||
return ls
|
||||
}
|
||||
return []string{mdb.TYPE, "sh", nfs.PATH, kit.Select("", kit.Dir(arg[2], arg[1]), arg[2] != ice.SRC)}
|
||||
return []string{mdb.TYPE, SH, nfs.PATH, kit.Select("", kit.Dir(arg[2], arg[1]), arg[2] != ice.SRC)}
|
||||
}, arg...)
|
||||
}
|
||||
|
||||
|
@ -47,9 +47,9 @@ func _publish_contexts(m *ice.Message, arg ...string) {
|
||||
m.Option(web.DOMAIN, m.Cmd(web.SPIDE, ice.SHY).Append(web.CLIENT_ORIGIN))
|
||||
case ice.CORE:
|
||||
m.Option(web.DOMAIN, m.Cmd(web.SPIDE, ice.DEV).Append(web.CLIENT_ORIGIN))
|
||||
case nfs.SOURCE, "dev":
|
||||
case nfs.SOURCE, ice.DEV:
|
||||
m.Options(nfs.SOURCE, ice.Info.Make.Remote)
|
||||
case nfs.BINARY, "app":
|
||||
case nfs.BINARY, ice.APP:
|
||||
case "curl", "wget":
|
||||
case "manual":
|
||||
m.Options(nfs.BINARY, "ice.linux.amd64")
|
||||
|
@ -31,7 +31,7 @@ func init() {
|
||||
}},
|
||||
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { ProcessXterm(m, PYTHON+" -i "+path.Join(arg[2], arg[1]), "") }},
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { _py_exec(m, path.Join(arg[2], arg[1])) }},
|
||||
TEMPLATE: {Hand: func(m *ice.Message, arg ...string) { m.Echo(nfs.Template(m, "demo.py")) }},
|
||||
TEMPLATE: {Hand: func(m *ice.Message, arg ...string) { m.Echo(nfs.Template(m, DEMO_PY)) }},
|
||||
}, PlugAction())},
|
||||
})
|
||||
}
|
||||
|
@ -2,13 +2,18 @@ package code
|
||||
|
||||
import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/web"
|
||||
)
|
||||
|
||||
const (
|
||||
GIT = "git"
|
||||
GIT = "git"
|
||||
REMOTE = "remote"
|
||||
REMOTE_URL = "remoteURL"
|
||||
INIT = "init"
|
||||
ADD = "add"
|
||||
)
|
||||
const REPOS = nfs.REPOS
|
||||
|
||||
@ -19,3 +24,4 @@ func init() {
|
||||
}, Hand: func(m *ice.Message, arg ...string) { m.Cmdy(web.CODE_GIT_REPOS, arg) }},
|
||||
})
|
||||
}
|
||||
func GitVersion(m *ice.Message) string { return m.Cmdx(cli.SYSTEM, GIT, VERSION) }
|
||||
|
@ -41,8 +41,8 @@ func init() {
|
||||
cmds, text := _sh_cmds(m, path.Join(arg[2], arg[1]))
|
||||
m.Cmdy(cli.SYSTEM, cmds, "-c", text).Status(ssh.SHELL, strings.ReplaceAll(text, lex.NL, "; "))
|
||||
}},
|
||||
TEMPLATE: {Hand: func(m *ice.Message, arg ...string) { m.Echo(nfs.Template(m, "demo.sh")) }},
|
||||
NAVIGATE: {Hand: func(m *ice.Message, arg ...string) { _c_tags(m, "ctags", "-a", "-R", nfs.PWD) }},
|
||||
TEMPLATE: {Hand: func(m *ice.Message, arg ...string) { m.Echo(nfs.Template(m, DEMO_SH)) }},
|
||||
NAVIGATE: {Hand: func(m *ice.Message, arg ...string) { _c_tags(m, CTAGS, "-a", "-R", nfs.PWD) }},
|
||||
}, PlugAction())},
|
||||
})
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ func init() {
|
||||
}},
|
||||
TEMPLATE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Option(mdb.NAME, path.Base(path.Dir(path.Join(arg[2], arg[1]))))
|
||||
m.Echo(nfs.Template(m, "demo.shy"))
|
||||
m.Echo(nfs.Template(m, DEMO_SHY))
|
||||
}},
|
||||
COMPLETE: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(web.WIKI_WORD, COMPLETE, arg) }},
|
||||
}, PlugAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
|
@ -41,6 +41,17 @@ func _vimer_make(m *ice.Message, dir string, msg *ice.Message) {
|
||||
}
|
||||
|
||||
const (
|
||||
DEMO_C = "demo.c"
|
||||
DEMO_SH = "demo.sh"
|
||||
DEMO_SHY = "demo.shy"
|
||||
DEMO_PY = "demo.py"
|
||||
DEMO_GO = "demo.go"
|
||||
DEMO_JS = "demo.js"
|
||||
DEMO_CSS = "demo.css"
|
||||
DEMO_HTML = "demo.html"
|
||||
MAIN_GO = "main.go"
|
||||
MAIN_JS = "main.js"
|
||||
|
||||
VIMER_SAVE = "vimer.save"
|
||||
)
|
||||
const VIMER = "vimer"
|
||||
@ -138,7 +149,7 @@ func init() {
|
||||
web.PushStream(m)
|
||||
m.Cmd(cli.SYSTEM, "echo")
|
||||
m.Cmd(cli.SYSTEM, "date")
|
||||
m.Cmd(cli.SYSTEM, cli.MAKE, m.Option("target"), kit.Dict(cli.CMD_DIR, m.Option(nfs.PATH)))
|
||||
m.Cmd(cli.SYSTEM, cli.MAKE, m.Option(nfs.TARGET), kit.Dict(cli.CMD_DIR, m.Option(nfs.PATH)))
|
||||
}},
|
||||
COMPILE: {Help: "编译", Hand: func(m *ice.Message, arg ...string) {
|
||||
if m.Option(nfs.PATH) != "" && nfs.ExistsFile(m, path.Join(m.Option(nfs.PATH), ice.MAKEFILE)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user