1
0
forked from x/icebergs

add docker

This commit is contained in:
shaoying 2020-01-09 09:36:01 +08:00
parent 456afbba49
commit 67bb04e892
4 changed files with 89 additions and 10 deletions

View File

@ -163,19 +163,21 @@ var Index = &ice.Context{Name: "wiki", Help: "文档模块",
m.Echo(string(markdown.ToHTML(buffer.Bytes(), nil, nil)))
}},
"_tree": {Name: "_tree path", Help: "文库", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
m.Cmdy("nfs.dir", m.Conf("note", "meta.path"),
kit.Select("", arg, 0), m.Conf("note", "meta.head"))
m.Cmdy("nfs.dir", kit.Select(m.Conf("note", "meta.path"), arg, 0), m.Conf("note", "meta.head"))
}},
"note": {Name: "note file", Help: "笔记", Meta: kit.Dict(
"remote", "you", "display", "inner",
"detail", []string{"add", "commit", "history", "share", "favor"},
), List: kit.List(
kit.MDB_INPUT, "text", "value", "miss.md", "name", "path",
kit.MDB_INPUT, "button", "value", "执行", "action", "auto",
kit.MDB_INPUT, "button", "value", "返回", "cb", "Last",
"note": {Name: "note file", Help: "笔记", Meta: kit.Dict("remote", "you", "display", "inner"), List: kit.List(
kit.MDB_INPUT, "text", "name", "path", "value", "miss.md",
kit.MDB_INPUT, "button", "name", "执行", "action", "auto",
kit.MDB_INPUT, "button", "name", "返回", "cb", "Last",
), Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
if len(arg) > 1 {
switch arg[1] {
case "运行":
switch arg[2] {
case "shell":
m.Cmdy(ice.CLI_SYSTEM, "sh", "-c", arg[4])
}
case "favor":
m.Cmdy(ice.WEB_FAVOR, kit.Select("story", m.Option("hot")), arg[2:])
case "share":

41
misc/docker/docker.go Normal file
View File

@ -0,0 +1,41 @@
package docker
import (
"github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/cli"
"github.com/shylinux/toolkits"
"strings"
)
var Index = &ice.Context{Name: "docker", Help: "docker",
Caches: map[string]*ice.Cache{},
Configs: map[string]*ice.Config{
"docker": {Name: "docker", Help: "docker", Value: kit.Data(kit.MDB_SHORT, "name")},
},
Commands: map[string]*ice.Command{
ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}},
ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}},
"docker": {Name: "docker", Help: "docker", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Echo("hello world")
}},
"image": {Name: "image", Help: "镜像管理", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Split(strings.Replace(m.Cmdx(ice.CLI_SYSTEM, "docker", "image", "ls"), "IMAGE ID", "IMAGE_ID", 1), "index", " ", "\n")
}},
"container": {Name: "container", Help: "容器管理", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
prefix := []string{ice.CLI_SYSTEM, "docker", "container"}
if len(arg) > 2 {
switch arg[1] {
case "modify":
switch arg[2] {
case "NAMES":
m.Cmd(prefix, "rename", arg[4], arg[3])
}
}
}
m.Split(strings.Replace(m.Cmdx(prefix, "ls"), "CONTAINER ID", "CONTAINER_ID", 1), "index", " ", "\n")
}},
},
}
func init() { cli.Index.Register(Index, nil) }

14
miss/main.go Normal file
View File

@ -0,0 +1,14 @@
package main
import (
"github.com/shylinux/icebergs"
_ "github.com/shylinux/icebergs/base"
_ "github.com/shylinux/icebergs/core"
_ "github.com/shylinux/icebergs/misc"
_ "github.com/shylinux/icebergs/misc/docker"
)
func main() {
println(ice.Run())
}

24
type.go
View File

@ -552,8 +552,30 @@ func (m *Message) Render(str string) *Message {
return m
}
func (m *Message) Split(str string, field string, space string, enter string) *Message {
indexs := []int{}
fields := kit.Split(field, space)
for _, l := range kit.Split(str, enter) {
for i, l := range kit.Split(str, enter) {
if i == 0 && (field == "" || field == "index") {
fields = kit.Split(l, space)
if field == "index" {
for _, v := range fields {
indexs = append(indexs, strings.Index(l, v))
}
}
continue
}
if len(indexs) > 0 {
for i, v := range indexs {
if i == len(indexs)-1 {
m.Push(kit.Select("some", fields, i), l[v:])
} else {
m.Push(kit.Select("some", fields, i), l[v:indexs[i+1]])
}
}
continue
}
for i, v := range kit.Split(l, space) {
m.Push(kit.Select("some", fields, i), v)
}