forked from x/ContextOS
add cli.system.cmd_parse
Change-Id: I32b4a6361a0b07962ccd1838fab2cfca3695e24e
This commit is contained in:
parent
ce777bdad2
commit
62cb4c8cac
@ -1,7 +1,9 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"contexts/ctx"
|
||||
"encoding/csv"
|
||||
"path"
|
||||
"toolkit"
|
||||
|
||||
@ -774,7 +776,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
||||
}},
|
||||
"system": &ctx.Command{Name: "system word...", Help: []string{"调用系统命令, word: 命令",
|
||||
"cmd_active(true/false): 是否交互", "cmd_timeout: 命令超时", "cmd_env: 环境变量", "cmd_dir: 工作目录"},
|
||||
Form: map[string]int{"cmd_active": 1, "cmd_timeout": 1, "cmd_env": 2, "cmd_dir": 1, "cmd_error": 0},
|
||||
Form: map[string]int{"cmd_active": 1, "cmd_timeout": 1, "cmd_env": 2, "cmd_dir": 1, "cmd_error": 0, "cmd_parse": 1},
|
||||
Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||
if len(m.Meta["result"]) > 0 {
|
||||
for _, v := range m.Meta["result"] {
|
||||
@ -855,8 +857,21 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
||||
m.Echo("error: ").Echo("%s\n", e)
|
||||
m.Echo("%s\n", string(out))
|
||||
} else {
|
||||
switch m.Option("cmd_parse") {
|
||||
case "csv":
|
||||
data, e := csv.NewReader(bytes.NewReader(out)).ReadAll()
|
||||
m.Assert(e)
|
||||
for i := 1; i < len(data); i++ {
|
||||
for j := 0; j < len(data[i]); j++ {
|
||||
m.Add("append", data[0][j], data[i][j])
|
||||
}
|
||||
}
|
||||
m.Table()
|
||||
default:
|
||||
m.Echo(string(out))
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
wait <- true
|
||||
}()
|
||||
|
@ -2253,10 +2253,26 @@ var CGI = template.FuncMap{
|
||||
}
|
||||
return []interface{}{}
|
||||
},
|
||||
|
||||
"slice": func(list interface{}, arg ...interface{}) interface{} {
|
||||
switch l := list.(type) {
|
||||
case string:
|
||||
if len(arg) == 0 {
|
||||
return l
|
||||
}
|
||||
if len(arg) == 1 {
|
||||
return l[arg[0].(int):]
|
||||
}
|
||||
if len(arg) == 2 {
|
||||
return l[arg[0].(int):arg[1].(int)]
|
||||
}
|
||||
}
|
||||
|
||||
return ""
|
||||
},
|
||||
"unescape": func(str string) interface{} {
|
||||
return template.HTML(str)
|
||||
},
|
||||
|
||||
"json": func(arg ...interface{}) interface{} {
|
||||
if len(arg) == 0 {
|
||||
return ""
|
||||
@ -2265,7 +2281,6 @@ var CGI = template.FuncMap{
|
||||
b, _ := json.Marshal(arg[0])
|
||||
return string(b)
|
||||
},
|
||||
|
||||
"list": func(arg interface{}) interface{} {
|
||||
n := 0
|
||||
switch v := arg.(type) {
|
||||
|
@ -890,6 +890,21 @@ function init_docker() {
|
||||
})
|
||||
location.reload()
|
||||
return
|
||||
case "remove_fly":
|
||||
context.GET("", {
|
||||
"componet_bench": context.Search("bench"),
|
||||
"componet_group": "index",
|
||||
"componet_name": "command",
|
||||
"cmd": "~code bench delete "+context.Search("bench"),
|
||||
})
|
||||
var b = ""
|
||||
document.querySelectorAll("div.workflow>ul.docker>li>ul.fly>li[data-key]").forEach(function(item){
|
||||
if (!b && item.dataset["key"] != context.Search("bench")) {
|
||||
b = item.dataset["key"]
|
||||
}
|
||||
})
|
||||
context.Search("bench", b)
|
||||
return
|
||||
}
|
||||
|
||||
// 切换工作流
|
||||
|
@ -181,10 +181,11 @@
|
||||
{{range $key, $item := conf . "bench"}}
|
||||
{{$creator := index $item "creator"}}
|
||||
{{if eq $creator $username}}
|
||||
<li data-key="{{$key}}">{{index $item "modify_time"}} {{index $item "comment"}}({{index $item "creator"}})</li>
|
||||
<li data-key="{{$key}}">{{index $item "modify_time"}} {{index $item "comment"}}({{slice $key 0 6}})</li>
|
||||
{{end}}
|
||||
{{end}}
|
||||
<li data-action="rename_fly">+ 命名工作流</li>
|
||||
<li data-action="remove_fly">+ 删除工作流</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
Loading…
x
Reference in New Issue
Block a user