提交 bd4d48f8 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

tips

上级 2bbfb6c2
......@@ -14,7 +14,7 @@ import (
func Generate(productId string, moduleId string, suiteId string, taskId string,
independentFile bool, scriptLang string) {
stdinUtils.CheckRequestConfig()
CheckRequestConfig()
if (productId != "") || (moduleId != "" && productId != "") || suiteId != "" || taskId != "" {
......
......@@ -10,7 +10,6 @@ import (
fileUtils "github.com/easysoft/zentaoatf/src/utils/file"
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/vari"
zentaoUtils "github.com/easysoft/zentaoatf/src/utils/zentao"
"path"
......@@ -66,7 +65,7 @@ func getCaseByTaskId(id string, dir string) []string {
taskId, err := strconv.Atoi(id)
if err == nil && taskId > 0 {
stdinUtils.CheckRequestConfig()
CheckRequestConfig()
zentaoService.GetCaseIdsByTask(id, &caseIdMap)
}
......@@ -80,7 +79,7 @@ func getCaseBySuiteId(id string, dir string) []string {
suiteId, err := strconv.Atoi(id)
if err == nil && suiteId > 0 {
stdinUtils.CheckRequestConfig()
CheckRequestConfig()
zentaoService.GetCaseIdsBySuite(id, &caseIdMap)
}
......
package action
import (
"fmt"
configUtils "github.com/easysoft/zentaoatf/src/utils/config"
i118Utils "github.com/easysoft/zentaoatf/src/utils/i118"
stdinUtils "github.com/easysoft/zentaoatf/src/utils/stdin"
)
func InputForSet() {
conf := configUtils.ReadCurrConfig()
var configSite bool
language := ""
url := ""
account := ""
password := ""
fmt.Println(i118Utils.I118Prt.Sprintf("begin_config"))
enCheck := ""
var numb string
if conf.Language == "en" {
enCheck = "*"
numb = "1"
}
zhCheck := ""
if conf.Language == "zh" {
zhCheck = "*"
numb = "2"
}
numbSelected := stdinUtils.GetInput("(1|2)", numb, "enter_language", enCheck, zhCheck)
if numbSelected == "1" {
language = "en"
} else {
language = "zh"
}
stdinUtils.InputForBool(&configSite, true, "config_zentao_site")
if configSite {
url = stdinUtils.GetInput("(http://.*)", conf.Url, "enter_url", conf.Url)
account = stdinUtils.GetInput("(.{3,})", conf.Account, "enter_account", conf.Account)
password = stdinUtils.GetInput("(.{4,})", conf.Password, "enter_password", conf.Password)
}
configUtils.SaveConfig(language, url, account, password)
configUtils.PrintCurrConfig()
}
func CheckRequestConfig() {
conf := configUtils.ReadCurrConfig()
if conf.Url == "" || conf.Account == "" || conf.Password == "" {
InputForRequest()
}
}
func InputForRequest() {
conf := configUtils.ReadCurrConfig()
url := ""
account := ""
password := ""
fmt.Println(i118Utils.I118Prt.Sprintf("begin_config"))
url = stdinUtils.GetInput("(http://.*)", conf.Url, "enter_url", conf.Url)
account = stdinUtils.GetInput("(.{3,})", conf.Account, "enter_account", conf.Account)
password = stdinUtils.GetInput("(.{4,})", conf.Password, "enter_password", conf.Password)
configUtils.SaveConfig("", url, account, password)
}
......@@ -6,7 +6,6 @@ import (
configUtils "github.com/easysoft/zentaoatf/src/utils/config"
fileUtils "github.com/easysoft/zentaoatf/src/utils/file"
logUtils "github.com/easysoft/zentaoatf/src/utils/log"
stdinUtils "github.com/easysoft/zentaoatf/src/utils/stdin"
"github.com/easysoft/zentaoatf/src/utils/vari"
"os"
)
......@@ -112,7 +111,7 @@ func main() {
}
case "set", "-s":
stdinUtils.InputForSet()
action.InputForSet()
case "help", "-h":
logUtils.PrintUsage()
......
......@@ -2,7 +2,6 @@ package stdinUtils
import (
"fmt"
configUtils "github.com/easysoft/zentaoatf/src/utils/config"
fileUtils "github.com/easysoft/zentaoatf/src/utils/file"
i118Utils "github.com/easysoft/zentaoatf/src/utils/i118"
langUtils "github.com/easysoft/zentaoatf/src/utils/lang"
......@@ -14,113 +13,28 @@ import (
"strings"
)
func InputForSet() {
conf := configUtils.ReadCurrConfig()
var configSite bool
language := ""
url := ""
account := ""
password := ""
fmt.Println(i118Utils.I118Prt.Sprintf("begin_config"))
enCheck := ""
var numb string
if conf.Language == "en" {
enCheck = "*"
numb = "1"
}
zhCheck := ""
if conf.Language == "zh" {
zhCheck = "*"
numb = "2"
}
language = getInput("(1|2|)", "enter_language", enCheck, zhCheck)
if language == "" {
language = conf.Language
logUtils.PrintToStdOut(numb, -1)
} else if language == "1" {
language = "en"
} else {
language = "zh"
}
InputForBool(&configSite, true, "config_zentao_site")
if configSite {
url = getInput("(http://.*|)", "enter_url", conf.Url)
if url == "" {
url = conf.Url
logUtils.PrintToStdOut(url, -1)
}
account = getInput("(.{3,}|)", "enter_account", conf.Account)
if account == "" {
account = conf.Account
logUtils.PrintToStdOut(account, -1)
}
password = getInput("(.{4,}|)", "enter_password", conf.Password)
if password == "" {
password = conf.Password
logUtils.PrintToStdOut(password, -1)
}
}
configUtils.SaveConfig(language, url, account, password)
configUtils.PrintCurrConfig()
}
func CheckRequestConfig() {
conf := configUtils.ReadCurrConfig()
if conf.Url == "" || conf.Account == "" || conf.Password == "" {
InputForRequest()
}
}
func InputForRequest() {
url := ""
account := ""
password := ""
fmt.Println(i118Utils.I118Prt.Sprintf("begin_config"))
url = getInput("http://.*", "enter_url")
account = getInput(".{3,}", "enter_account")
password = getInput(".{4,}", "enter_password")
configUtils.SaveConfig("", url, account, password)
configUtils.PrintCurrConfig()
}
func InputForCheckout(productId *string, moduleId *string, suiteId *string, taskId *string,
independentFile *bool, scriptLang *string) {
coType := getInput("(1|2|3|4)", "enter_co_type")
coType := GetInput("(1|2|3|4)", "", "enter_co_type")
coType = strings.ToLower(coType)
if coType == "1" {
*productId = getInput("\\d+",
*productId = GetInput("\\d+", "",
i118Utils.I118Prt.Sprintf("pls_enter")+" "+i118Utils.I118Prt.Sprintf("product_id"))
} else if coType == "2" {
*productId = getInput("\\d+",
*productId = GetInput("\\d+", "",
i118Utils.I118Prt.Sprintf("pls_enter")+" "+i118Utils.I118Prt.Sprintf("product_id"))
*moduleId = getInput("\\d+",
*moduleId = GetInput("\\d+", "",
i118Utils.I118Prt.Sprintf("pls_enter")+" "+i118Utils.I118Prt.Sprintf("module_id"))
} else if coType == "3" {
*suiteId = getInput("\\d+",
*suiteId = GetInput("\\d+", "",
i118Utils.I118Prt.Sprintf("pls_enter")+" "+i118Utils.I118Prt.Sprintf("suite_id"))
} else if coType == "4" {
*taskId = getInput("\\d+",
*taskId = GetInput("\\d+", "",
i118Utils.I118Prt.Sprintf("pls_enter")+" "+i118Utils.I118Prt.Sprintf("task_id"))
}
......@@ -128,7 +42,7 @@ func InputForCheckout(productId *string, moduleId *string, suiteId *string, task
numbs, names, labels := langUtils.GetSupportLanguageOptions()
fmtParam := strings.Join(labels, "\n")
numbStr := getInput("("+strings.Join(numbs, "|")+")", "enter_co_language", fmtParam)
numbStr := GetInput("("+strings.Join(numbs, "|")+")", "enter_co_language", fmtParam)
numb, _ := strconv.Atoi(numbStr)
......@@ -136,15 +50,11 @@ func InputForCheckout(productId *string, moduleId *string, suiteId *string, task
}
func InputForDir(dir *string, entity string) {
*dir = getInput("is_dir", "enter_dir", i118Utils.I118Prt.Sprintf(entity))
}
func InputForInt(in *string, fmtStr string, fmtParam ...string) {
*in = getInput("\\d+", "fmtStr", fmtParam)
*dir = GetInput("is_dir", "", "enter_dir", i118Utils.I118Prt.Sprintf(entity))
}
func InputForBool(in *bool, defaultVal bool, fmtStr string, fmtParam ...string) {
str := getInput("(yes|no|y|n|)", fmtStr, fmtParam)
str := GetInput("(yes|no|y|n|)", "", fmtStr, fmtParam)
if str == "" {
*in = defaultVal
......@@ -167,7 +77,7 @@ func InputForBool(in *bool, defaultVal bool, fmtStr string, fmtParam ...string)
}
}
func getInput(regx string, fmtStr string, params ...interface{}) string {
func GetInput(regx string, defaultVal string, fmtStr string, params ...interface{}) string {
var ret string
msg := i118Utils.I118Prt.Sprintf(fmtStr, params...)
......@@ -176,6 +86,10 @@ func getInput(regx string, fmtStr string, params ...interface{}) string {
logUtils.PrintToStdOut("\n"+msg, color.FgCyan)
fmt.Scanln(&ret)
if strings.TrimSpace(ret) == "" {
ret = defaultVal
}
temp := strings.ToLower(ret)
if temp == "exit" {
os.Exit(1)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册