From 7a72e0cd729d479c008ed11bb957a6a0cca66cf8 Mon Sep 17 00:00:00 2001 From: shylinux Date: Tue, 12 Oct 2021 15:53:40 +0800 Subject: [PATCH] opt some --- core/chat/river.go | 2 +- core/code/autogen.go | 13 +++++++------ core/code/binpack.go | 14 +++++++++++++- core/code/publish.go | 6 +----- init.go | 19 +++++++------------ 5 files changed, 29 insertions(+), 25 deletions(-) diff --git a/core/chat/river.go b/core/chat/river.go index 04a93126..2de373c0 100644 --- a/core/chat/river.go +++ b/core/chat/river.go @@ -180,7 +180,7 @@ func init() { m.Cmd(code.PUBLISH, mdb.CREATE, kit.MDB_FILE, ice.BIN_ICE_SH) m.Cmd(code.PUBLISH, mdb.CREATE, kit.MDB_FILE, ice.BIN_ICE_BIN) }}, - cli.START: {Name: "start name repos template", Help: "启动", Hand: func(m *ice.Message, arg ...string) { + cli.START: {Name: "start name=hi repos template", Help: "启动", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(m.Space(m.Option(cli.POD)), web.DREAM, cli.START, arg) }}, diff --git a/core/code/autogen.go b/core/code/autogen.go index 409f20d4..5ebe4a85 100644 --- a/core/code/autogen.go +++ b/core/code/autogen.go @@ -9,6 +9,7 @@ import ( "shylinux.com/x/icebergs/base/cli" "shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/nfs" + "shylinux.com/x/icebergs/base/ssh" "shylinux.com/x/icebergs/base/web" kit "shylinux.com/x/toolkits" ) @@ -52,11 +53,6 @@ func init() { ice.Cmd("{{.Option "key"}}", {{.Option "name"}}{}) } m.Cmd(nfs.SAVE, dir, string(buf)) } func _autogen_import(m *ice.Message, main string, ctx string, mod string) (list []string) { - m.Cmd(nfs.DEFS, ice.GO_MOD, kit.Format(`module %s - -go 1.11 -`, path.Base(kit.Path("")))) - m.Cmd(nfs.DEFS, main, `package main import "shylinux.com/x/ice" @@ -82,6 +78,11 @@ func main() { print(ice.Run()) } return } func _autogen_mod(m *ice.Message, file string) (mod string) { + m.Cmd(nfs.DEFS, ice.GO_MOD, kit.Format(`module %s + +go 1.11 +`, path.Base(kit.Path("")))) + m.Cmd(nfs.CAT, file, func(line string, index int) { if strings.HasPrefix(line, "module") { mod = strings.Split(line, " ")[1] @@ -178,7 +179,7 @@ func init() { _autogen_version(m) m.Cmd(BINPACK, mdb.CREATE) }}, - "script": {Name: "script", Help: "脚本:生成 etc/miss.sh", Hand: func(m *ice.Message, arg ...string) { + ssh.SCRIPT: {Name: "script", Help: "脚本:生成 etc/miss.sh", Hand: func(m *ice.Message, arg ...string) { _autogen_miss(m) }}, }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { diff --git a/core/code/binpack.go b/core/code/binpack.go index 2c0b2afc..3a99f209 100644 --- a/core/code/binpack.go +++ b/core/code/binpack.go @@ -80,7 +80,7 @@ const BINPACK = "binpack" func init() { Index.Merge(&ice.Context{Commands: map[string]*ice.Command{ - BINPACK: {Name: "binpack path auto create", Help: "打包", Action: map[string]*ice.Action{ + BINPACK: {Name: "binpack path auto create remove export", Help: "打包", Action: map[string]*ice.Action{ mdb.CREATE: {Name: "create", Help: "创建", Hand: func(m *ice.Message, arg ...string) { if pack, p, e := kit.Create(ice.SRC_BINPACK); m.Assert(e) { defer pack.Close() @@ -107,6 +107,18 @@ func init() { m.Echo(p) } }}, + mdb.REMOVE: {Name: "remove", Help: "删除", Hand: func(m *ice.Message, arg ...string) { + ice.Info.BinPack = map[string][]byte{} + }}, + mdb.EXPORT: {Name: "export", Help: "导出", Hand: func(m *ice.Message, arg ...string) { + for key, value := range ice.Info.BinPack { + if strings.HasPrefix(key, "/") { + key = ice.USR_VOLCANOS + key + } + m.Warn(os.MkdirAll(path.Dir(key), ice.MOD_DIR) != nil, "key: ", key) + m.Warn(ioutil.WriteFile(key, value, ice.MOD_FILE) != nil, "key: ", key) + } + }}, }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { for k, v := range ice.Info.BinPack { m.Push(kit.MDB_NAME, k) diff --git a/core/code/publish.go b/core/code/publish.go index 8a75795d..35da42f1 100644 --- a/core/code/publish.go +++ b/core/code/publish.go @@ -149,11 +149,7 @@ func init() { SH, `#!/bin/bash echo "hello world" `, - JS, `Volcanos("onengine", {_init: function(can, sub) { - can.misc.Log("hello volcanos world") -}, river: { - -}}) + JS, `Volcanos("onengine", {}) `, )}, }}) diff --git a/init.go b/init.go index b9e5484a..76bd33fb 100644 --- a/init.go +++ b/init.go @@ -158,19 +158,14 @@ var Info = struct { } func Dump(w io.Writer, name string, cb func(string)) bool { - if b, ok := Info.BinPack[name]; ok { - if cb != nil { - cb(name) + for _, key := range []string{name, strings.TrimPrefix(name, USR_VOLCANOS)} { + if b, ok := Info.BinPack[key]; ok { + if cb != nil { + cb(name) + } + w.Write(b) + return true } - w.Write(b) - return true - } - if b, ok := Info.BinPack[strings.TrimPrefix(name, USR_VOLCANOS)]; ok { - if cb != nil { - cb(name) - } - w.Write(b) - return true } return false }