1
0
mirror of https://shylinux.com/x/ContextOS synced 2025-04-25 16:58:06 +08:00

opt cli.project

This commit is contained in:
shaoying 2019-07-15 08:49:22 +08:00
parent d2304e5bda
commit 13520059c7
53 changed files with 559 additions and 253 deletions

View File

@ -8,6 +8,7 @@
config load tmp/data.json ktv
~wiki
config load tmp/wiki.json wiki_visit
source etc/common.shy
~ssh
remote auto

View File

@ -6,6 +6,7 @@ import (
"contexts/ctx"
"encoding/csv"
"encoding/json"
"io/ioutil"
"os/exec"
"os/user"
"path"
@ -144,13 +145,8 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
"action": &ctx.Config{Name: "action", Value: map[string]interface{}{}, Help: "交互任务"},
"project": &ctx.Config{Name: "project", Value: map[string]interface{}{
// vim git golang
"ubuntu": map[string]interface{}{},
"github": "https://github.com/shylinux/context",
"env": map[string]interface{}{
"GOPATH": "https://github.com/shylinux/context",
},
"import": []interface{}{
"goproxy": "https://goproxy.cn", "import": []interface{}{
"github.com/nsf/termbox-go",
"github.com/gomodule/redigo/redis",
"github.com/go-sql-driver/mysql",
@ -159,13 +155,28 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
"github.com/skip2/go-qrcode",
"github.com/PuerkitoBio/goquery",
"github.com/go-cas/cas",
}, "plugin": map[string]interface{}{
"path": "src/plugin", "list": []interface{}{
map[string]interface{}{"name": "index.go", "text": ""},
map[string]interface{}{"name": "index.js", "text": ""},
map[string]interface{}{"name": "local.shy", "text": ""},
},
}, Help: "运行环境"},
}, "script": map[string]interface{}{
"path": "usr/script",
},
}, Help: "项目管理"},
"compile": &ctx.Config{Name: "compile", Value: map[string]interface{}{
"bench": "src/extend/bench.go",
"tmp": "var/tmp/go",
"bench": "src/extend/bench.go", "list": []interface{}{
map[string]interface{}{"os": "linux", "cpu": "amd64"},
map[string]interface{}{"os": "linux", "cpu": "386"},
map[string]interface{}{"os": "linux", "cpu": "arm"},
map[string]interface{}{"os": "windows", "cpu": "amd64"},
map[string]interface{}{"os": "windows", "cpu": "386"},
map[string]interface{}{"os": "darwin", "cpu": "amd64"},
},
"env": []interface{}{"GOPATH", "PATH"},
}, Help: "运行环境"},
"tmp": "var/tmp/go",
}, Help: "源码编译"},
"publish": &ctx.Config{Name: "publish", Value: map[string]interface{}{
"path": "usr/publish", "list": map[string]interface{}{
"boot_sh": "bin/boot.sh",
@ -177,7 +188,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
"template_tar_gz": "usr/template",
"librarys_tar_gz": "usr/librarys",
},
}, Help: "运行环境"},
}, Help: "版本发布"},
"upgrade": &ctx.Config{Name: "upgrade", Value: map[string]interface{}{
"system": []interface{}{"boot.sh", "node.sh", "init.shy", "common.shy", "exit.shy"},
"portal": []interface{}{"template.tar.gz", "librarys.tar.gz"},
@ -193,10 +204,10 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
"template_tar_gz": "usr/template.tar.gz",
"librarys_tar_gz": "usr/librarys.tar.gz",
},
}, Help: "日志地址"},
}, Help: "服务升级"},
"missyou": &ctx.Config{Name: "missyou", Value: map[string]interface{}{
"path": "usr/work",
}, Help: "免密登录"},
"path": "usr/local/work", "local": "usr/local",
}, Help: "任务管理"},
"timer": &ctx.Config{Name: "timer", Value: map[string]interface{}{}, Help: "定时器"},
"timer_next": &ctx.Config{Name: "timer_next", Value: "", Help: "定时器"},
@ -639,28 +650,24 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
return
}},
"project": &ctx.Command{Name: "project", Help: "", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
"project": &ctx.Command{Name: "project init|stat|import|plugin", Help: "项目管理, ", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
switch arg[0] {
case "prepare":
case "init":
if _, e := os.Stat(".git"); e == nil {
m.Cmdp(0, []string{"git update"}, []string{"cli.system", "git"}, [][]string{
[]string{"git", "stash"},
[]string{"git", "pull"},
[]string{"git", "stash", "pop"},
[]string{"git", "stash"}, []string{"git", "pull"}, []string{"git", "stash", "pop"},
})
m.Cmdy("nfs.git", "status")
return e
}
m.Cmdp(0, []string{"git init"}, []string{"cli.system", "git"}, [][]string{
[]string{"init"},
[]string{"remote", "add", kit.Select("origin", arg, 1), kit.Select(m.Conf("project", "github"), arg, 2)},
[]string{"stash"},
[]string{"pull"},
[]string{"checkout", "-f", "master"},
[]string{"stash", "pop"},
[]string{"init"}, []string{"remote", "add", kit.Select("origin", arg, 1), kit.Select(m.Conf("project", "github"), arg, 2)},
[]string{"stash"}, []string{"pull"}, []string{"checkout", "-f", "master"}, []string{"stash", "pop"},
})
case "stat":
m.Cmdy("nfs.dir", "src", "dir_deep", "dir_type", "file", "dir_sort", "line", "int_r").CopyTo(m, "append")
case "import":
list := [][]string{}
m.Confm("project", "import", func(index int, value string) {
@ -671,44 +678,67 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
m.Table()
m.Cmdp(time.Second, []string{"go init"}, []string{"cli.system", "go", "get",
"cmd_env", "GOPROXY", m.Conf("project", "goproxy"),
"cmd_env", "GOPATH", m.Conf("runtime", "boot.ctx_path")}, list)
case "stat":
m.Cmd("nfs.dir", "src", "dir_deep", "dir_type", "file").CopyTo(m, "append")
m.Cmd("nfs.dir", "usr/librarys", "dir_deep", "dir_type", "file").CopyTo(m, "append")
m.Set("result").Table()
case "plugin":
arg = arg[1:]
if len(arg) == 0 {
m.Cmdy("nfs.dir", m.Conf("project", "plugin.path"))
break
}
fallthrough
default:
p := path.Join(m.Conf("project", "plugin.path"), arg[0])
if _, e := os.Stat(p); os.IsNotExist(e) && m.Assert(os.MkdirAll(p, 0777)) {
m.Confm("project", "plugin.list", func(index int, value map[string]interface{}) {
ioutil.WriteFile(path.Join(p, kit.Format(value["name"])), []byte(kit.Format(value["text"])), 0666)
})
}
m.Cmdy("nfs.dir", p, "time", "size", "line", "path")
}
return
}},
"compile": &ctx.Command{Name: "compile [OS [ARCH]]", Help: "解析脚本, script: 脚本文件, stdio: 命令终端, snippet: 代码片段", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
"compile": &ctx.Command{Name: "compile all|self|[[[plugin] name] [OS [ARCH]]]", Help: "源码编译", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
switch arg[0] {
case "all":
list := [][]string{}
m.Confm("compile", "list", func(index int, value map[string]interface{}) {
list = append(list, []string{kit.Format(value["os"]), kit.Format(value["cpu"])})
})
m.Cmdp(0, []string{"go build"}, []string{"cli.compile"}, list)
m.Cmdy("nfs.dir", m.Conf("publish", "path"), "dir_reg", "bench")
case "self":
m.Cmd("cli.version", "create")
if len(arg) > 0 && arg[0] == "self" {
if m.Cmdy("cli.system", "go", "install", m.Cmdx("nfs.path", m.Conf("compile", "bench"))); m.Result(0) == "" {
m.Echo("%v: %v ", version.host, version.self)
m.Cmdy("cli.quit", 1)
}
return
m.Append("host", version.host)
m.Append("self", version.self)
m.Table()
}
if len(arg) > 0 && arg[0] == "all" {
m.Cmdp(0, []string{"go build"}, []string{"cli.compile"}, [][]string{
[]string{"linux", "386"},
[]string{"linux", "amd64"},
[]string{"linux", "arm"},
[]string{"windows", "386"},
[]string{"windows", "amd64"},
[]string{"darwin", "amd64"},
})
m.Echo("done %s", m.Time())
return
case "plugin":
arg = arg[1:]
if len(arg) == 0 {
m.Cmdy("nfs.dir", m.Conf("publish", "path"), "dir_deep", "dir_reg", ".*\\.so", "time", "size", "hash", "path")
break
}
if len(arg) > 0 {
fallthrough
default:
p, q, o := path.Join(m.Conf("project", "plugin.path"), arg[0], "index.go"), "", []string{}
if _, e := os.Stat(p); e == nil {
q = path.Join(m.Conf("publish", "path"), arg[0], "index.so")
o = []string{"-buildmode=plugin"}
arg = arg[1:]
}
goos := kit.Select(m.Conf("runtime", "host.GOOS"), arg, 0)
arch := kit.Select(m.Conf("runtime", "host.GOARCH"), arg, 1)
name := strings.Join([]string{"bench", goos, arch}, "_")
wd, _ := os.Getwd()
os.MkdirAll(m.Conf("compile", "tmp"), 0777)
env := []string{"cmd_env", "GOOS", goos, "cmd_env", "GOARCH", arch, "cmd_env",
env := []string{"cmd_env", "GOOS", goos, "cmd_env", "GOARCH", arch,
"cmd_env", "GOTMPDIR", path.Join(wd, m.Conf("compile", "tmp")),
"cmd_env", "GOCACHE", path.Join(wd, m.Conf("compile", "tmp")),
}
@ -716,18 +746,21 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
env = append(env, "cmd_env", key, kit.Select(os.Getenv(key), m.Option(key)))
})
p := m.Cmdx("nfs.path", m.Conf("compile", "bench"))
q := path.Join(m.Conf("publish", "path"), name)
if m.Cmdy("cli.system", env, "go", "build", "-o", q, p); m.Result(0) == "" {
if q == "" {
q = path.Join(m.Conf("publish", "path"), strings.Join([]string{"bench", goos, arch}, "_"))
p = m.Cmdx("nfs.path", m.Conf("compile", "bench"))
}
if m.Cmdy("cli.system", env, "go", "build", o, "-o", q, p); m.Result(0) == "" {
m.Append("time", m.Time())
m.Append("bin", name)
m.Append("bin", q)
m.Append("hash", kit.Hashs(q))
m.Table()
}
}
return
}},
"publish": &ctx.Command{Name: "publish", Help: "", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
"publish": &ctx.Command{Name: "publish", Help: "版本发布", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
dir := m.Conf("publish", "path")
m.Assert(os.MkdirAll(dir, 0777))
@ -740,6 +773,16 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
return
}
p := path.Join(m.Conf("project", "plugin.path"), arg[0])
q := path.Join(m.Conf("publish", "path"), arg[0])
if _, e := os.Stat(p); e == nil && m.Assert(os.MkdirAll(q, 0777)) {
m.Confm("project", "plugin.list", func(index int, value map[string]interface{}) {
m.Cmd("nfs.copy", path.Join(q, kit.Format(value["name"])), path.Join(p, kit.Format(value["name"])))
})
m.Cmdy("nfs.dir", q, "time", "size", "hash", "path")
return e
}
for _, key := range arg {
key = kit.Key(key)
value := m.Conf("publish", []string{"list", key})
@ -757,74 +800,59 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
}
}
m.Table()
// m.Cmdy("nfs.dir", dir, "dir_sort", "time", "time_r")
return
}},
"version": &ctx.Command{Name: "version", Help: "", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
if len(arg) == 0 {
types := reflect.TypeOf(version)
value := reflect.ValueOf(version)
for i := 0; i < types.NumField(); i++ {
key := types.Field(i)
val := value.Field(i)
m.Add("append", "name", key.Name)
m.Add("append", "type", key.Type.Name())
m.Add("append", "value", fmt.Sprintf("%v", val))
}
m.Table()
return
}
m.Cmd("nfs.save", path.Join(m.Conf("runtime", "boot.ctx_home"), "src/contexts/cli/version.go"), fmt.Sprintf(`package cli
var version = struct {
time string
host string
self int
}{
"%s", "%s", %d,
}
`, m.Time(), m.Conf("runtime", "node.route"), version.self+1))
m.Append("directory", "")
return
}},
"upgrade": &ctx.Command{Name: "upgrade project|bench|system|plugin|portal|script", Help: "服务升级", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
"upgrade": &ctx.Command{Name: "upgrade project|bench|system|portal|plugin|script", Help: "服务升级", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
if len(arg) == 0 {
m.Cmdy("ctx.config", "upgrade")
return
}
if len(arg) > 0 && arg[0] == "project" {
switch arg[0] {
case "project":
m.Cmd("cli.project", "init")
m.Cmd("cli.compile", "all")
m.Cmd("cli.publish")
return
case "script":
if len(arg) == 1 {
m.Cmdy("nfs.dir", m.Conf("project", "script.path"), "time", "size", "line", "hash", "path")
break
}
if len(arg) > 0 && arg[0] == "plugin" {
m.Cmdy("web.get", "dev", fmt.Sprintf("publish/%s", arg[1]),
"upgrade", "plugin", "save", path.Join("src/plugin", arg[1]))
m.Cmdy("cli.plugin", "test.so")
return
}
if len(arg) > 1 && arg[0] == "script" {
miss := ""
if len(arg) > 2 {
miss, arg = arg[1], arg[2:]
} else {
arg = arg[1:]
miss, arg = arg[1], arg[1:]
}
for _, v := range arg {
for _, v := range arg[1:] {
m.Cmdy("web.get", "dev", fmt.Sprintf("publish/%s", v),
"upgrade", "script", "missyou", miss, "save", path.Join("usr/script", v))
}
return
case "plugin":
if arg = arg[1:]; len(arg) == 0 {
m.Cmdy("cli.context")
break
}
fallthrough
default:
if p, e := plugin.Open(path.Join(m.Conf("publish", "path"), arg[0], "index.so")); e == nil {
if s, e := p.Lookup("Index"); m.Assert(e) {
msg := m.Spawn(c.Register(*(s.(**ctx.Context)), nil, arg[0])).Cmd("_init", arg[1:])
msg.Cap("stream", arg[0])
msg.Confm("index", func(index int, value map[string]interface{}) {
value["componet_ctx"] = "cli." + arg[0]
m.Conf("ssh.componet", []interface{}{arg[0], index}, value)
m.Add("append", "index", index)
m.Add("append", "name", value["componet_name"])
m.Add("append", "help", value["componet_help"])
})
m.Table()
}
return e
}
restart := false
for _, link := range kit.View([]string{arg[0]}, m.Confm("upgrade")) {
file := kit.Select(link, m.Conf("upgrade", []string{"list", strings.Replace(link, ".", "_", -1)}))
if arg[0] == "script" {
file = path.Join("usr/script", file)
}
m.Cmd("web.get", "dev", fmt.Sprintf("publish/%s", link),
"GOARCH", m.Conf("runtime", "host.GOARCH"),
@ -848,14 +876,15 @@ var version = struct {
m.Cmd("cli.system", "tar", "-xvf", file, "-C", path.Dir(file))
}
}
m.Table()
if restart {
if m.Table(); restart {
m.Cmd("cli.quit", 1)
}
}
return
}},
"missyou": &ctx.Command{Name: "missyou", Help: "服务升级", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
"missyou": &ctx.Command{Name: "missyou [name [stop]]", Help: "任务管理", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
if len(arg) == 0 {
m.Option("dir_root", "")
m.Cmd("nfs.dir", m.Conf("missyou", "path")).Table(func(value map[string]string) {
@ -888,31 +917,56 @@ var version = struct {
p := path.Join(m.Conf("missyou", "path"), arg[0])
if _, e := os.Stat(p); e != nil {
m.Cmd("nfs.copy", path.Join(p, "etc/local.shy"), "usr/missyou/job.shy")
m.Cmd("nfs.copy", path.Join(p, "etc/local.shy"), path.Join(m.Conf("publish", "path"), kit.Select("hello", arg, 1), "local.shy"))
m.Confm("missyou", "local", func(index string, local string) {
m.Cmd("nfs.git", "clone", local, path.Join(p, "usr/local", index))
m.Cmd("nfs.git", "clone", local, path.Join(p, m.Conf("missyou", "local"), index))
})
}
m.Cmdy("cli.system", path.Join(m.Conf("runtime", "boot.ctx_home"), "bin/node.sh"), "create", arg[0],
"daemon",
"cmd_env", "PATH", os.Getenv("path"),
"cmd_dir", m.Conf("missyou", "path"),
args := []string{
"daemon", "cmd_dir", p,
"cmd_env", "PATH", os.Getenv("PATH"),
"cmd_env", "ctx_home", m.Conf("runtime", "boot.ctx_home"),
"cmd_env", "ctx_ups", fmt.Sprintf("127.0.0.1%s", m.Conf("runtime", "boot.ssh_port")),
"cmd_env", "ctx_box", fmt.Sprintf("http://127.0.0.1%s", m.Conf("runtime", "boot.web_port")),
"cmd_daemon", "true",
)
return
m.Cmdy("cli.system", m.Conf("runtime", "boot.ctx_bin"), "daemon",
"cmd_dir", p,
"cmd_env", "ctx_home", m.Conf("runtime", "boot.ctx_home"),
"cmd_env", "ctx_box", fmt.Sprintf("http://127.0.0.1%s", m.Conf("runtime", "boot.web_port")),
"cmd_daemon", "true",
)
}
if m.Conf("runtime", "host.GOOS") == "windows" {
m.Cmdy("cli.system", path.Join(m.Conf("runtime", "boot.ctx_home"), "bin/node.sh"), args)
} else {
m.Cmdy("cli.system", m.Conf("runtime", "boot.ctx_bin"), args)
}
return
}},
"version": &ctx.Command{Name: "version", Help: "", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
if len(arg) == 0 {
types := reflect.TypeOf(version)
value := reflect.ValueOf(version)
for i := 0; i < types.NumField(); i++ {
key := types.Field(i)
val := value.Field(i)
m.Add("append", "name", key.Name)
m.Add("append", "type", key.Type.Name())
m.Add("append", "value", fmt.Sprintf("%v", val))
}
m.Table()
return
}
m.Cmd("nfs.save", path.Join(m.Conf("runtime", "boot.ctx_home"), "src/contexts/cli/version.go"), fmt.Sprintf(`package cli
var version = struct {
time string
host string
self int
}{
"%s", "%s", %d,
}
`, m.Time(), m.Conf("runtime", "node.route"), version.self+1))
m.Append("directory", "")
return
}},
"source": &ctx.Command{Name: "source [script|stdio|snippet]", Help: "解析脚本, script: 脚本文件, stdio: 命令终端, snippet: 代码片段", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
if len(arg) == 0 {
m.Cmdy("dir", "", "dir_deep", "dir_reg", ".*\\.(sh|shy|py)$")

View File

@ -4,5 +4,5 @@ var version = struct {
host string
self int
}{
"2019-07-13 14:35:25", "ZYB-20190522USI", 141,
"2019-07-15 02:05:42", "com.mac", 169,
}

View File

@ -8,41 +8,51 @@ import (
"toolkit"
)
func (c *Context) Register(s *Context, x Server, args ...interface{}) {
force := false
func (c *Context) Register(s *Context, x Server, args ...interface{}) *Context {
name, force := s.Name, false
if len(args) > 0 {
switch arg := args[0].(type) {
case bool:
force = arg
case string:
name, s.Name = arg, arg
}
}
if c.contexts == nil {
c.contexts = make(map[string]*Context)
}
if x, ok := c.contexts[s.Name]; ok && !force {
if x, ok := c.contexts[name]; ok && !force {
panic(errors.New(c.Name + "上下文中已存在模块:" + x.Name))
}
c.contexts[s.Name] = s
c.contexts[name] = s
s.context = c
s.Server = x
return s
}
func (c *Context) Plugin(args []string) string {
Index.Register(c, nil)
m := &Message{code: 0, time: time.Now(), source: c, target: c, Meta: map[string][]string{}}
func (c *Context) Plugin(s *Context, args []string) string {
c.Register(s, nil)
m := &Message{code: 0, time: time.Now(), source: s, target: s, Meta: map[string][]string{}}
m.Option("log.disable", true)
if len(args) == 0 {
m.Echo("%s: %s\n\n", c.Name, c.Help)
m.Echo("%s: %s\n\n", s.Name, s.Help)
m.Echo("命令列表:\n")
for k, v := range c.Commands {
for k, v := range s.Commands {
if !strings.HasPrefix(k, "_") {
m.Echo(" %s: %s\n %v\n\n", k, v.Name, v.Help)
}
}
m.Echo("配置列表:\n")
for k, v := range c.Configs {
m.Echo(" %s(%v): %s\n", k, v.Value, v.Help)
for k, v := range s.Configs {
if !strings.HasPrefix(k, "_") {
m.Echo("--%s(%v): %s\n", k, kit.Formats(v.Value), v.Help)
}
}
} else {
if Index.Begin(Pulse, args...); Index.Start(Pulse, args...) {
}
m.Cmd(args)
}
return strings.Join(m.Meta["result"], "")

View File

@ -39,7 +39,6 @@ func (ctx *CTX) Begin(m *Message, arg ...string) Server {
}
func (ctx *CTX) Start(m *Message, arg ...string) bool {
m.Cmd("ctx._init")
kit.Log("fuck", "what")
if m.Optionv("ps_target", Index); len(arg) == 0 {
m.Option("cli.modal", "active")
m.Option("log.disable", false)
@ -47,12 +46,10 @@ func (ctx *CTX) Start(m *Message, arg ...string) bool {
m.Cmd("log._init")
m.Cmd("yac._init")
m.Cmd("gdb._init")
m.Log("fuck", "what")
m.Cmd("cli.source", m.Conf("system", "script.init")).Cmd("cli.source", "stdio").Cmd("cli.source", m.Conf("system", "script.exit"))
} else {
m.Option("cli.modal", "action")
m.Cmd("yac._init")
m.Log("fuck", "what")
// m.Cmd("yac._init")
for _, v := range m.Spawn().Cmd(arg).Meta["result"] {
fmt.Printf("%s", v)
}

View File

@ -1210,12 +1210,58 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
}},
"dir": &ctx.Command{Name: "dir [path [fields...]]", Help: []string{"查看目录, path: 路径, fields...: 查询字段, time|type|full|path|tree|filename|size|line|hash",
"dir_deep: 递归查询", "dir_type both|file|dir|all: 文件类型", "dir_reg reg: 正则表达式", "dir_sort field order: 排序"},
Form: map[string]int{"dir_deep": 0, "dir_type": 1, "dir_reg": 1, "dir_sort": 2},
Form: map[string]int{"dir_deep": 0, "dir_type": 1, "dir_reg": 1, "dir_sort": 2, "dir_sed": -1},
Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
if len(arg) == 0 {
arg = append(arg, "")
}
p := arg[0]
p0 := p + ".tmp0"
p1 := p + ".tmp1"
if args := kit.Trans(m.Optionv("dir_sed")); len(args) > 0 {
if _, e := os.Stat(p1); e == nil {
return e
}
out, e := os.Create(p1)
defer os.Remove(p1)
defer out.Close()
m.Log("info", "open %v", p1)
if _, e := os.Stat(p0); e != nil {
m.Cmd("nfs.copy", p0, p)
}
in, e := os.Open(p0)
defer in.Close()
m.Log("info", "open %v", p0)
switch args[0] {
case "set":
defer os.Rename(p1, p0)
defer os.Remove(p0)
index := kit.Int(args[1])
for bio, i := bufio.NewScanner(in), 0; bio.Scan(); i++ {
if i == index {
out.WriteString(args[2])
} else {
out.WriteString(bio.Text())
}
out.WriteString("\n")
}
return e
case "add":
out0, _ := os.OpenFile(p0, os.O_WRONLY|os.O_APPEND, 0666)
defer out0.Close()
out0.WriteString("\n")
case "put":
defer os.Rename(p0, p)
}
return e
}
wd, e := os.Getwd()
m.Assert(e)
trip := len(wd) + 1
@ -1230,9 +1276,27 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
dir(m, p, 0, kit.Right(m.Has("dir_deep")), m.Confx("dir_type"), trip, rg,
strings.Split(m.Confx("dir_fields", strings.Join(arg[1:], " ")), " "),
m.Conf("time_format"))
} else {
if s.Size() < 100 {
p0 := p + ".tmp0"
f, e := os.Open(p0)
if e != nil {
f, e = os.Open(p)
m.Log("info", "open %v", p)
} else {
p = p0
m.Log("info", "open %v", p0)
}
for bio := bufio.NewScanner(f); bio.Scan(); {
m.Echo(bio.Text())
}
m.Append("file", p)
m.Append("size", s.Size())
m.Append("time", s.ModTime().Format(m.Conf("time_format")))
} else {
m.Append("directory", p)
}
}
return true
}
return false
@ -1247,8 +1311,10 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
m.Echo(v).Echo(" ")
}
} else {
if !m.Appends("file") {
m.Table()
}
}
return
}},
"git": &ctx.Command{Name: "git sum", Help: "版本控制", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {

View File

@ -130,38 +130,37 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
"componet_tmpl": "componet", "componet_view": "componet", "componet_init": "",
"componet_type": "private", "componet_ctx": "cli", "componet_cmd": "project",
"componet_args": []interface{}{}, "inputs": []interface{}{
map[string]interface{}{"type": "select", "name": "cmd", "values": []interface{}{"import"}},
map[string]interface{}{"type": "select", "name": "cmd", "values": []interface{}{"plugin", "stat", "init"}},
map[string]interface{}{"type": "text", "name": "who"},
map[string]interface{}{"type": "button", "value": "执行"},
},
},
map[string]interface{}{"componet_name": "compile", "componet_help": "编译",
"componet_tmpl": "componet", "componet_view": "Compile", "componet_init": "",
"componet_tmpl": "componet", "componet_view": "componet", "componet_init": "",
"componet_type": "private", "componet_ctx": "cli", "componet_cmd": "compile",
"componet_args": []interface{}{}, "inputs": []interface{}{
map[string]interface{}{"type": "select", "name": "action", "values": []interface{}{"windows", "darwin", "linux", "self", "all"}},
map[string]interface{}{"type": "select", "name": "cmd", "values": []interface{}{"plugin", "windows", "darwin", "linux", "self", "all"}},
map[string]interface{}{"type": "text", "name": "who"},
map[string]interface{}{"type": "button", "value": "编译"},
},
"display": map[string]interface{}{"hide_append": true, "show_result": true},
},
map[string]interface{}{"componet_name": "publish", "componet_help": "发布",
"componet_tmpl": "componet", "componet_view": "Compile", "componet_init": "",
"componet_tmpl": "componet", "componet_view": "componet", "componet_init": "",
"componet_type": "private", "componet_ctx": "cli", "componet_cmd": "publish",
"componet_args": []interface{}{}, "inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "action"},
map[string]interface{}{"type": "text", "name": "who"},
map[string]interface{}{"type": "button", "value": "发布"},
},
"display": map[string]interface{}{"hide_append": true, "show_result": true},
},
map[string]interface{}{"componet_name": "upgrade", "componet_help": "升级",
"componet_tmpl": "componet", "componet_view": "Compile", "componet_init": "",
"componet_tmpl": "componet", "componet_view": "componet", "componet_init": "",
"componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route",
"componet_args": []interface{}{"$$", "context", "cli", "upgrade"}, "inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "pod", "imports": "plugin_pod"},
map[string]interface{}{"type": "select", "name": "action", "values": []interface{}{"script", "portal", "system", "plugin", "bench"}},
map[string]interface{}{"type": "text", "name": "action"},
map[string]interface{}{"type": "select", "name": "action", "values": []interface{}{"script", "plugin", "portal", "system", "bench"}},
map[string]interface{}{"type": "text", "name": "who"},
map[string]interface{}{"type": "button", "value": "升级"},
},
"display": map[string]interface{}{"hide_append": true, "show_result": true},
"options": map[string]interface{}{"call_timeout": "180s"},
},
map[string]interface{}{"componet_name": "missyou", "componet_help": "任务",
@ -288,7 +287,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
map[string]interface{}{"type": "button", "value": "查看", "action": "auto"},
map[string]interface{}{"type": "button", "value": "回退", "click": "Back"},
},
"display": map[string]interface{}{"hide_result": true},
"display": map[string]interface{}{"deal": "editor"},
"exports": []interface{}{"dir", "", "dir"},
"dir_root": []interface{}{"/"},
},

View File

@ -54,11 +54,11 @@ var Index = &ctx.Context{Name: "wiki", Help: "文档中心",
},
}, Help: "组件列表"},
"wiki_level": &ctx.Config{Name: "wiki_level", Value: "wiki/自然/编程", Help: "路由数量"},
"wiki_level": &ctx.Config{Name: "wiki_level", Value: "local/wiki/自然/编程", Help: "路由数量"},
"wiki_favor": &ctx.Config{Name: "wiki_favor", Value: "index.md", Help: "路由数量"},
"wiki_visit": &ctx.Config{Name: "wiki_visit", Value: map[string]interface{}{}, Help: "路由数量"},
"wiki_dir": &ctx.Config{Name: "wiki_dir", Value: "wiki", Help: "路由数量"},
"wiki_dir": &ctx.Config{Name: "wiki_dir", Value: "usr/local/wiki", Help: "路由数量"},
"wiki_list": &ctx.Config{Name: "wiki_list", Value: []interface{}{}, Help: "路由数量"},
"wiki_list_show": &ctx.Config{Name: "wiki_list_show", Value: map[string]interface{}{
"md": true,

View File

@ -1,13 +1,16 @@
package main
import (
"contexts/cli"
"contexts/ctx"
_ "contexts/nfs"
"toolkit"
"fmt"
"math"
"math/rand"
"os"
"strings"
"toolkit"
)
func Merge(left []int, right []int) []int {
@ -55,10 +58,21 @@ func QuickSort(m *ctx.Message, level int, data []int, left int, right int) {
}
var Index = &ctx.Context{Name: "sort", Help: "sort code",
Caches: map[string]*ctx.Cache{},
Configs: map[string]*ctx.Config{
"data": &ctx.Config{Name: "data", Value: map[string]interface{}{
"seed": []int{47, 59, 81, 40, 56, 0, 94, 11, 18, 25},
}},
"index": &ctx.Config{Name: "index", Value: []interface{}{
map[string]interface{}{"componet_name": "select", "componet_help": "选择排序",
"componet_tmpl": "componet", "componet_view": "componet", "componet_init": "",
"componet_type": "public", "componet_ctx": "sort", "componet_cmd": "select",
"componet_args": []interface{}{}, "inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "pod", "imports": "plugin_pod"},
map[string]interface{}{"type": "button", "value": "执行"},
},
},
}},
},
Commands: map[string]*ctx.Command{
"_init": &ctx.Command{Name: "_init", Help: "_init", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
@ -180,5 +194,5 @@ var Index = &ctx.Context{Name: "sort", Help: "sort code",
}
func main() {
fmt.Print(Index.Plugin(os.Args[1:]))
fmt.Print(cli.Index.Plugin(Index, os.Args[1:]))
}

View File

@ -1,18 +1,20 @@
package main
import (
"runtime"
"contexts/cli"
"contexts/ctx"
"toolkit"
"bufio"
"bytes"
"encoding/json"
"fmt"
"contexts/ctx"
kit "toolkit"
"io"
"io/ioutil"
"net/http"
"os"
"path"
"runtime"
"strings"
"sync"
"sync/atomic"
@ -131,6 +133,18 @@ var Index = &ctx.Context{Name: "test", Help: "测试工具",
"timeout": {Name: "timeout", Help: "请求超时", Value: "10s"},
"prefix0": {Name: "prefix0", Help: "请求前缀", Value: "uri["},
"prefix1": {Name: "prefix1", Help: "参数前缀", Value: "request_param["},
"index": &ctx.Config{Name: "index", Value: []interface{}{
map[string]interface{}{"componet_name": "status", "componet_help": "状态",
"componet_tmpl": "componet", "componet_view": "Company", "componet_init": "",
"componet_type": "private", "componet_ctx": "test", "componet_cmd": "diff",
"componet_args": []interface{}{}, "inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "pod", "imports": "plugin_pod"},
map[string]interface{}{"type": "select", "name": "sub", "values": []interface{}{"status", ""}},
map[string]interface{}{"type": "button", "value": "执行"},
},
},
}},
},
Commands: map[string]*ctx.Command{
"diff": {Name: "diff file server1 server2", Form: map[string]int{"nsleep": 1}, Help: "接口对比工具", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
@ -273,7 +287,7 @@ var Index = &ctx.Context{Name: "test", Help: "测试工具",
}},
},
}
func main() {
kit.DisableLog = true
fmt.Print(Index.Plugin(os.Args[1:]))
fmt.Print(cli.Index.Plugin(Index, os.Args[1:]))
}

View File

@ -83,6 +83,18 @@ fieldset>div.output table td {
word-break:keep-all;
min-width:40px;
}
fieldset>div.output>table.edit {
}
fieldset>div.output>table.edit td {
min-width:4px;
padding:0px;
}
fieldset>div.output>table.edit td>input {
width:600px;
padding:0px;
}
fieldset>div.output table.edit {
}
fieldset.toast {
border:solid 2px red;

View File

@ -754,6 +754,41 @@ function Plugin(page, pane, field) {
},
ondaemon: {
editor: function(msg, cb) {
output.innerHTML = ""
!display.hide_append && msg.append && kit.OrderTable(kit.AppendTable(kit.AppendChild(output, "table"), ctx.Table(msg), msg.append), exports[1], function(event, value, name, line) {
page.Sync("plugin_"+exports[0]).set(plugin.onexport[exports[2]||""](value, name, line))
});
var args = [option.pod.value, option.dir.value]
if (msg.file) {
var action = kit.AppendAction(kit.AppendChild(output, [{view: ["action"]}]).last, [
"追加", "提交", "取消",
], function(value, event) {
switch (value) {
case "追加":
field.Run(event, args.concat(["dir_sed", "add"]))
break
case "提交":
field.Run(event, args.concat(["dir_sed", "put"]))
break
case "取消":
break
}
})
kit.AppendChild(output, [{view: ["edit", "table"], list: msg.result.map(function(value, index) {
return {view: ["line", "tr"], list: [{view: ["num", "td", index+1]}, {view: ["txt", "td"], list: [{value: value, input: [value, function(event) {
if (event.key == "Enter") {
field.Run(event, args.concat(["dir_sed", "set", index, event.target.value]))
}
}]}]}]}
})}])
}
typeof cb == "function" && cb(msg)
},
table: function(msg, cb) {
output.innerHTML = ""
!display.hide_append && msg.append && kit.OrderTable(kit.AppendTable(kit.AppendChild(output, "table"), ctx.Table(msg), msg.append), exports[1], function(event, value, name, line) {
@ -819,14 +854,8 @@ function Plugin(page, pane, field) {
return value
}
var deal = display.deal
var back = option.dir.value
display.deal = "void"
option.dir.value = value
plugin.Runs(window.event, function() {
display.deal = deal
option.dir.value = back
})
plugin.Runs(window.event)
},
},
display: function(arg) {

33
usr/local/wiki/index.md Normal file
View File

@ -0,0 +1,33 @@
天行健,君子以自强不息
|--------|----|----|----|--------|----|----|----|--------|----|----|----|
|--------|----|----|----|--------|----|----|----|--------|----|----|----|
|**人文**|感性|理性|灵性|**社会**|行业|企业|产业|**自然**|微观|宏观|宇观|
|**哲学**|世界|价值|人生|**史学**|经济|政治|文化|**科学**|实验|理论|方程|
|--------|----|----|----|--------|----|----|----|--------|----|----|----|
|**意识**|生活|工作|学习|**意志**|学位|职位|地位|**意义**|问题|难题|课题|
|**欲望**|幸福|财富|智慧|**缘份**|同学|同事|同行|**成就**|创造|创新|创始|
|--------|----|----|----|--------|----|----|----|--------|----|----|----|
|**做人**|随缘|随性|随心|**做事**|交易|交流|交情|**做学**|多做|多看|多想|
|**教育**|习惯|信用|道德|**资本**|资源|资格|资历|**工程**|技术|学术|艺术|
|--------|----|----|----|--------|----|----|----|--------|----|----|----|
|--------|----|----|----|--------|----|----|----|--------|----|----|----|
|--------|----|----|----|--------|----|----|----|--------|----|----|----|
|**精神**|需求|追求|要求|**历史**|英雄|家族|阶级|**宇宙**|天文|气象|地质|
|**语言**|词汇|语法|语义|**经济**|生产|市场|消费|**物理**|物质|能量|信息|
|**文学**|散文|诗歌|小说|**政治**|外交|法制|民生|**数学**|代数|函数|几何|
|**艺术**|音乐|美术|体育|**军事**|战略|战术|战争|**生命**|基因|组织|系统|
|--------|----|----|----|--------|----|----|----|--------|----|----|----|
|**信仰**|科学|民主|自由|**人际**|心理|伦理|道理|**传感**|属性|关系|规律|
|**表达**|意识|情感|意志|**管理**|物力|人力|才力|**编程**|语言|框架|平台|
|**修养**|益智|怡情|养性|**物流**|交通|管道|电信|**控制**|过程|状态|特征|
|**阅读**|摘要|情节|典故|**金融**|基金|股票|保险|**设计**|功能|性能|智能|
|--------|----|----|----|--------|----|----|----|--------|----|----|----|
|**黑客**|博学|博识|博爱|**总裁**|路线|方针|政策|**建筑**|地基|栋梁|装饰|
|**读者**|搜集|检索|查阅|**经理**|客户|产品|服务|**机械**|原动|传动|制动|
|**朋友**|相识|相知|相交|**总监**|行情|行规|行家|**电子**|输入|处理|输出|
|**演讲**|论点|论据|论证|**董事**|提案|表决|监督|**电脑**|硬件|软件|文件|
|--------|----|----|----|--------|----|----|----|--------|----|----|----|
地势坤,君子以厚德载物

View File

@ -0,0 +1,79 @@
# Common builder
ARG GO_IMAGE
FROM ${GO_IMAGE} as builder
COPY hack/dockerfile/install/tini.installer /
COPY hack/dockerfile/install/proxy.installer /
RUN apt-get update && apt-get install -y \
bash \
btrfs-tools \
ca-certificates \
cmake \
gcc \
git \
libc-dev \
libgcc-6-dev \
libltdl-dev \
libtool \
make
RUN grep "_COMMIT=" /*.installer |cut -f2- -d: > /binaries-commits
# dockerd
FROM builder as dockerd-builder
WORKDIR /go/src/github.com/docker/docker
COPY . /go/src/github.com/docker/docker
ARG VERSION
ARG GITCOMMIT
ARG BUILDTIME
ARG PLATFORM
ARG PRODUCT
ARG DEFAULT_PRODUCT_LICENSE
ENV VERSION ${VERSION}
ENV GITCOMMIT ${GITCOMMIT}
ENV BUILDTIME ${BUILDTIME}
ENV PLATFORM ${PLATFORM}
ENV PRODUCT ${PRODUCT}
ENV DEFAULT_PRODUCT_LICENSE ${DEFAULT_PRODUCT_LICENSE}
# TODO The way we set the version could easily be simplified not to depend on hack/...
RUN bash ./hack/make/.go-autogen
RUN go build -o /sbin/dockerd \
-tags 'autogen netgo static_build selinux journald' \
-installsuffix netgo -a -buildmode=pie -ldflags '-w -extldflags "-static" ' \
github.com/docker/docker/cmd/dockerd
# docker-proxy
# TODO if libnetwork folds into the docker tree this can be combined above
FROM builder as proxy-builder
RUN git clone https://github.com/docker/libnetwork.git /go/src/github.com/docker/libnetwork
WORKDIR /go/src/github.com/docker/libnetwork
RUN . /binaries-commits && \
git checkout -q "$LIBNETWORK_COMMIT" && \
CGO_ENABLED=0 go build -buildmode=pie -ldflags="$PROXY_LDFLAGS" \
-o /sbin/docker-proxy \
github.com/docker/libnetwork/cmd/proxy
# docker-init - TODO move this out, last time we bumped was 2016!
FROM builder as init-builder
RUN git clone https://github.com/krallin/tini.git /tini
WORKDIR /tini
RUN . /binaries-commits && \
git checkout -q "$TINI_COMMIT" && \
cmake . && make tini-static && \
cp tini-static /sbin/docker-init
# runc
FROM builder as runc-builder
RUN apt-get install -y libseccomp-dev
RUN git clone https://github.com/opencontainers/runc.git /go/src/github.com/opencontainers/runc
WORKDIR /go/src/github.com/opencontainers/runc
RUN . /binaries-commits && \
git checkout -q "$RUNC_COMMIT" && \
make BUILDTAGS='seccomp apparmor' static && make install
# Final docker image
FROM scratch
COPY --from=dockerd-builder /sbin/dockerd /sbin/
COPY --from=proxy-builder /sbin/docker-proxy /sbin/
COPY --from=init-builder /sbin/docker-init /sbin/
COPY --from=runc-builder /usr/local/sbin/runc /sbin/
ENTRYPOINT ["/sbin/dockerd"]

@ -0,0 +1 @@
Subproject commit 007921611b04d8fca5ad0b1d4e7b0461b47cd435

3
why.go
View File

@ -1,3 +0,0 @@
package main
func main() {}