From 62cb4c8cacdb21067479662b99b9429fcb6d4d7f Mon Sep 17 00:00:00 2001 From: shaoying Date: Mon, 10 Dec 2018 23:32:31 +0800 Subject: [PATCH] add cli.system.cmd_parse Change-Id: I32b4a6361a0b07962ccd1838fab2cfca3695e24e --- src/contexts/cli/cli.go | 19 +++++++++++++++++-- src/contexts/ctx/ctx.go | 19 +++++++++++++++++-- usr/librarys/code.js | 15 +++++++++++++++ usr/template/code/code.tmpl | 3 ++- 4 files changed, 51 insertions(+), 5 deletions(-) diff --git a/src/contexts/cli/cli.go b/src/contexts/cli/cli.go index d87124b8..87e9154c 100644 --- a/src/contexts/cli/cli.go +++ b/src/contexts/cli/cli.go @@ -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,7 +857,20 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心", m.Echo("error: ").Echo("%s\n", e) m.Echo("%s\n", string(out)) } else { - m.Echo(string(out)) + 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 diff --git a/src/contexts/ctx/ctx.go b/src/contexts/ctx/ctx.go index 656120d8..6df18e12 100644 --- a/src/contexts/ctx/ctx.go +++ b/src/contexts/ctx/ctx.go @@ -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) { diff --git a/usr/librarys/code.js b/usr/librarys/code.js index b9f709c8..2ffb3803 100644 --- a/usr/librarys/code.js +++ b/usr/librarys/code.js @@ -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 } // 切换工作流 diff --git a/usr/template/code/code.tmpl b/usr/template/code/code.tmpl index 2d6aef3d..e1148bfb 100644 --- a/usr/template/code/code.tmpl +++ b/usr/template/code/code.tmpl @@ -181,10 +181,11 @@ {{range $key, $item := conf . "bench"}} {{$creator := index $item "creator"}} {{if eq $creator $username}} -
  • {{index $item "modify_time"}} {{index $item "comment"}}({{index $item "creator"}})
  • +
  • {{index $item "modify_time"}} {{index $item "comment"}}({{slice $key 0 6}})
  • {{end}} {{end}}
  • + 命名工作流
  • +
  • + 删除工作流