mirror of
https://shylinux.com/x/icebergs
synced 2025-04-26 01:24:05 +08:00
opt code
This commit is contained in:
parent
30fdb259c6
commit
20e53d3885
@ -39,18 +39,21 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
var _release = ""
|
||||
func release(m *ice.Message) string {
|
||||
osid := runtime.GOOS
|
||||
if osid != "linux" {
|
||||
return osid
|
||||
}
|
||||
m.Cmd(nfs.CAT, "/etc/os-release", kit.Dict(ice.MSG_USERROLE, aaa.ROOT), func(text string) {
|
||||
m.Option(nfs.CAT_CONTENT, _release)
|
||||
_release = m.Cmdx(nfs.CAT, "/etc/os-release", kit.Dict(ice.MSG_USERROLE, aaa.ROOT), func(text string, _ int) string {
|
||||
if ls := kit.Split(text, ice.EQ); len(ls) > 1 {
|
||||
switch ls[0] {
|
||||
case "ID", "ID_LIKE":
|
||||
osid = strings.TrimSpace(ls[1] + ice.SP + osid)
|
||||
}
|
||||
}
|
||||
return text
|
||||
})
|
||||
return osid
|
||||
}
|
||||
@ -68,3 +71,4 @@ func insert(m *ice.Message, sys, cmd string, arg ...string) bool {
|
||||
func IsAlpine(m *ice.Message, arg ...string) bool { return insert(m, ALPINE, "system apk add", arg...) }
|
||||
func IsCentos(m *ice.Message, arg ...string) bool { return insert(m, CENTOS, "yum install -y", arg...) }
|
||||
func IsUbuntu(m *ice.Message, arg ...string) bool { return insert(m, UBUNTU, "apt get -y", arg...) }
|
||||
func IsSystem(m *ice.Message, arg ...string) bool { return IsAlpine(m, arg...) || IsCentos(m, arg...) || IsUbuntu(m, arg...) }
|
||||
|
@ -99,6 +99,7 @@ func init() {
|
||||
ice.Index.Register(Index, &Frame{}, BROAD, SERVE, SPACE, DREAM, SHARE, CACHE, SPIDE)
|
||||
}
|
||||
func ApiAction(arg ...string) ice.Actions { return ice.Actions{kit.Select(ice.PS, arg, 0): {}} }
|
||||
func Prefix(arg ...string) string { return kit.Keys(WEB, arg) }
|
||||
|
||||
func P(arg ...string) string { return path.Join(ice.PS, path.Join(arg...)) }
|
||||
func PP(arg ...string) string { return P(arg...) + ice.PS }
|
||||
|
@ -59,6 +59,7 @@ func _autogen_version(m *ice.Message) {
|
||||
}
|
||||
m.Cmd(nfs.DEFS, ice.SRC_BINPACK_GO, `package main`+ice.NL)
|
||||
m.Cmd(nfs.SAVE, ice.SRC_VERSION_GO, kit.Format(_version_template, _autogen_gits(m, nfs.MODULE, _autogen_mod(m, ice.GO_MOD), tcp.HOSTNAME, ice.Info.Hostname, aaa.USERNAME, ice.Info.Username)))
|
||||
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)
|
||||
|
@ -20,7 +20,7 @@ func _bench_http(m *ice.Message, target string, arg ...string) {
|
||||
list := []*http.Request{}
|
||||
for _, v := range strings.Split(target, ice.NL) {
|
||||
switch ls := kit.Split(v); ls[0] {
|
||||
case http.MethodPost: // POST,url,file
|
||||
case http.MethodPost:
|
||||
if f, e := nfs.OpenFile(m, ls[2]); m.Assert(e) {
|
||||
defer f.Close()
|
||||
if req, err := http.NewRequest(http.MethodPost, ls[1], f); m.Assert(err) {
|
||||
|
@ -2,7 +2,6 @@ package code
|
||||
|
||||
import (
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
@ -13,51 +12,47 @@ import (
|
||||
|
||||
func _c_show(m *ice.Message, arg ...string) { TagsList(m) }
|
||||
func _c_exec(m *ice.Message, arg ...string) {
|
||||
name := strings.TrimSuffix(arg[1], path.Ext(arg[1])) + ".bin"
|
||||
if msg := m.Cmd(cli.SYSTEM, "gcc", "-o", name, arg[1], kit.Dict(cli.CMD_DIR, arg[2])); !cli.IsSuccess(msg) {
|
||||
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) {
|
||||
m.Cmdy(cli.SYSTEM, target).StatusTime(nfs.PATH, target)
|
||||
} else {
|
||||
_vimer_make(m, arg[2], msg)
|
||||
return
|
||||
}
|
||||
if m.Cmdy(cli.SYSTEM, path.Join(arg[2], name)); m.Append(cli.CMD_ERR) == "" {
|
||||
m.Result(m.Append(cli.CMD_OUT))
|
||||
m.SetAppend()
|
||||
}
|
||||
m.StatusTime()
|
||||
}
|
||||
func _c_tags(m *ice.Message, man string, cmd ...string) {
|
||||
if !nfs.ExistsFile(m, path.Join(m.Option(nfs.PATH), nfs.TAGS)) {
|
||||
m.Cmd(cli.SYSTEM, cmd, kit.Dict(cli.CMD_DIR, m.Option(nfs.PATH)))
|
||||
}
|
||||
if _inner_tags(m, m.Option(nfs.PATH), m.Option(mdb.NAME)); !cli.IsSuccess(m) || m.Length() == 0 {
|
||||
m.Push(nfs.FILE, kit.Keys(m.Option(mdb.NAME), man))
|
||||
m.Push(nfs.LINE, "1")
|
||||
m.Push(nfs.FILE, kit.Keys(m.Option(mdb.NAME), man)).Push(nfs.LINE, "1")
|
||||
}
|
||||
}
|
||||
|
||||
const MAN = "man"
|
||||
const H = "h"
|
||||
const C = "c"
|
||||
const MAN = "man"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
C: {Name: "c path auto", Help: "系统", Actions: ice.MergeActions(ice.Actions{
|
||||
MAN: {Name: MAN, Help: "系统手册", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { m.Cmd(cli.SYSTEM, cli.MAN, kit.TrimExt(arg[1], arg[0])) }},
|
||||
}, PlugAction())},
|
||||
H: {Name: "h path auto", Help: "系统编程", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { _c_show(m, arg...) }},
|
||||
NAVIGATE: {Hand: func(m *ice.Message, arg ...string) { _c_tags(m, MAN, "ctags", "-a", "-R", nfs.PWD) }},
|
||||
}, PlugAction(), LangAction())},
|
||||
C: {Name: "c 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) { _c_exec(m, arg...) }},
|
||||
NAVIGATE: {Hand: func(m *ice.Message, arg ...string) { _c_tags(m, MAN, "ctags", "-a", "-R", nfs.PWD) }},
|
||||
TEMPLATE: {Hand: func(m *ice.Message, arg ...string) { kit.IfElse(arg[0] == C, func() { m.Echo(_c_template) }) }},
|
||||
}, PlugAction(), LangAction())},
|
||||
H: {Name: "h path auto", Help: "系统", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { _c_show(m, arg...) }},
|
||||
NAVIGATE: {Hand: func(m *ice.Message, arg ...string) { _c_tags(m, MAN, "ctags", "-a", "-R", nfs.PWD) }},
|
||||
}, PlugAction(), LangAction())},
|
||||
MAN: {Name: MAN, Help: "手册", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 1 {
|
||||
arg = append(arg, "")
|
||||
}
|
||||
key := kit.TrimExt(arg[1], arg[0])
|
||||
m.Option(cli.CMD_ENV, "COLUMNS", kit.Int(kit.Select("1920", m.Option("width")))/12)
|
||||
m.Echo(cli.SystemCmds(m, "man %s %s|col -b", "", key))
|
||||
}},
|
||||
}, PlugAction())},
|
||||
})
|
||||
}
|
||||
|
||||
var _c_template = `#include <stdio.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
printf("hello world\n");
|
||||
}
|
||||
`
|
||||
|
@ -27,4 +27,4 @@ func init() {
|
||||
)
|
||||
}
|
||||
|
||||
func Prefix(arg ...string) string { return kit.Keys(web.WEB, CODE, arg) }
|
||||
func Prefix(arg ...string) string { return web.Prefix(CODE, kit.Keys(arg)) }
|
||||
|
@ -3,13 +3,13 @@ package code
|
||||
import (
|
||||
"path"
|
||||
"runtime"
|
||||
"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"
|
||||
|
||||
// "shylinux.com/x/icebergs/base/web"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
@ -30,7 +30,7 @@ func _compile_target(m *ice.Message, arg ...string) (string, string, string, str
|
||||
}
|
||||
}
|
||||
if file == "" {
|
||||
file = path.Join(ice.USR_PUBLISH, kit.Keys(kit.Select(ice.ICE, kit.TrimExt(main), main != ice.SRC_MAIN_GO), goos, arch))
|
||||
file = path.Join(ice.USR_PUBLISH, kit.Keys(kit.Select(ice.ICE, kit.TrimExt(main, GO), main != ice.SRC_MAIN_GO), goos, arch))
|
||||
}
|
||||
return main, file, goos, arch
|
||||
}
|
||||
@ -41,49 +41,35 @@ const (
|
||||
const COMPILE = "compile"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{Configs: ice.Configs{
|
||||
COMPILE: {Value: kit.Data(cli.ENV, kit.Dict("GOPRIVATE", "shylinux.com,github.com", "GOPROXY", "https://goproxy.cn,direct", "CGO_ENABLED", "0"))},
|
||||
}, Commands: ice.Commands{
|
||||
COMPILE: {Name: "compile arch=amd64,386,mipsle,arm,arm64 os=linux,darwin,windows src=src/main.go@key run binpack relay", Help: "编译", Actions: ice.Actions{
|
||||
Index.MergeCommands(ice.Commands{
|
||||
COMPILE: {Name: "compile arch=amd64,386,mipsle,arm,arm64 os=linux,darwin,windows src=src/main.go@key run relay binpack", Help: "编译", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
cli.IsAlpine(m, "curl")
|
||||
cli.IsAlpine(m, "make")
|
||||
cli.IsAlpine(m, "gcc")
|
||||
cli.IsAlpine(m, "vim")
|
||||
cli.IsAlpine(m, "tmux")
|
||||
kit.Fetch([]string{"curl", "make", "gcc", "vim", "tmux"}, func(cmd string) { cli.IsSystem(m, cmd) })
|
||||
if cli.IsAlpine(m, "git"); !cli.IsAlpine(m, "go", "go git") {
|
||||
m.Cmd(mdb.INSERT, cli.CLI, "", mdb.ZONE, cli.CLI, "go", cli.CMD, kit.Format("install download https://golang.google.cn/dl/go1.15.5.%s-%s.tar.gz usr/local", runtime.GOOS, runtime.GOARCH))
|
||||
}
|
||||
}},
|
||||
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(nfs.DIR, ice.SRC, nfs.DIR_CLI_FIELDS, kit.Dict(nfs.DIR_REG, `.*\.go$`)).Sort(nfs.PATH)
|
||||
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)
|
||||
}},
|
||||
RELAY: {Help: "跳板", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(COMPILE, ice.SRC_RELAY_GO, path.Join(ice.USR_PUBLISH, RELAY))
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, arg ...string) {
|
||||
BINPACK: {Help: "打包", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(AUTOGEN, BINPACK) }},
|
||||
RELAY: {Help: "跳板", Hand: func(m *ice.Message, arg ...string) { m.Cmdy("", ice.SRC_RELAY_GO, path.Join(ice.USR_PUBLISH, RELAY)) }},
|
||||
}, 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())
|
||||
|
||||
// 执行编译
|
||||
// web.PushStream(m)
|
||||
main, file, goos, arch := _compile_target(m, arg...)
|
||||
m.Optionv(cli.CMD_ENV, kit.Simple(cli.HOME, kit.Env(cli.HOME), cli.PATH, kit.Env(cli.PATH), m.Configv(cli.ENV), m.Optionv(cli.ENV), cli.GOOS, goos, cli.GOARCH, arch))
|
||||
// m.Cmd(cli.SYSTEM, GO, "get", "shylinux.com/x/ice")
|
||||
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))
|
||||
if !strings.Contains(m.Cmdx(nfs.CAT, ice.GO_MOD), "shylinux.com/x/ice") {
|
||||
m.Cmd(cli.SYSTEM, GO, "get", "shylinux.com/x/ice")
|
||||
}
|
||||
if msg := m.Cmd(cli.SYSTEM, GO, cli.BUILD, "-o", file, main, ice.SRC_VERSION_GO, ice.SRC_BINPACK_GO); !cli.IsSuccess(msg) {
|
||||
m.Copy(msg)
|
||||
return
|
||||
}
|
||||
m.Option(cli.CMD_OUTPUT, "")
|
||||
|
||||
// 编译成功
|
||||
m.Logs(mdb.EXPORT, nfs.SOURCE, main, nfs.TARGET, file)
|
||||
m.Cmdy(nfs.DIR, file, nfs.DIR_WEB_FIELDS)
|
||||
m.Cmdy(PUBLISH, ice.CONTEXTS)
|
||||
m.StatusTimeCount()
|
||||
m.Process("")
|
||||
m.Cmdy(nfs.DIR, file, nfs.DIR_WEB_FIELDS).StatusTimeCount()
|
||||
if strings.Contains(file, ice.ICE) {
|
||||
m.Cmdy(PUBLISH, ice.CONTEXTS)
|
||||
}
|
||||
}},
|
||||
}})
|
||||
})
|
||||
}
|
||||
|
@ -11,27 +11,24 @@ import (
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _css_stat(m *ice.Message, block string, stats map[string]int) {
|
||||
func _css_stat(m *ice.Message, zone string, stats map[string]int) {
|
||||
msg := m.Spawn()
|
||||
for k, v := range stats {
|
||||
msg.Push("name", k)
|
||||
msg.Push("value", v)
|
||||
msg.Push("block", block)
|
||||
msg.Push(mdb.NAME, k).Push(mdb.VALUE, v).Push(mdb.ZONE, zone)
|
||||
}
|
||||
msg.SortIntR("value")
|
||||
msg.SortIntR(mdb.VALUE)
|
||||
m.Copy(msg)
|
||||
}
|
||||
func _css_show(m *ice.Message, arg ...string) {
|
||||
// block := ""
|
||||
stats_key := map[string]int{}
|
||||
stats_value := map[string]int{}
|
||||
zone := ""
|
||||
stats_key, stats_value := map[string]int{}, map[string]int{}
|
||||
m.Cmd(nfs.CAT, path.Join(arg[2], arg[1]), func(line string) {
|
||||
if line = strings.TrimSpace(line); line == "" || strings.HasPrefix(line, "//") || strings.HasPrefix(line, "/*") {
|
||||
return
|
||||
}
|
||||
switch {
|
||||
case strings.HasSuffix(line, "{"):
|
||||
// block = strings.TrimSuffix(line, "{")
|
||||
zone = strings.TrimSuffix(line, "{")
|
||||
case strings.HasSuffix(line, "}"):
|
||||
if line == "}" {
|
||||
break
|
||||
@ -42,13 +39,17 @@ func _css_show(m *ice.Message, arg ...string) {
|
||||
if len(list) < 2 {
|
||||
continue
|
||||
}
|
||||
m.Push("name", list[0])
|
||||
m.Push("value", list[1])
|
||||
m.Push("block", ls[0])
|
||||
m.Push(mdb.NAME, list[0])
|
||||
m.Push(mdb.VALUE, list[1])
|
||||
m.Push(mdb.ZONE, ls[0])
|
||||
stats_key[list[0]]++
|
||||
stats_value[list[1]]++
|
||||
}
|
||||
default:
|
||||
list := kit.Split(line, "", ":;")
|
||||
m.Push(mdb.NAME, list[0])
|
||||
m.Push(mdb.VALUE, list[1])
|
||||
m.Push(mdb.ZONE, zone)
|
||||
}
|
||||
})
|
||||
_css_stat(m, "stats.key", stats_key)
|
||||
@ -56,8 +57,8 @@ func _css_show(m *ice.Message, arg ...string) {
|
||||
m.StatusTimeCount()
|
||||
}
|
||||
func _css_exec(m *ice.Message, arg ...string) {
|
||||
if arg[2] == "usr/volcanos/" && strings.HasPrefix(arg[1], "plugin/local/") {
|
||||
key := "web." + strings.ReplaceAll(strings.TrimSuffix(strings.TrimPrefix(arg[1], "plugin/local/"), ".css"), ice.PS, ice.PT)
|
||||
if arg[2] == ice.USR_VOLCANOS && strings.HasPrefix(arg[1], ice.PLUGIN_LOCAL) {
|
||||
key := ctx.GetFileCmd("/require/shylinux.com/x/icebergs/core/"+strings.TrimPrefix(arg[1], ice.PLUGIN_LOCAL))
|
||||
ctx.ProcessCommand(m, kit.Select("can.plugin", key), kit.Simple())
|
||||
return
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package code
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
@ -14,25 +16,22 @@ const FAVOR = "favor"
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
FAVOR: {Name: "favor zone id auto insert page", Help: "收藏夹", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.INSERT: {Name: "insert zone=数据结构 type=go name=hi text=hello path file line", Help: "添加"},
|
||||
XTERM: {Name: "xterm", Help: "终端", Hand: func(m *ice.Message, arg ...string) {
|
||||
ctx.Process(m, m.ActionKey(), m.OptionSimple(mdb.TYPE, mdb.NAME, mdb.TEXT), arg...)
|
||||
mdb.INSERT: {Name: "insert zone*=数据结构 type=go name*=hi text*=hello path file line"},
|
||||
XTERM: {Help: "终端", Hand: func(m *ice.Message, arg ...string) {
|
||||
if msg := mdb.ZoneSelects(m.Spawn(), m.Option(mdb.ZONE), m.Option(mdb.ID)); strings.HasPrefix(msg.Option(mdb.TYPE), cli.OPEN) {
|
||||
m.Cmdy(cli.SYSTEM, m.Option(mdb.TYPE)).ProcessHold()
|
||||
} else {
|
||||
ctx.Process(m, m.ActionKey(), msg.OptionSimple(mdb.TYPE, mdb.NAME, mdb.TEXT), arg...)
|
||||
}
|
||||
}},
|
||||
INNER: {Name: "inner", Help: "源码", Hand: func(m *ice.Message, arg ...string) {
|
||||
ctx.Process(m, m.ActionKey(), m.OptionSplit(nfs.PATH, nfs.FILE, nfs.LINE), arg...)
|
||||
INNER: {Help: "源码", Hand: func(m *ice.Message, arg ...string) {
|
||||
msg := mdb.ZoneSelects(m, m.Option(mdb.ZONE), m.Option(mdb.ID))
|
||||
ctx.Process(m, m.ActionKey(), msg.OptionSplit(nfs.PATH, nfs.FILE, nfs.LINE), arg...)
|
||||
}},
|
||||
"click": {Name: "click", Help: "应用", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(cli.DAEMON, m.Option(mdb.TYPE))
|
||||
}},
|
||||
}, mdb.ZoneAction(mdb.SHORT, mdb.ZONE, mdb.FIELD, "time,id,type,name,text,path,file,line")), Hand: func(m *ice.Message, arg ...string) {
|
||||
}, mdb.PageZoneAction(mdb.FIELD, "time,id,type,name,text,path,file,line"), ctx.CmdAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Option(mdb.CACHE_LIMIT, "30")
|
||||
if mdb.PageZoneSelect(m, arg...); len(arg) > 0 && arg[0] != "" {
|
||||
if arg[0] == "_recent_file" {
|
||||
m.Sort(nfs.FILE)
|
||||
}
|
||||
m.Tables(func(value ice.Maps) {
|
||||
m.PushButton(kit.Select(INNER, XTERM, value[mdb.TEXT] == "" || value[nfs.FILE] == ""))
|
||||
}).Option(ctx.STYLE, arg[0])
|
||||
m.Tables(func(value ice.Maps) { m.PushButton(kit.Select(INNER, XTERM, value[nfs.FILE] == "")) }).Option(ctx.STYLE, arg[0])
|
||||
}
|
||||
}},
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user