mirror of
https://shylinux.com/x/icebergs
synced 2025-04-26 01:24:05 +08:00
opt cmd.go
This commit is contained in:
parent
4dd4590e69
commit
87daa0cf53
@ -15,4 +15,4 @@ var Index = &ice.Context{Name: CTX, Help: "标准模块", Commands: map[string]*
|
||||
}},
|
||||
}}
|
||||
|
||||
func init() { ice.Index.Register(Index, nil, CONTEXT, COMMAND, CONFIG) }
|
||||
func init() { ice.Index.Register(Index, nil, CONTEXT, COMMAND, CONFIG, MESSAGE) }
|
||||
|
25
base/ctx/message.go
Normal file
25
base/ctx/message.go
Normal file
@ -0,0 +1,25 @@
|
||||
package ctx
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
const MESSAGE = "message"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
|
||||
MESSAGE: {Name: "message", Help: "消息", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
t := reflect.TypeOf(m)
|
||||
for i := 0; i < t.NumMethod(); i++ {
|
||||
method := t.Method(i)
|
||||
p := kit.FileLine(method.Func.Interface(), 4)
|
||||
m.Push(kit.MDB_NAME, method.Name)
|
||||
m.Push(kit.MDB_TEXT, strings.Split(p, ice.ICEBERGS+"/")[1])
|
||||
}
|
||||
}},
|
||||
}})
|
||||
}
|
@ -90,6 +90,9 @@ func _serve_params(msg *ice.Message, path string) {
|
||||
msg.Logs("refer", ls[2], ls[3])
|
||||
msg.Option(ls[2], ls[3])
|
||||
}
|
||||
case "pod":
|
||||
msg.Logs("refer", ls[1], ls[2])
|
||||
msg.Option(ls[1], ls[2])
|
||||
}
|
||||
}
|
||||
func _serve_handle(key string, cmd *ice.Command, msg *ice.Message, w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -40,14 +40,9 @@ func init() {
|
||||
return // 目录
|
||||
}
|
||||
|
||||
if msg := m.Cmd(ctx.COMMAND, arg[0]); msg.Append("meta") != "" {
|
||||
_cmd_render(m, arg[0], arg[1:])
|
||||
return // 命令
|
||||
}
|
||||
|
||||
switch p := path.Join(m.Conf(CMD, kit.META_PATH), path.Join(arg...)); kit.Ext(p) {
|
||||
case "svg":
|
||||
_cmd_render(m, "web.wiki.draw", path.Dir(p)+"/", path.Base(p))
|
||||
_cmd_render(m, "web.wiki.draw", p)
|
||||
case "csv":
|
||||
_cmd_render(m, "web.wiki.data", p)
|
||||
case "json":
|
||||
@ -57,6 +52,17 @@ func init() {
|
||||
case "go", "mod", "sum":
|
||||
_cmd_render(m, "web.code.inner", path.Dir(p)+"/", path.Base(p))
|
||||
default:
|
||||
if m.Option(cli.POD) != "" {
|
||||
if m.PodCmd(ctx.COMMAND, arg[0]); m.Append("meta") != "" {
|
||||
_cmd_render(m, arg[0], arg[1:])
|
||||
return // 远程命令
|
||||
}
|
||||
} else {
|
||||
if msg := m.Cmd(ctx.COMMAND, arg[0]); msg.Append("meta") != "" {
|
||||
_cmd_render(m, arg[0], arg[1:])
|
||||
return // 本地命令
|
||||
}
|
||||
}
|
||||
m.RenderDownload(p)
|
||||
}
|
||||
}},
|
||||
|
@ -1,13 +1,10 @@
|
||||
package chat
|
||||
|
||||
import (
|
||||
"path"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/tcp"
|
||||
"shylinux.com/x/icebergs/base/web"
|
||||
"shylinux.com/x/icebergs/core/code"
|
||||
@ -112,8 +109,7 @@ func init() {
|
||||
m.Cmdy(code.WEBPACK, mdb.CREATE, m.OptionSimple(kit.MDB_NAME))
|
||||
}},
|
||||
"devops": {Name: "devops", Help: "开发模式", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(nfs.SAVE, path.Join(ice.USR_VOLCANOS, "page/cache.js"))
|
||||
m.Cmd(nfs.SAVE, path.Join(ice.USR_VOLCANOS, "page/cache.css"))
|
||||
m.Cmdy(code.WEBPACK, "devops")
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Option(TRANS, kit.Format(kit.Value(c.Commands[cmd].Meta, "_trans")))
|
||||
|
@ -1,6 +1,8 @@
|
||||
package chat
|
||||
|
||||
import (
|
||||
"path"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
@ -20,17 +22,25 @@ func init() {
|
||||
m.Push("args", "")
|
||||
return
|
||||
}
|
||||
m.Cmdy(ctx.COMMAND, arg[0])
|
||||
if !m.PodCmd(ctx.COMMAND, arg[0]) {
|
||||
m.Cmdy(ctx.COMMAND, arg[0])
|
||||
}
|
||||
}},
|
||||
cli.RUN: {Name: "command", Help: "执行", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(arg)
|
||||
if !m.PodCmd(arg) {
|
||||
m.Cmdy(arg)
|
||||
}
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if kit.Select("", arg, 0) == "" {
|
||||
_cmd_render(m, web.ROUTE)
|
||||
return
|
||||
}
|
||||
m.RenderIndex(web.SERVE, ice.VOLCANOS)
|
||||
if len(arg) == 1 {
|
||||
m.RenderIndex(web.SERVE, ice.VOLCANOS)
|
||||
return
|
||||
}
|
||||
m.Cmdy(m.Prefix("/cmd/"), path.Join(arg[2:]...))
|
||||
}},
|
||||
},
|
||||
Configs: map[string]*ice.Config{
|
||||
|
@ -90,6 +90,12 @@ func init() {
|
||||
m.Cmd(nfs.SAVE, path.Join(ice.USR_VOLCANOS, "page/cache.css"), "")
|
||||
m.Cmd(nfs.SAVE, path.Join(ice.USR_VOLCANOS, "page/cache.js"), "")
|
||||
}},
|
||||
"devops": {Name: "devops", Help: "开发模式", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(nfs.SAVE, path.Join(ice.USR_VOLCANOS, "page/cache.js"))
|
||||
m.Cmd(nfs.SAVE, path.Join(ice.USR_VOLCANOS, "page/cache.css"))
|
||||
m.Cmd(nfs.COPY, _volcanos("page/cmd.css"), _volcanos("page/index.css"), _volcanos("page/cache.css"))
|
||||
m.Cmd(nfs.COPY, _volcanos("page/cmd.js"), _volcanos("proto.js"), _volcanos("page/cache.js"))
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Option(nfs.DIR_DEEP, true)
|
||||
m.Option(nfs.DIR_TYPE, nfs.CAT)
|
||||
|
@ -1,11 +1,53 @@
|
||||
package wiki
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _json_show(m *ice.Message, data interface{}) {
|
||||
switch data := data.(type) {
|
||||
case map[string]interface{}:
|
||||
i := 0
|
||||
if m.Echo(`{`); len(data) > 0 {
|
||||
m.Echo(`<span class="toggle">...</span>`)
|
||||
}
|
||||
m.Echo(`<div class="list">`)
|
||||
for k, v := range data {
|
||||
m.Echo(`<div class="item">`)
|
||||
m.Echo(`"<span class="key">%s</span>": `, k)
|
||||
_json_show(m, v)
|
||||
if i++; i < len(data) {
|
||||
m.Echo(",")
|
||||
}
|
||||
m.Echo("</div>")
|
||||
}
|
||||
m.Echo(`</div>`)
|
||||
m.Echo("}")
|
||||
case []interface{}:
|
||||
if m.Echo(`[`); len(data) > 0 {
|
||||
m.Echo(`<span class="toggle">...</span>`)
|
||||
}
|
||||
m.Echo(`<div class="list">`)
|
||||
for i, v := range data {
|
||||
_json_show(m, v)
|
||||
if i < len(data)-1 {
|
||||
m.Echo(",")
|
||||
}
|
||||
}
|
||||
m.Echo(`</div>`)
|
||||
m.Echo("]")
|
||||
case string:
|
||||
m.Echo(`"<span class="value str">%v</span>"`, data)
|
||||
default:
|
||||
m.Echo(`<span class="value">%v</span>`, data)
|
||||
}
|
||||
}
|
||||
|
||||
const JSON = "json"
|
||||
|
||||
func init() {
|
||||
@ -20,6 +62,14 @@ func init() {
|
||||
nfs.SAVE: {Name: "save path text", Help: "保存", Hand: func(m *ice.Message, arg ...string) {
|
||||
_wiki_save(m, JSON, arg[0], arg[1])
|
||||
}},
|
||||
cli.RUN: {Name: "run", Help: "执行", Hand: func(m *ice.Message, arg ...string) {
|
||||
var data interface{}
|
||||
json.Unmarshal([]byte(m.Cmdx(arg)), &data)
|
||||
m.Option("type", "json")
|
||||
m.RenderTemplate(`<div {{.OptionTemplate}}>`)
|
||||
_json_show(m, data)
|
||||
m.Echo(`</div>`)
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if !_wiki_list(m, JSON, kit.Select("./", arg, 0)) {
|
||||
m.Cmdy(nfs.CAT, arg[0])
|
||||
|
Loading…
x
Reference in New Issue
Block a user