diff --git a/src/contexts/cli/cli.go b/src/contexts/cli/cli.go index d48ce742..421fc1b5 100644 --- a/src/contexts/cli/cli.go +++ b/src/contexts/cli/cli.go @@ -327,7 +327,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心", t := time.Now() // {{{ if m.Options("parse") { f := "2006-01-02 15:04:05" - n, e := time.Parse(f, m.Option("parse")) + n, e := time.ParseInLocation(f, m.Option("parse"), time.Local) m.Assert(e) t = n } diff --git a/src/contexts/ctx.go b/src/contexts/ctx.go index 747833f4..b762e7bd 100644 --- a/src/contexts/ctx.go +++ b/src/contexts/ctx.go @@ -2363,7 +2363,7 @@ var Index = &Context{Name: "ctx", Help: "模块中心", // }}} }}, "command": &Command{Name: "command [all] add [key [name help]]", Help: "查看或修改命令", - Formats: map[string]int{"all": 0, "delete": 0, "void": 0}, + Formats: map[string]int{"all": 0, "delete": 0, "void": 0, "condition": -1}, Hand: func(m *Message, c *Context, key string, arg ...string) { all := m.Has("all") // {{{ if len(arg) == 0 { @@ -2417,12 +2417,61 @@ var Index = &Context{Name: "ctx", Help: "模块中心", m.Capi("part", 1) return case "list": - for i := 0; i < m.Capi("part"); i++ { + begin, end := 0, m.Capi("part") + if len(arg) > 1 { + n, e := strconv.Atoi(arg[1]) + m.Assert(e) + begin = n + } + if len(arg) > 2 { + n, e := strconv.Atoi(arg[2]) + m.Assert(e) + end = n + } + for i := begin; i < end; i++ { if c, ok := m.target.Commands[fmt.Sprintf("%d", i)]; ok { m.Echo("%d: %s\n", i, c.Name) } } return + case "test": + begin, end := 0, m.Capi("part") + if len(arg) > 1 { + n, e := strconv.Atoi(arg[1]) + m.Assert(e) + begin = n + } + if len(arg) > 2 { + n, e := strconv.Atoi(arg[2]) + m.Assert(e) + end = n + } + success, failure := 0, 0 + for i := begin; i < end; i++ { + key := fmt.Sprintf("%d", i) + if c, ok := m.target.Commands[key]; ok { + msg := m.Spawn(m.Target()) + msg.Cmd(key) + if m.Options("condition") { + condition := m.Meta["condition"] + done := true + for j := 0; j < len(condition)-1; j += 2 { + if !msg.Has(condition[j]) || msg.Append(condition[j]) != condition[j+1] { + m.Echo("\033[31m%s %s %s\033[0m\n", key, " fail", c.Name) + failure++ + done = false + } + } + if done { + // m.Echo("%s %s\n", key, " done") + m.Echo("%s %s %s\n", key, " done", c.Name) + success++ + } + } + } + } + m.Echo("\033[32msuccess: %d\033[0m, \033[31mfailure: %d\033[0m, \033[33mtotal: %d\033[0m", success, failure, success+failure) + return } switch len(arg) { diff --git a/src/contexts/web/web.go b/src/contexts/web/web.go index 51065ba1..91e29292 100644 --- a/src/contexts/web/web.go +++ b/src/contexts/web/web.go @@ -494,7 +494,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", io.Copy(part, file) for i := 0; i < len(arg)-1; i += 2 { - writer.WriteField(arg[0], arg[1]) + writer.WriteField(arg[i], arg[i]) } contenttype = writer.FormDataContentType() @@ -553,7 +553,25 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", buf, e := ioutil.ReadAll(res.Body) m.Assert(e) - m.Echo(string(buf)) + + if res.Header.Get("Content-Type") == "application/json" { + result := map[string]interface{}{} + json.Unmarshal(buf, &result) + for k, v := range result { + switch value := v.(type) { + case string: + m.Append(k, value) + case float64: + m.Append(k, fmt.Sprintf("%d", int(value))) + default: + m.Put("append", k, value) + } + } + } + + result := string(buf) + m.Echo(result) + m.Append("response", result) // }}} }}, "list": &ctx.Command{Name: "list [set|add|del [url]]", Help: "查看、访问、添加url", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {