From ff7d5381f9a0dea7bdd268d129cce9c336258744 Mon Sep 17 00:00:00 2001 From: Aaron Chen <462826@qq.com> Date: Tue, 3 Sep 2019 21:39:52 +0800 Subject: [PATCH] code refactoring for exe logic --- res/messages_en.json | 10 ++++++++++ res/messages_zh.json | 10 ++++++++++ src/service/zentao/account.go | 6 ++++-- src/service/zentao/testcase.go | 15 +++++++++++---- src/utils/stdin/stdin.go | 10 ++++++++++ 5 files changed, 45 insertions(+), 6 deletions(-) diff --git a/res/messages_en.json b/res/messages_en.json index a7d9320c..42afbbcc 100644 --- a/res/messages_en.json +++ b/res/messages_en.json @@ -21,6 +21,16 @@ "message": "result", "translation": "result" }, + { + "id": "want_to_continue", + "message": "", + "translation": "Do you want to continue[Y/n]?" + }, + { + "id": "case_update_confirm", + "message": "", + "translation": "Will update case as below:\n Title: %s" + }, { "id": "enter_dir", "message": "enter dir", diff --git a/res/messages_zh.json b/res/messages_zh.json index 28199223..87e8a2c6 100644 --- a/res/messages_zh.json +++ b/res/messages_zh.json @@ -21,6 +21,16 @@ "message": "result", "translation": "结果" }, + { + "id": "want_to_continue", + "message": "", + "translation": "确认继续[Y/n]?" + }, + { + "id": "case_update_confirm", + "message": "", + "translation": "以下用例信息将被更新:\n 标题: %s" + }, { "id": "enter_dir", "message": "enter dir", diff --git a/src/service/zentao/account.go b/src/service/zentao/account.go index 8c02d807..1f488f15 100644 --- a/src/service/zentao/account.go +++ b/src/service/zentao/account.go @@ -25,8 +25,10 @@ func Login(baseUrl string, account string, password string) bool { var log string _, ok = client.PostStr(url, params) if ok { - log = i118Utils.I118Prt.Sprintf("success_to_login") - logUtils.PrintToCmd(log, -1) + if vari.Verbose { + log = i118Utils.I118Prt.Sprintf("success_to_login") + logUtils.PrintToCmd(log, -1) + } } else { log = i118Utils.I118Prt.Sprintf("fail_to_login") logUtils.PrintToCmd(log, color.FgRed) diff --git a/src/service/zentao/testcase.go b/src/service/zentao/testcase.go index 41958b0a..ba417983 100644 --- a/src/service/zentao/testcase.go +++ b/src/service/zentao/testcase.go @@ -8,6 +8,7 @@ import ( configUtils "github.com/easysoft/zentaoatf/src/utils/config" i118Utils "github.com/easysoft/zentaoatf/src/utils/i118" logUtils "github.com/easysoft/zentaoatf/src/utils/log" + stdinUtils "github.com/easysoft/zentaoatf/src/utils/stdin" "github.com/easysoft/zentaoatf/src/utils/zentao" "sort" "strconv" @@ -217,10 +218,16 @@ func CommitCase(caseId int, title string) { uri := fmt.Sprintf("testcase-edit-%d.json", caseId) requestObj := map[string]interface{}{"title": title} - url := config.Url + uri - _, ok = client.PostObject(url, requestObj) + var yes bool + logUtils.PrintToStdOut("\n"+i118Utils.I118Prt.Sprintf("case_update_confirm", title), -1) + stdinUtils.InputForBool(&yes, "want_to_continue") - if ok { - logUtils.PrintToStdOut(i118Utils.I118Prt.Sprintf("success_to_commit_case", caseId)+"\n", -1) + if yes { + url := config.Url + uri + _, ok = client.PostObject(url, requestObj) + + if ok { + logUtils.PrintToStdOut(i118Utils.I118Prt.Sprintf("success_to_commit_case", caseId)+"\n", -1) + } } } diff --git a/src/utils/stdin/stdin.go b/src/utils/stdin/stdin.go index 8d3c3085..175e61d2 100644 --- a/src/utils/stdin/stdin.go +++ b/src/utils/stdin/stdin.go @@ -117,6 +117,16 @@ func InputForInt(in *string, entity string) { *in = getInput("\\d+", "enter_id", i118Utils.I118Prt.Sprintf(entity)) } +func InputForBool(in *bool, entity string) { + str := getInput("(yes|no|y|n)", i118Utils.I118Prt.Sprintf(entity), "") + + if str != "n" && str != "no" { + *in = true + } else { + *in = false + } +} + func getInput(regx string, fmtStr string, params ...interface{}) string { var ret string -- GitLab