提交 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
productId, projectId, langType, singleFile,
name, account, password)
configUtils.UpdateWorkDirHistoryForGenerate()
fmt.Sprintf("success to generate %d test scripts in '%s' at %s",
count, constant.ScriptDir, dateUtils.DateTimeStr(time.Now()))
} else {
......
package action
func SwitchWorkDir(dir string) error {
Set("workDir", dir, true)
Set("workDir", dir, false)
return nil
}
......@@ -53,6 +53,10 @@ func main() {
flagSets = append(flagSets, *rerunSet)
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)
flagSets = append(flagSets, *genSet)
genSet.StringVar(&zentaoUrl, "u", "", "Zentao project url")
......@@ -103,6 +107,15 @@ func main() {
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":
if err := genSet.Parse(os.Args[2:]); err == nil {
if zentaoUrl == "" || langType == "" || entityType == "" || entityVal == "" ||
......
......@@ -3,6 +3,7 @@ package commonUtils
import (
"github.com/easysoft/zentaoatf/src/utils/const"
"os"
"os/user"
"path"
"path/filepath"
"regexp"
......@@ -72,21 +73,25 @@ func UpdateUrl(url string) string {
func ConvertWorkDir(p string) string {
sepa := string(os.PathSeparator)
var temp string
if p == "." {
temp, _ := filepath.Abs(`.`)
temp = temp + sepa
return temp
}
if IsRelativePath(p) {
if strings.Index(p, ".") == 0 {
temp, _ := filepath.Abs(".")
p = temp + p[1:]
} else if strings.Index(p, "~") == 0 && !IsWin() {
user, err := user.Current()
if nil == err {
temp := user.HomeDir
p = temp + p[1:]
}
} else if IsRelativePath(p) {
temp, _ = filepath.Abs(`.`)
temp = temp + sepa + p
p = temp + sepa + p
}
if !PathEndWithSeparator(p) {
temp = p + sepa
p = p + sepa
}
return temp
return p
}
// base on workdir
......
......@@ -43,7 +43,7 @@ func SetPreference(param string, val string, dumb bool) {
val = commonUtils.ConvertWorkDir(val)
vari.Prefer.WorkDir = val
UpdateWorkDirHistory()
UpdateWorkDirHistoryForSwitch()
}
data, _ := yaml.Marshal(&vari.Prefer)
ioutil.WriteFile(constant.PreferenceFile, data, 0666)
......@@ -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
// 已经是第一个,不做操作
......@@ -136,7 +147,7 @@ func UpdateWorkDirHistory() {
histories = append([]model.WorkHistory{history}, histories...)
// 保存最后10个
// 保存最后10个
if len(histories) > 10 {
histories = histories[:10]
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册