forked from x/icebergs
add parse
This commit is contained in:
parent
9e1fd3acee
commit
47ea2e37a5
@ -199,6 +199,7 @@ func init() {
|
||||
m.Push(mdb.NAME, v)
|
||||
}
|
||||
m.Sort(nfs.FILE)
|
||||
m.StatusTimeCount()
|
||||
}},
|
||||
"route": {Name: "route", Help: "接口命令", Hand: func(m *ice.Message, arg ...string) {
|
||||
for k, v := range ice.Info.Route {
|
||||
|
@ -139,13 +139,14 @@ const (
|
||||
JS = ice.JS
|
||||
GO = ice.GO
|
||||
SH = ice.SH
|
||||
SHY = ice.SHY
|
||||
CSV = ice.CSV
|
||||
JSON = ice.JSON
|
||||
YML = "yml"
|
||||
IML = "iml"
|
||||
TXT = "txt"
|
||||
SHY = "shy"
|
||||
SVG = "svg"
|
||||
|
||||
YML = "yml"
|
||||
IML = "iml"
|
||||
TXT = "txt"
|
||||
SVG = "svg"
|
||||
|
||||
PWD = "./"
|
||||
)
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"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"
|
||||
@ -25,7 +26,7 @@ func init() {
|
||||
m.Cmdy(CMD, mdb.CREATE, mdb.TYPE, "csv", mdb.NAME, "web.wiki.data")
|
||||
m.Cmdy(CMD, mdb.CREATE, mdb.TYPE, "json", mdb.NAME, "web.wiki.json")
|
||||
|
||||
for _, k := range []string{"sh", "go", "js", "mod", "sum"} {
|
||||
for _, k := range []string{"mod", "sum"} {
|
||||
m.Cmdy(CMD, mdb.CREATE, mdb.TYPE, k, mdb.NAME, "web.code.inner")
|
||||
}
|
||||
}},
|
||||
@ -35,6 +36,12 @@ func init() {
|
||||
return // 目录
|
||||
}
|
||||
|
||||
if mdb.HashSelect(m.Spawn(), path.Join(arg...)).Table(func(index int, value map[string]string, head []string) {
|
||||
m.RenderCmd(value[mdb.NAME])
|
||||
}).Length() > 0 {
|
||||
return // 命令
|
||||
}
|
||||
|
||||
p := path.Join(m.Config(nfs.PATH), path.Join(arg...))
|
||||
if mdb.HashSelect(m.Spawn(), kit.Ext(m.R.URL.Path)).Table(func(index int, value map[string]string, head []string) {
|
||||
m.RenderCmd(value[mdb.NAME], p)
|
||||
@ -42,6 +49,30 @@ func init() {
|
||||
return // 插件
|
||||
}
|
||||
|
||||
switch p := path.Join(arg...); kit.Ext(p) {
|
||||
case nfs.JS:
|
||||
if cmd := ice.GetFileCmd(p); cmd != "" {
|
||||
m.Display(ice.FileURI(p))
|
||||
m.RenderCmd(cmd)
|
||||
}
|
||||
return
|
||||
case nfs.GO:
|
||||
if cmd := ice.GetFileCmd(p); cmd != "" {
|
||||
m.RenderCmd(cmd)
|
||||
}
|
||||
return
|
||||
case nfs.SH:
|
||||
if cmd := ice.GetFileCmd(p); cmd != "" {
|
||||
msg := m.Cmd(cmd, ice.OptionFields(""))
|
||||
if msg.Length() > 0 {
|
||||
msg.Table()
|
||||
}
|
||||
m.Cmdy(cli.SYSTEM, "sh", p, msg.Result())
|
||||
m.RenderResult()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if m.PodCmd(ctx.COMMAND, arg[0]) {
|
||||
if !m.IsErr() {
|
||||
m.RenderCmd(arg[0], arg[1:]) // 远程命令
|
||||
@ -74,7 +105,7 @@ func init() {
|
||||
m.ProcessLocation(arg[0])
|
||||
return
|
||||
}
|
||||
switch kit.Ext(path.Join(arg...)) {
|
||||
switch p := path.Join(arg...); kit.Ext(p) {
|
||||
case "html":
|
||||
m.RenderResult(m.Cmdx(nfs.CAT, path.Join(ice.SRC, path.Join(arg...))))
|
||||
return
|
||||
|
44
info.go
44
info.go
@ -64,11 +64,7 @@ source: https://shylinux.com/x/icebergs
|
||||
names: map[string]interface{}{},
|
||||
}
|
||||
|
||||
func FileCmd(dir string) string {
|
||||
dir = strings.Split(dir, DF)[0]
|
||||
dir = strings.ReplaceAll(dir, ".js", ".go")
|
||||
dir = strings.ReplaceAll(dir, ".sh", ".go")
|
||||
|
||||
func FileURI(dir string) string {
|
||||
if strings.Contains(dir, "go/pkg/mod") {
|
||||
return path.Join("/require", strings.Split(dir, "go/pkg/mod")[1])
|
||||
}
|
||||
@ -86,5 +82,39 @@ func FileCmd(dir string) string {
|
||||
}
|
||||
return dir
|
||||
}
|
||||
func AddFileCmd(dir, key string) { Info.File[FileCmd(dir)] = key }
|
||||
func GetFileCmd(dir string) string { return Info.File[FileCmd(dir)] }
|
||||
func FileCmd(dir string) string {
|
||||
dir = strings.Split(dir, DF)[0]
|
||||
dir = strings.ReplaceAll(dir, ".js", ".go")
|
||||
dir = strings.ReplaceAll(dir, ".sh", ".go")
|
||||
return FileURI(dir)
|
||||
}
|
||||
func AddFileCmd(dir, key string) {
|
||||
Info.File[FileCmd(dir)] = key
|
||||
}
|
||||
func GetFileCmd(dir string) string {
|
||||
if strings.HasPrefix(dir, "require/") {
|
||||
dir = "/" + dir
|
||||
}
|
||||
for _, dir := range []string{dir, "/require/"+Info.Make.Module+"/"+dir}{
|
||||
if cmd, ok := Info.File[FileCmd(dir)]; ok {
|
||||
return cmd
|
||||
}
|
||||
p := path.Dir(dir)
|
||||
if cmd, ok := Info.File[FileCmd(path.Join(p, path.Base(p)+".go"))]; ok {
|
||||
return cmd
|
||||
}
|
||||
for k, v := range Info.File {
|
||||
if strings.HasPrefix(k, p) {
|
||||
return v
|
||||
}
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
func FileRequire(n int) string {
|
||||
p := kit.Split(kit.FileLine(n, 100), DF)[0]
|
||||
if strings.Contains(p, "go/pkg/mod") {
|
||||
return path.Join("/require", strings.Split(p, "go/pkg/mod")[1])
|
||||
}
|
||||
return path.Join("/require/" + kit.ModPath(n), path.Base(p))
|
||||
}
|
||||
|
3
logs.go
3
logs.go
@ -112,6 +112,9 @@ func (m *Message) Error(err bool, str string, arg ...interface{}) bool {
|
||||
return false
|
||||
}
|
||||
func (m *Message) Debug(str string, arg ...interface{}) {
|
||||
if str == "" {
|
||||
str = m.FormatMeta()
|
||||
}
|
||||
m.log(LOG_DEBUG, str, arg...)
|
||||
}
|
||||
|
||||
|
@ -60,6 +60,9 @@ func init() {
|
||||
m.ProcessCommand(code.INNER, m.OptionSplit("path,file,line"), arg...)
|
||||
}},
|
||||
INPUT: {Name: "input name text", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
|
||||
if m.Option(mdb.TEXT) == "" {
|
||||
return
|
||||
}
|
||||
mdb.ZoneSelectCB(m, kit.Slice(kit.Split(m.Option(mdb.TEXT), ice.PT), -1)[0], func(value map[string]string) {
|
||||
if !strings.Contains(value[mdb.NAME], m.Option(mdb.NAME)) {
|
||||
return
|
||||
|
@ -89,6 +89,7 @@ func (m *Message) RenderCmd(index string, args ...interface{}) {
|
||||
list = kit.Format(kit.List(kit.Dict(
|
||||
INDEX, index, ARGS, kit.Simple(args), msg.AppendSimple(NAME, HELP),
|
||||
INPUTS, kit.UnMarshal(msg.Append(LIST)), FEATURE, kit.UnMarshal(msg.Append(META)),
|
||||
"display", m.Option(MSG_DISPLAY),
|
||||
)))
|
||||
}
|
||||
m.Echo(kit.Format(`<!DOCTYPE html>
|
||||
@ -285,11 +286,7 @@ func DisplayRequire(n int, file string, arg ...string) map[string]string {
|
||||
file = kit.Keys(kit.FileName(n+1), JS)
|
||||
}
|
||||
if !strings.HasPrefix(file, HTTP) && !strings.HasPrefix(file, PS) {
|
||||
if kit.FileExists("src/" + file) {
|
||||
file = path.Join(PS, REQUIRE, "src/", file)
|
||||
} else {
|
||||
file = path.Join(PS, REQUIRE, kit.ModPath(n+1, file))
|
||||
}
|
||||
file = path.Join(PS, path.Join(path.Dir(FileRequire(n+2)), file))
|
||||
}
|
||||
return DisplayBase(file, arg...)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user