mirror of
https://shylinux.com/x/icebergs
synced 2025-05-03 03:57:01 +08:00
opt field
This commit is contained in:
parent
fe5d71177c
commit
9d246c8014
@ -6,11 +6,46 @@ import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/web"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _div_deep(str string) int {
|
||||
for i, c := range str {
|
||||
if c != ' ' {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
func _div_parse(m *ice.Message, root map[string]interface{}, list []string) int {
|
||||
var last map[string]interface{}
|
||||
deep := _div_deep(list[0])
|
||||
for i := 0; i < len(list); i++ {
|
||||
if d := _div_deep(list[i]); d < deep {
|
||||
return i
|
||||
} else if d > deep {
|
||||
i += _div_parse(m, last, list[i:]) - 1
|
||||
continue
|
||||
}
|
||||
|
||||
ls := kit.Split(list[i])
|
||||
if ls[0] == "_left" {
|
||||
ls = append([]string{"", "", "style", "left"}, ls[1:]...)
|
||||
}
|
||||
meta := kit.Dict(
|
||||
"index", kit.Select("", ls, 0),
|
||||
"args", kit.Select("", ls, 1),
|
||||
)
|
||||
for i := 2; i < len(ls); i += 2 {
|
||||
meta[ls[i]] = ls[i+1]
|
||||
}
|
||||
last = kit.Dict("meta", meta, "list", kit.List())
|
||||
kit.Value(root, "list.-2", last)
|
||||
}
|
||||
return len(list)
|
||||
}
|
||||
|
||||
const DIV = "div"
|
||||
|
||||
func init() {
|
||||
@ -22,8 +57,12 @@ func init() {
|
||||
}, Commands: map[string]*ice.Command{
|
||||
DIV: {Name: "div hash auto", Help: "定制", Action: ice.MergeAction(map[string]*ice.Action{
|
||||
mdb.CREATE: {Name: "create type=page name=hi.html text", Help: "创建"},
|
||||
cli.MAKE: {Name: "make", Help: "生成", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(nfs.SAVE, path.Join(m.Conf(DIV, kit.META_PATH), m.Option(kit.MDB_NAME)), m.Option(kit.MDB_TEXT))
|
||||
cli.MAKE: {Name: "make name=some line:textarea", Help: "生成", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Fields(0)
|
||||
node := kit.Dict("meta", kit.Dict("name", m.Option("name")), "list", []interface{}{})
|
||||
_div_parse(m, node, kit.Split(m.Option("line"), "\n", "\n", "\n"))
|
||||
m.ProcessDisplay("/plugin/local/chat/div.js")
|
||||
m.Push("text", kit.Formats(node))
|
||||
}},
|
||||
}, mdb.HashAction(), mdb.CmdAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Fields(len(arg), m.Conf(DIV, kit.META_FIELD))
|
||||
@ -35,7 +74,7 @@ func init() {
|
||||
m.Option(ice.MSG_DISPLAY, "/plugin/local/chat/div.js")
|
||||
m.Action("添加", "保存", "预览")
|
||||
} else {
|
||||
m.Action(mdb.CREATE)
|
||||
m.Action(mdb.CREATE, cli.MAKE)
|
||||
}
|
||||
}},
|
||||
"/div": {Name: "/div", Help: "定制", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
|
@ -23,7 +23,10 @@ func _field_show(m *ice.Message, name, text string, arg ...string) {
|
||||
|
||||
// 扩展参数
|
||||
for i := 0; i < len(arg)-1; i += 2 {
|
||||
if strings.HasPrefix(arg[i], "args.") {
|
||||
if strings.HasPrefix(arg[i], "opts.") {
|
||||
m.Option(arg[i], strings.TrimSpace(arg[i+1]))
|
||||
kit.Value(meta, arg[i], m.Option(arg[i]))
|
||||
} else if strings.HasPrefix(arg[i], "args.") {
|
||||
m.Option(arg[i], strings.TrimSpace(arg[i+1]))
|
||||
kit.Value(meta, arg[i], m.Option(arg[i]))
|
||||
} else if strings.HasPrefix(arg[i], ARGS) {
|
||||
@ -80,7 +83,9 @@ func init() {
|
||||
m.Cmdy(arg)
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
arg = _name(m, arg)
|
||||
if arg = _name(m, arg); strings.Contains(arg[1], "\n") {
|
||||
arg = append([]string{arg[0], "web.chat.div", "auto.cmd", "make", "opts.line", arg[1]}, arg[2:]...)
|
||||
}
|
||||
_field_show(m, arg[0], arg[1], arg[2:]...)
|
||||
}},
|
||||
},
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
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/ssh"
|
||||
"shylinux.com/x/icebergs/base/web"
|
||||
@ -63,11 +64,11 @@ func init() {
|
||||
Commands: map[string]*ice.Command{
|
||||
WORD: {Name: "word path=src/main.shy auto 演示", Help: "语言文字", Meta: kit.Dict(
|
||||
ice.Display("/plugin/local/wiki/word.js", WORD),
|
||||
), Action: map[string]*ice.Action{
|
||||
), Action: ice.MergeAction(map[string]*ice.Action{
|
||||
web.STORY: {Name: "story", Help: "运行", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(arg[0], ctx.ACTION, cli.RUN, arg[2:])
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
}, mdb.CmdAction()), 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, ice.TRUE); !_wiki_list(m, cmd, arg...) {
|
||||
_word_show(m, arg[0])
|
||||
|
@ -81,7 +81,8 @@ func init() {
|
||||
}
|
||||
|
||||
args := []string{}
|
||||
args = append(args, "log", kit.Format("--author=%s\\|shylinux", m.Option(ice.MSG_USERNAME)),
|
||||
args = append(args, "log",
|
||||
// kit.Format("--author=%s\\|shylinux", m.Option(ice.MSG_USERNAME)),
|
||||
"--shortstat", "--pretty=commit: %ad %n%s", "--date=iso", "--reverse")
|
||||
if len(arg) > 0 {
|
||||
if strings.Contains(arg[0], "-") && !strings.Contains(arg[0], ":") {
|
||||
|
Loading…
x
Reference in New Issue
Block a user