提交 38f6d181 编写于 作者: m0_58228130's avatar m0_58228130

windows set interpreter path

上级 5db1192c
......@@ -101,7 +101,7 @@ func main() {
case "checkout", "co":
if err := flagSet.Parse(os.Args[2:]); err == nil {
action.Generate(productId, moduleId, suiteId, taskId, independentFile, commConsts.Language, actionModule)
action.Generate(productId, moduleId, suiteId, taskId, independentFile, language, actionModule)
}
case "set", "-set":
......
......@@ -4,6 +4,7 @@ const (
App = "ztf"
AppServer = "server"
AppAgent = "agent"
AppCommand = "cmd"
ConfigVersion = "3.0"
ConfigDir = "conf"
......
......@@ -60,3 +60,12 @@ func GetFieldVal(config commDomain.ProjectConf, key string) string {
return val
}
func SetFieldVal(config *commDomain.ProjectConf, key string, val string) string {
key = stringUtils.UcFirst(key)
mutable := reflect.ValueOf(config).Elem()
mutable.FieldByName(key).SetString(val)
return val
}
......@@ -7,9 +7,11 @@ import (
fileUtils "github.com/aaronchen2k/deeptest/internal/pkg/lib/file"
langUtils "github.com/aaronchen2k/deeptest/internal/pkg/lib/lang"
logUtils "github.com/aaronchen2k/deeptest/internal/pkg/lib/log"
stringUtils "github.com/aaronchen2k/deeptest/internal/pkg/lib/string"
serverDomain "github.com/aaronchen2k/deeptest/internal/server/modules/v1/domain"
"github.com/kataras/iris/v12"
"io/ioutil"
"path"
"regexp"
)
......@@ -142,3 +144,20 @@ func addDir(pth string, parent *serverDomain.TestAsset) (dirNode *serverDomain.T
return
}
func GetScriptType(scripts []string) []string {
exts := make([]string, 0)
for _, script := range scripts {
ext := path.Ext(script)
if ext != "" {
ext = ext[1:]
name := langUtils.ScriptExtToNameMap[ext]
if !stringUtils.FindInArr(name, exts) {
exts = append(exts, name)
}
}
}
return exts
}
......@@ -3,12 +3,15 @@ package commandConfig
import (
"fmt"
commConsts "github.com/aaronchen2k/deeptest/internal/comm/consts"
commDomain "github.com/aaronchen2k/deeptest/internal/comm/domain"
configUtils "github.com/aaronchen2k/deeptest/internal/comm/helper/config"
scriptUtils "github.com/aaronchen2k/deeptest/internal/comm/helper/script"
"github.com/aaronchen2k/deeptest/internal/comm/vari"
commonUtils "github.com/aaronchen2k/deeptest/internal/pkg/lib/common"
"github.com/aaronchen2k/deeptest/internal/pkg/lib/display"
fileUtils "github.com/aaronchen2k/deeptest/internal/pkg/lib/file"
i118Utils "github.com/aaronchen2k/deeptest/internal/pkg/lib/i118"
langUtils "github.com/aaronchen2k/deeptest/internal/pkg/lib/lang"
logUtils "github.com/aaronchen2k/deeptest/internal/pkg/lib/log"
stdinUtils "github.com/aaronchen2k/deeptest/internal/pkg/lib/stdin"
"github.com/aaronchen2k/deeptest/internal/server/modules/v1/repo"
......@@ -93,15 +96,15 @@ func InputForSet() {
conf.Username = stdinUtils.GetInput("(.{2,})", conf.Username, "enter_account", conf.Username)
conf.Password = stdinUtils.GetInput("(.{2,})", conf.Password, "enter_password", conf.Password)
}
// Todo
//if commonUtils.IsWin() {
// var configInterpreter bool
// stdinUtils.InputForBool(&configInterpreter, true, "config_script_interpreter")
// if configInterpreter {
// scripts := assertUtils.GetCaseByDirAndFile([]string{"."})
// InputForScriptInterpreter(scripts, &conf, "set")
// }
//}
if commonUtils.IsWin() {
var configInterpreter bool
stdinUtils.InputForBool(&configInterpreter, true, "config_script_interpreter")
if configInterpreter {
scripts := scriptUtils.LoadScriptByProject(commConsts.WorkDir)
InputForScriptInterpreter(scripts, &conf, "set")
}
}
configUtils.SaveToFile(conf, commConsts.WorkDir)
PrintCurrConfig()
}
......@@ -140,37 +143,36 @@ func getZenTaoBaseUrl(url string) string {
return base
}
//func InputForScriptInterpreter(scripts []string, config *commDomain.ProjectConf, from string) bool {
// configChanged := false
// //
// langs := assertUtils.GetScriptType(scripts)
//
// for _, lang := range langs {
// if lang == "bat" || lang == "shell" {
// continue
// }
//
// deflt := configUtils.GetFieldVal(*config, lang)
// if from == "run" && deflt != "" { // already set when run, "-" means ignore
// continue
// }
//
// if deflt == "-" {
// deflt = ""
// }
// sampleOrDefaultTips := ""
// if deflt == "" {
// sampleOrDefaultTips = i118Utils.Sprintf("for_example", langUtils.LangMap[lang]["interpreter"]) + " " +
// i118Utils.Sprintf("empty_to_ignore")
// } else {
// sampleOrDefaultTips = deflt
// }
//
// configChanged = true
//
// inter := stdinUtils.GetInputForScriptInterpreter(deflt, "set_script_interpreter", lang, sampleOrDefaultTips)
// configUtils.SetFieldVal(config, lang, inter)
// }
//
// return configChanged
//}
func InputForScriptInterpreter(scripts []string, config *commDomain.ProjectConf, from string) bool {
configChanged := false
langs := scriptUtils.GetScriptType(scripts)
for _, lang := range langs {
if lang == "bat" || lang == "shell" {
continue
}
deflt := configUtils.GetFieldVal(*config, lang)
if from == "run" && deflt != "" { // already set when run, "-" means ignore
continue
}
if deflt == "-" {
deflt = ""
}
sampleOrDefaultTips := ""
if deflt == "" {
sampleOrDefaultTips = i118Utils.Sprintf("for_example", langUtils.LangMap[lang]["interpreter"]) + " " +
i118Utils.Sprintf("empty_to_ignore")
} else {
sampleOrDefaultTips = deflt
}
configChanged = true
inter := stdinUtils.GetInputForScriptInterpreter(deflt, "set_script_interpreter", lang, sampleOrDefaultTips)
configUtils.SetFieldVal(config, lang, inter)
}
return configChanged
}
......@@ -20,7 +20,7 @@ func InitConfig() {
commandConfig.InitScreenSize()
// internationalization
i118Utils.Init(commConsts.Language, commConsts.AppServer)
i118Utils.Init(commConsts.Language, commConsts.AppCommand)
langUtils.GetExtToNameMap()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册