mirror of
https://shylinux.com/x/icebergs
synced 2025-05-01 03:09:21 +08:00
opt some
This commit is contained in:
parent
3dfc379d69
commit
280c00ccbd
@ -1,16 +1,16 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
)
|
||||
|
||||
func _system_show(m *ice.Message, cmd *exec.Cmd) {
|
||||
@ -81,6 +81,11 @@ const (
|
||||
CMD_CODE = "cmd_code"
|
||||
)
|
||||
|
||||
const (
|
||||
LINUX = "linux"
|
||||
DARWIN = "darwin"
|
||||
WINDOWS = "windows"
|
||||
)
|
||||
const SYSTEM = "system"
|
||||
|
||||
func init() {
|
||||
|
@ -17,19 +17,15 @@ import (
|
||||
)
|
||||
|
||||
type Buffer struct {
|
||||
data []byte
|
||||
m *ice.Message
|
||||
n string
|
||||
}
|
||||
|
||||
func (b *Buffer) Write(buf []byte) (int, error) {
|
||||
b.data = append(b.data, buf...)
|
||||
b.m.Cmd(web.SPACE, b.n, "grow", string(buf))
|
||||
return len(buf), nil
|
||||
}
|
||||
func (b *Buffer) Close() error {
|
||||
return nil
|
||||
}
|
||||
func (b *Buffer) Close() error { return nil }
|
||||
|
||||
const PREPARE = "prepare"
|
||||
const INSTALL = "install"
|
||||
@ -37,9 +33,7 @@ const INSTALL = "install"
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{
|
||||
Configs: map[string]*ice.Config{
|
||||
INSTALL: {Name: INSTALL, Help: "安装", Value: kit.Data(
|
||||
kit.MDB_SHORT, kit.MDB_NAME, kit.MDB_PATH, ice.USR_INSTALL,
|
||||
)},
|
||||
INSTALL: {Name: INSTALL, Help: "安装", Value: kit.Data(kit.MDB_SHORT, kit.MDB_NAME, kit.MDB_PATH, ice.USR_INSTALL)},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
INSTALL: {Name: "install name port path auto download", Help: "安装", Meta: kit.Dict(), Action: map[string]*ice.Action{
|
||||
@ -53,7 +47,7 @@ func init() {
|
||||
return // 文件存在
|
||||
}
|
||||
|
||||
// 文件占位
|
||||
// 创建文件
|
||||
m.Cmd(nfs.SAVE, file, "")
|
||||
|
||||
m.GoToast("download", func(toast func(string, int, int)) {
|
||||
@ -73,25 +67,25 @@ func init() {
|
||||
})
|
||||
|
||||
// 下载
|
||||
os.MkdirAll(m.Option(cli.CMD_DIR, m.Conf(INSTALL, kit.META_PATH)), ice.MOD_DIR)
|
||||
msg := m.Cmd(web.SPIDE, web.SPIDE_DEV, web.SPIDE_CACHE, web.SPIDE_GET, link)
|
||||
m.Cmd(nfs.LINK, file, msg.Append(kit.MDB_FILE))
|
||||
|
||||
// 解压
|
||||
m.Cmdy(nfs.LINK, file, msg.Append(kit.MDB_FILE))
|
||||
m.Option(cli.CMD_DIR, path.Dir(file))
|
||||
m.Cmd(cli.SYSTEM, "tar", "xvf", name)
|
||||
})
|
||||
}},
|
||||
gdb.BUILD: {Name: "build link", Help: "构建", Hand: func(m *ice.Message, arg ...string) {
|
||||
|
||||
m.Option(cli.CMD_OUTPUT, &Buffer{m: m, n: m.Option(ice.MSG_DAEMON)})
|
||||
defer func() {
|
||||
m.Toast("success", "build")
|
||||
m.ProcessHold()
|
||||
}()
|
||||
|
||||
p := m.Option(cli.CMD_DIR, path.Join(m.Conf(INSTALL, kit.META_PATH), kit.TrimExt(m.Option(kit.MDB_LINK))))
|
||||
pp := kit.Path(path.Join(p, "_install"))
|
||||
switch cb := m.Optionv("prepare").(type) {
|
||||
|
||||
// 推流
|
||||
m.Option(cli.CMD_OUTPUT, &Buffer{m: m, n: m.Option(ice.MSG_DAEMON)})
|
||||
defer func() { m.Toast("success", "build") }()
|
||||
defer func() { m.ProcessHold() }()
|
||||
|
||||
// 配置
|
||||
switch cb := m.Optionv(PREPARE).(type) {
|
||||
case func(string):
|
||||
cb(p)
|
||||
default:
|
||||
@ -100,10 +94,12 @@ func init() {
|
||||
}
|
||||
}
|
||||
|
||||
if m.Cmd(cli.SYSTEM, "make", "-j8"); m.Append(cli.CMD_CODE) != "0" {
|
||||
// 编译
|
||||
if m.Cmd(cli.SYSTEM, "make", "-j8").Append(cli.CMD_CODE) != "0" {
|
||||
return
|
||||
}
|
||||
|
||||
// 安装
|
||||
m.Cmd(cli.SYSTEM, "make", "PREFIX="+pp, "install")
|
||||
}},
|
||||
gdb.SPAWN: {Name: "spawn link", Help: "新建", Hand: func(m *ice.Message, arg ...string) {
|
||||
@ -120,7 +116,7 @@ func init() {
|
||||
p := m.Option(cli.CMD_DIR, m.Cmdx(INSTALL, gdb.SPAWN))
|
||||
|
||||
args := []string{}
|
||||
switch cb := m.Optionv("prepare").(type) {
|
||||
switch cb := m.Optionv(PREPARE).(type) {
|
||||
case func(string) []string:
|
||||
args = append(args, cb(p)...)
|
||||
}
|
||||
@ -128,36 +124,32 @@ func init() {
|
||||
m.Cmdy(cli.DAEMON, arg[1:], args)
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
// 源码列表
|
||||
m.Option(mdb.FIELDS, m.Conf(INSTALL, kit.META_FIELD))
|
||||
if len(arg) == 0 { // 源码列表
|
||||
m.Fields(len(arg) == 0, "time,name,path")
|
||||
m.Cmdy(mdb.SELECT, INSTALL, "", mdb.HASH)
|
||||
return
|
||||
}
|
||||
|
||||
if len(arg) == 1 {
|
||||
// 服务列表
|
||||
arg = kit.Split(path.Base(arg[0]), "-.")
|
||||
m.Option(mdb.FIELDS, "time,port,status,pid,cmd,dir")
|
||||
if len(arg) == 1 { // 服务列表
|
||||
arg = kit.Split(path.Base(arg[0]), "-.")[:1]
|
||||
|
||||
m.Fields(len(arg) == 1, "time,port,status,pid,cmd,dir")
|
||||
m.Cmd(mdb.SELECT, cli.DAEMON, "", mdb.HASH).Table(func(index int, value map[string]string, head []string) {
|
||||
if strings.Contains(value["cmd"], "bin/"+arg[0]) {
|
||||
if strings.Contains(value[cli.CMD], "bin/"+arg[0]) {
|
||||
m.Push("", value, kit.Split(m.Option(mdb.FIELDS)))
|
||||
}
|
||||
})
|
||||
m.Appendv(kit.SSH_PORT, []string{})
|
||||
|
||||
m.Appendv(tcp.PORT, []string{})
|
||||
m.Table(func(index int, value map[string]string, head []string) {
|
||||
m.Push(kit.SSH_PORT, path.Base(value[kit.SSH_DIR]))
|
||||
m.Push(tcp.PORT, path.Base(value[nfs.DIR]))
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 目录列表
|
||||
m.Option(nfs.DIR_ROOT, path.Join(m.Conf(cli.DAEMON, kit.META_PATH), arg[1]))
|
||||
if strings.HasSuffix(kit.Select("./", arg, 2), "/") {
|
||||
m.Cmdy(nfs.DIR, kit.Select("./", arg, 2))
|
||||
} else {
|
||||
m.Cmdy(nfs.CAT, kit.Select("./", arg, 2))
|
||||
}
|
||||
}},
|
||||
},
|
||||
})
|
||||
|
@ -40,15 +40,7 @@ func _wiki_save(m *ice.Message, cmd, name, text string, arg ...string) {
|
||||
m.Cmd(nfs.SAVE, name, text)
|
||||
}
|
||||
func _wiki_upload(m *ice.Message, cmd string, dir string) {
|
||||
up := kit.Simple(m.Optionv(ice.MSG_UPLOAD))
|
||||
if p := _wiki_path(m, cmd, dir, up[1]); m.Option(ice.MSG_USERPOD) == "" {
|
||||
// 本机文件
|
||||
m.Cmdy(web.CACHE, web.WATCH, up[0], p)
|
||||
} else {
|
||||
// 下发文件
|
||||
m.Cmdy(web.SPIDE, web.SPIDE_DEV, web.SPIDE_SAVE, p, web.SPIDE_GET,
|
||||
kit.MergeURL2(m.Option(ice.MSG_USERWEB), path.Join("/share/cache", up[0])))
|
||||
}
|
||||
m.Upload(_wiki_path(m, cmd, dir))
|
||||
}
|
||||
|
||||
const WIKI = "wiki"
|
||||
|
@ -1,6 +1,11 @@
|
||||
package wiki
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/cli"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
@ -8,11 +13,6 @@ import (
|
||||
"github.com/shylinux/icebergs/base/ssh"
|
||||
"github.com/shylinux/icebergs/base/web"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
|
||||
"fmt"
|
||||
"net/url"
|
||||
"path"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func _name(m *ice.Message, arg []string) []string {
|
||||
@ -453,6 +453,7 @@ func init() {
|
||||
m.Cmdy(arg[0], kit.MDB_ACTION, "run", arg[1:])
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Option(nfs.DIR_REG, m.Conf(WORD, kit.Keym(kit.MDB_REGEXP)))
|
||||
if m.Option(nfs.DIR_DEEP, "true"); _wiki_list(m, cmd, arg...) {
|
||||
return
|
||||
}
|
||||
|
39
misc.go
39
misc.go
@ -295,20 +295,6 @@ func (m *Message) Fields(condition bool, fields string) string {
|
||||
func (m *Message) Action(arg ...string) {
|
||||
m.Option(MSG_ACTION, kit.Format(arg))
|
||||
}
|
||||
func (m *Message) Process(action string, arg ...interface{}) {
|
||||
m.Option(MSG_PROCESS, action)
|
||||
m.Option("_arg", arg...)
|
||||
}
|
||||
func (m *Message) ProcessHold() { m.Process(PROCESS_HOLD) }
|
||||
func (m *Message) ProcessBack() { m.Process(PROCESS_BACK) }
|
||||
|
||||
func (m *Message) ProcessRefresh(delay string) {
|
||||
if d, e := time.ParseDuration(delay); e == nil {
|
||||
m.Option("_delay", int(d/time.Millisecond))
|
||||
}
|
||||
m.Process(PROCESS_REFRESH)
|
||||
}
|
||||
|
||||
func (m *Message) Status(arg ...interface{}) {
|
||||
args := kit.Simple(arg)
|
||||
list := []map[string]string{}
|
||||
@ -319,3 +305,28 @@ func (m *Message) Status(arg ...interface{}) {
|
||||
}
|
||||
m.Option(MSG_STATUS, kit.Format(list))
|
||||
}
|
||||
|
||||
func (m *Message) Process(action string, arg ...interface{}) {
|
||||
m.Option(MSG_PROCESS, action)
|
||||
m.Option("_arg", arg...)
|
||||
}
|
||||
func (m *Message) ProcessRefresh(delay string) {
|
||||
if d, e := time.ParseDuration(delay); e == nil {
|
||||
m.Option("_delay", int(d/time.Millisecond))
|
||||
}
|
||||
m.Process(PROCESS_REFRESH)
|
||||
}
|
||||
func (m *Message) ProcessHold() { m.Process(PROCESS_HOLD) }
|
||||
func (m *Message) ProcessBack() { m.Process(PROCESS_BACK) }
|
||||
|
||||
func (m *Message) Upload(dir string) {
|
||||
up := kit.Simple(m.Optionv(MSG_UPLOAD))
|
||||
if p := path.Join(dir, up[1]); m.Option(MSG_USERPOD) == "" {
|
||||
// 本机文件
|
||||
m.Cmdy("web.cache", "watch", up[0], p)
|
||||
} else {
|
||||
// 下拉文件
|
||||
m.Cmdy("web.spide", "dev", "save", p, "GET",
|
||||
kit.MergeURL2(m.Option(MSG_USERWEB), path.Join("/share/cache", up[0])))
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user