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

save project settings in preference file after import; support switching dir...

save project settings in preference file after import; support switching dir to paths like . ./ ~ ~/test
上级 d55cbf30
...@@ -24,6 +24,8 @@ func GenerateScriptFromCmd(url string, entityType string, entityVal string, lang ...@@ -24,6 +24,8 @@ func GenerateScriptFromCmd(url string, entityType string, entityVal string, lang
productId, projectId, langType, singleFile, productId, projectId, langType, singleFile,
name, account, password) name, account, password)
configUtils.UpdateWorkDirHistoryForGenerate()
fmt.Sprintf("success to generate %d test scripts in '%s' at %s", fmt.Sprintf("success to generate %d test scripts in '%s' at %s",
count, constant.ScriptDir, dateUtils.DateTimeStr(time.Now())) count, constant.ScriptDir, dateUtils.DateTimeStr(time.Now()))
} else { } else {
......
package action package action
func SwitchWorkDir(dir string) error { func SwitchWorkDir(dir string) error {
Set("workDir", dir, true) Set("workDir", dir, false)
return nil return nil
} }
...@@ -53,6 +53,10 @@ func main() { ...@@ -53,6 +53,10 @@ func main() {
flagSets = append(flagSets, *rerunSet) flagSets = append(flagSets, *rerunSet)
rerunSet.StringVar(&path, "p", "", "Test result file path") rerunSet.StringVar(&path, "p", "", "Test result file path")
switchSet := flag.NewFlagSet("atf switch - Swith work dir to another path", flag.ContinueOnError)
flagSets = append(flagSets, *switchSet)
switchSet.StringVar(&path, "p", "", "Work dir path")
genSet := flag.NewFlagSet("atf gen - Generate test scripts from zentaoService test cases", flag.ContinueOnError) genSet := flag.NewFlagSet("atf gen - Generate test scripts from zentaoService test cases", flag.ContinueOnError)
flagSets = append(flagSets, *genSet) flagSets = append(flagSets, *genSet)
genSet.StringVar(&zentaoUrl, "u", "", "Zentao project url") genSet.StringVar(&zentaoUrl, "u", "", "Zentao project url")
...@@ -103,6 +107,15 @@ func main() { ...@@ -103,6 +107,15 @@ func main() {
action.Rerun(path) action.Rerun(path)
} }
} }
case "switch":
if err := switchSet.Parse(os.Args[2:]); err == nil {
if path == "" {
switchSet.Usage()
os.Exit(1)
} else {
action.SwitchWorkDir(path)
}
}
case "gen": case "gen":
if err := genSet.Parse(os.Args[2:]); err == nil { if err := genSet.Parse(os.Args[2:]); err == nil {
if zentaoUrl == "" || langType == "" || entityType == "" || entityVal == "" || if zentaoUrl == "" || langType == "" || entityType == "" || entityVal == "" ||
......
...@@ -3,6 +3,7 @@ package commonUtils ...@@ -3,6 +3,7 @@ package commonUtils
import ( import (
"github.com/easysoft/zentaoatf/src/utils/const" "github.com/easysoft/zentaoatf/src/utils/const"
"os" "os"
"os/user"
"path" "path"
"path/filepath" "path/filepath"
"regexp" "regexp"
...@@ -72,21 +73,25 @@ func UpdateUrl(url string) string { ...@@ -72,21 +73,25 @@ func UpdateUrl(url string) string {
func ConvertWorkDir(p string) string { func ConvertWorkDir(p string) string {
sepa := string(os.PathSeparator) sepa := string(os.PathSeparator)
var temp string var temp string
if p == "." { if strings.Index(p, ".") == 0 {
temp, _ := filepath.Abs(`.`) temp, _ := filepath.Abs(".")
temp = temp + sepa p = temp + p[1:]
return temp } else if strings.Index(p, "~") == 0 && !IsWin() {
} user, err := user.Current()
if nil == err {
if IsRelativePath(p) { temp := user.HomeDir
p = temp + p[1:]
}
} else if IsRelativePath(p) {
temp, _ = filepath.Abs(`.`) temp, _ = filepath.Abs(`.`)
temp = temp + sepa + p p = temp + sepa + p
} }
if !PathEndWithSeparator(p) { if !PathEndWithSeparator(p) {
temp = p + sepa p = p + sepa
} }
return temp return p
} }
// base on workdir // base on workdir
......
...@@ -43,7 +43,7 @@ func SetPreference(param string, val string, dumb bool) { ...@@ -43,7 +43,7 @@ func SetPreference(param string, val string, dumb bool) {
val = commonUtils.ConvertWorkDir(val) val = commonUtils.ConvertWorkDir(val)
vari.Prefer.WorkDir = val vari.Prefer.WorkDir = val
UpdateWorkDirHistory() UpdateWorkDirHistoryForSwitch()
} }
data, _ := yaml.Marshal(&vari.Prefer) data, _ := yaml.Marshal(&vari.Prefer)
ioutil.WriteFile(constant.PreferenceFile, data, 0666) ioutil.WriteFile(constant.PreferenceFile, data, 0666)
...@@ -109,7 +109,18 @@ func PrintPreferenceToView() { ...@@ -109,7 +109,18 @@ func PrintPreferenceToView() {
} }
} }
func UpdateWorkDirHistory() { func UpdateWorkDirHistoryForGenerate() {
conf := ReadCurrConfig()
vari.Prefer.WorkHistories[0].ProjectName = conf.ProjectName
vari.Prefer.WorkHistories[0].EntityType = conf.EntityType
vari.Prefer.WorkHistories[0].EntityVal = conf.EntityVal
data, _ := yaml.Marshal(&vari.Prefer)
ioutil.WriteFile(constant.PreferenceFile, data, 0666)
}
func UpdateWorkDirHistoryForSwitch() {
histories := vari.Prefer.WorkHistories histories := vari.Prefer.WorkHistories
// 已经是第一个,不做操作 // 已经是第一个,不做操作
...@@ -136,7 +147,7 @@ func UpdateWorkDirHistory() { ...@@ -136,7 +147,7 @@ func UpdateWorkDirHistory() {
histories = append([]model.WorkHistory{history}, histories...) histories = append([]model.WorkHistory{history}, histories...)
// 保存最后10个 // 保存最后10个
if len(histories) > 10 { if len(histories) > 10 {
histories = histories[:10] histories = histories[:10]
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册