1
0
forked from x/ContextOS

add cli.system.cmd_parse

Change-Id: I32b4a6361a0b07962ccd1838fab2cfca3695e24e
This commit is contained in:
shaoying 2018-12-10 23:32:31 +08:00
parent ce777bdad2
commit 62cb4c8cac
4 changed files with 51 additions and 5 deletions

View File

@ -1,7 +1,9 @@
package cli package cli
import ( import (
"bytes"
"contexts/ctx" "contexts/ctx"
"encoding/csv"
"path" "path"
"toolkit" "toolkit"
@ -774,7 +776,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
}}, }},
"system": &ctx.Command{Name: "system word...", Help: []string{"调用系统命令, word: 命令", "system": &ctx.Command{Name: "system word...", Help: []string{"调用系统命令, word: 命令",
"cmd_active(true/false): 是否交互", "cmd_timeout: 命令超时", "cmd_env: 环境变量", "cmd_dir: 工作目录"}, "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) { Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
if len(m.Meta["result"]) > 0 { if len(m.Meta["result"]) > 0 {
for _, v := range m.Meta["result"] { 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("error: ").Echo("%s\n", e)
m.Echo("%s\n", string(out)) m.Echo("%s\n", string(out))
} else { } 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)) m.Echo(string(out))
} }
}
} }
wait <- true wait <- true
}() }()

View File

@ -2253,10 +2253,26 @@ var CGI = template.FuncMap{
} }
return []interface{}{} 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{} { "unescape": func(str string) interface{} {
return template.HTML(str) return template.HTML(str)
}, },
"json": func(arg ...interface{}) interface{} { "json": func(arg ...interface{}) interface{} {
if len(arg) == 0 { if len(arg) == 0 {
return "" return ""
@ -2265,7 +2281,6 @@ var CGI = template.FuncMap{
b, _ := json.Marshal(arg[0]) b, _ := json.Marshal(arg[0])
return string(b) return string(b)
}, },
"list": func(arg interface{}) interface{} { "list": func(arg interface{}) interface{} {
n := 0 n := 0
switch v := arg.(type) { switch v := arg.(type) {

View File

@ -890,6 +890,21 @@ function init_docker() {
}) })
location.reload() location.reload()
return 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
} }
// 切换工作流 // 切换工作流

View File

@ -181,10 +181,11 @@
{{range $key, $item := conf . "bench"}} {{range $key, $item := conf . "bench"}}
{{$creator := index $item "creator"}} {{$creator := index $item "creator"}}
{{if eq $creator $username}} {{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}}
{{end}} {{end}}
<li data-action="rename_fly">+ 命名工作流</li> <li data-action="rename_fly">+ 命名工作流</li>
<li data-action="remove_fly">+ 删除工作流</li>
</ul> </ul>
</li> </li>
</ul> </ul>