mirror of
https://shylinux.com/x/ContextOS
synced 2025-04-25 08:48:06 +08:00
add nfs.template
This commit is contained in:
parent
a58ece0f72
commit
dd200672cb
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,3 +1,5 @@
|
||||
error.log
|
||||
usr/publish
|
||||
var/
|
||||
pkg/
|
||||
*.swp
|
||||
|
@ -9,7 +9,6 @@ import (
|
||||
"encoding/csv"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/user"
|
||||
@ -163,8 +162,11 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
||||
"project": &ctx.Config{Name: "project", Value: map[string]interface{}{
|
||||
"github": "https://github.com/shylinux/context",
|
||||
"goproxy": "https://goproxy.cn",
|
||||
"template": map[string]interface{}{
|
||||
"path": "usr/template",
|
||||
},
|
||||
"plugin": map[string]interface{}{
|
||||
"path": "src/plugin", "list": Template,
|
||||
"path": "src/plugin", "template": "usr/template/plugin",
|
||||
}, "script": map[string]interface{}{
|
||||
"path": "usr/script",
|
||||
}, "trash": map[string]interface{}{
|
||||
@ -887,15 +889,9 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
||||
}
|
||||
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", "line", "hashs", "path")
|
||||
m.Option("name", arg[0])
|
||||
m.Option("help", kit.Select("plugin", arg, 1))
|
||||
m.Cmdy("nfs.template", path.Join(m.Conf("project", "plugin.path"), arg[0])+"/", path.Join(m.Conf("project", "plugin.template"))+"/")
|
||||
}
|
||||
return
|
||||
}},
|
||||
@ -1228,17 +1224,11 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
||||
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", "")
|
||||
m.Option("time", m.Time())
|
||||
m.Option("host", m.Conf("runtime", "node.route"))
|
||||
m.Option("self", version.self+1)
|
||||
m.Cmdy("nfs.template", "force", path.Join(m.Conf("runtime", "boot.ctx_home"), "src/contexts/cli/version.go"), path.Join(m.Conf("project", "template.path"), "version/"))
|
||||
return
|
||||
}},
|
||||
},
|
||||
|
@ -1,8 +1,11 @@
|
||||
package cli
|
||||
|
||||
var version = struct {
|
||||
init []string
|
||||
time string
|
||||
host string
|
||||
self int
|
||||
}{
|
||||
"2019-09-28 15:18:05", "mac", 611,
|
||||
[]string{"2017-11-01 01:02:03", "2019-07-13 18:02:21"},
|
||||
`2019-09-29 17:30:47`, `centos`, 612,
|
||||
}
|
||||
|
@ -2,6 +2,8 @@ package ctx
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"io"
|
||||
"path"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@ -85,3 +87,9 @@ var CGI = template.FuncMap{
|
||||
return ""
|
||||
},
|
||||
}
|
||||
|
||||
func ExecuteFile(m *Message, w io.Writer, p string) error {
|
||||
tmpl := template.New("render").Funcs(CGI)
|
||||
tmpl.ParseGlob(p)
|
||||
return tmpl.ExecuteTemplate(w, path.Base(p), m)
|
||||
}
|
||||
|
@ -799,6 +799,38 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
|
||||
return
|
||||
}},
|
||||
|
||||
"template": &ctx.Command{Name: "template [force] target source...", Help: "生成模板", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
force := false
|
||||
if arg[0] == "force" {
|
||||
force, arg = true, arg[1:]
|
||||
}
|
||||
|
||||
if _, e := os.Stat(arg[0]); os.IsNotExist(e) || force {
|
||||
if strings.HasSuffix(arg[0], "/") && m.Assert(os.MkdirAll(arg[0], 0777)) {
|
||||
|
||||
kit.List(arg[1:], func(p string) {
|
||||
m.Cmd("nfs.dir", p, "name", "path").Table(func(line map[string]string) {
|
||||
if w, _, e := kit.Create(path.Join(arg[0], line["name"])); m.Assert(e) {
|
||||
defer w.Close()
|
||||
|
||||
m.Assert(ctx.ExecuteFile(m, w, line["path"]))
|
||||
}
|
||||
})
|
||||
})
|
||||
} else if w, _, e := kit.Create(arg[0]); m.Assert(e) {
|
||||
defer w.Close()
|
||||
|
||||
kit.List(arg[1:], func(p string) {
|
||||
m.Cmd("nfs.dir", p).Table(func(line map[string]string) {
|
||||
m.Assert(ctx.ExecuteFile(m, w, line["path"]))
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
m.Cmdy("nfs.dir", arg[0], "time", "line", "hashs", "path")
|
||||
return
|
||||
}},
|
||||
"temp": &ctx.Command{Name: "temp data", Help: "查找文件路径", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
if f, p, e := kit.Create(path.Join(m.Conf("dir", "temp"), kit.Hashs(arg[0]))); m.Assert(e) {
|
||||
defer f.Close()
|
||||
|
@ -206,3 +206,15 @@ func Linex(p string) map[string]string {
|
||||
})
|
||||
return meta
|
||||
}
|
||||
|
||||
func List(arg interface{}, cb interface{}) {
|
||||
list := Trans(arg)
|
||||
for i, v := range list {
|
||||
switch cb := cb.(type) {
|
||||
case func(string):
|
||||
cb(v)
|
||||
case func(string, int):
|
||||
cb(v, i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
3
usr/template/plugin/index.css
Normal file
3
usr/template/plugin/index.css
Normal file
@ -0,0 +1,3 @@
|
||||
fieldset.item.{{options . "name"}} div.output {
|
||||
}
|
||||
|
@ -1,8 +1,4 @@
|
||||
package cli
|
||||
|
||||
var Template = []interface{}{
|
||||
map[string]interface{}{"name": "index.go", "text":
|
||||
`package main
|
||||
package main
|
||||
|
||||
import (
|
||||
"contexts/cli"
|
||||
@ -13,7 +9,7 @@ import (
|
||||
"os"
|
||||
)
|
||||
|
||||
var Index = &ctx.Context{Name: "test", Help: "测试工具",
|
||||
var Index = &ctx.Context{Name: `{{options . "name"}}`, Help: `{{options . "help"}}`,
|
||||
Caches: map[string]*ctx.Cache{},
|
||||
Configs: map[string]*ctx.Config{
|
||||
"_index": &ctx.Config{Name: "index", Value: []interface{}{
|
||||
@ -38,20 +34,3 @@ var Index = &ctx.Context{Name: "test", Help: "测试工具",
|
||||
func main() {
|
||||
fmt.Print(cli.Index.Plugin(Index, os.Args[1:]))
|
||||
}
|
||||
`}, map[string]interface{}{"name": "index.shy", "text":
|
||||
`fun hello world "" "" public \
|
||||
text "" \
|
||||
button "执行"
|
||||
copy pwd
|
||||
end
|
||||
`}, map[string]interface{}{"name": "index.css", "text":
|
||||
`fieldset.item.demo div.output {
|
||||
}
|
||||
`}, map[string]interface{}{"name": "index.js", "text":
|
||||
`{init: function(run, field, option, output) {
|
||||
kit.Log("hello world")
|
||||
return {}
|
||||
}}
|
||||
`}, map[string]interface{}{"name": "local.shy", "text":
|
||||
``},
|
||||
}
|
5
usr/template/plugin/index.js
Normal file
5
usr/template/plugin/index.js
Normal file
@ -0,0 +1,5 @@
|
||||
{init: function(run, field, option, output) {
|
||||
kit.Log("hello world")
|
||||
return {}
|
||||
}}
|
||||
|
6
usr/template/plugin/index.shy
Normal file
6
usr/template/plugin/index.shy
Normal file
@ -0,0 +1,6 @@
|
||||
fun hello world "" "" public \
|
||||
text "" \
|
||||
button "执行"
|
||||
copy pwd
|
||||
|
||||
end
|
11
usr/template/version/version.go
Normal file
11
usr/template/version/version.go
Normal file
@ -0,0 +1,11 @@
|
||||
package cli
|
||||
|
||||
var version = struct {
|
||||
init []string
|
||||
time string
|
||||
host string
|
||||
self int
|
||||
}{
|
||||
[]string{"2017-11-01 01:02:03", "2019-07-13 18:02:21"},
|
||||
`{{options . "time"}}`, `{{options . "host"}}`, {{options . "self"}},
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user