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

close task#7668

上级 eec2ab07
......@@ -102,23 +102,23 @@ fields:
postfix: "\t"
- field: field_use_ranges # 引用內置的定义文件,该文件定义了多个range,他们共享了一些field层面的属性。
from: users.jenkins.number.v1.yaml # 引用data/custom/number/v1.yaml文件里面的ranges定义。
from: custom.test.number.v1.yaml # 引用data/custom/number/v1.yaml文件里面的ranges定义。
use: medium # 使用该文件中定义的medium分组。
postfix: "\t"
- field: field_use_instance # 引用其他的定义文件,该文件定义了多个实例。
from: yaml.ip.v1.yaml # 引用data/system/ip/v1.yaml
from: system.ip.v1.yaml # 引用data/system/ip/v1.yaml
use: privateC,privateB # 使用该文件中定义的privateC和privateB两个实例。
postfix: "\t"
- field: field_nested_instant # 引用其他的定义文件,且该文件引用了其他实例。
from: users.jenkins.ip.private.yaml # 引用data/custom/ip/private.yaml
from: custom.ip.private.yaml # 引用data/custom/ip/private.yaml
use: all # 使用该文件中的所有实例。
prefix: "{"
postfix: "}"
- field: field_use_excel # 从excel数据源里面取数据。
from: address.cn.v1.china # 从data/address/cn.v1.xlsx文件中读取名为china的工作簿。
from: system.address.v1.china # 从data/system/address/v1.xlsx文件中读取名为china的工作簿。
select: city # 查询city字段。
where: state like '%山东%' # 条件是省份包含山东。
postfix: "\t"
......
......@@ -26,6 +26,18 @@
"id": "enter_language",
"translation": "1) 请选择您要使用的语言,中文请输入数字1。\n2) Please select the language. Input 2 for English."
},
{
"id": "add_to_path",
"translation": "Would you like to add ZenData to PATH environment variable? (y/n, default is Yes)"
},
{
"id": "add_to_path_success_win",
"translation": "Success to add PATH environment variable, please reopen the command window."
},
{
"id": "add_to_path_success_linux",
"translation": "Success to add PATH environment variable, please execute 'source %s' to make it effective."
},
{
"id": "current_config",
"translation": "Current config:"
......@@ -132,6 +144,10 @@
{
"id": "fail_to_generate_field",
"translation": "Fail to generate data for field '%s'."
},
{
"id": "fail_to_exec_cmd",
"translation": "Fail to exec command '%s', error is '%s'."
}
]
}
\ No newline at end of file
此差异已折叠。
......@@ -21,6 +21,18 @@
"id": "enter_language",
"translation": "1) 请选择您要使用的语言,中文请输入数字1。\n2) Please select the language. Input 2 for English."
},
{
"id": "add_to_path",
"translation": "是否将ZenData加入Path环境变量,以方便在任何目录中执行?(y/n, 默认Yes)"
},
{
"id": "add_to_path_success_win",
"translation": "成功设置PATH环境变量,请重新打开命令行窗口。"
},
{
"id": "add_to_path_success_linux",
"translation": "成功设置PATH环境变量,请执行source %s使其生效。"
},
{
"id": "current_config",
"translation": "当前配置:"
......@@ -123,6 +135,10 @@
{
"id": "fail_to_generate_field",
"translation": "为Field %s生成数据失败。"
},
{
"id": "fail_to_exec_cmd",
"translation": "执行命令'%s'失败,错误消息为'%s'。"
}
]
}
\ No newline at end of file
......@@ -14,8 +14,10 @@ import (
"github.com/fatih/color"
"gopkg.in/ini.v1"
"os"
"os/user"
"path/filepath"
"reflect"
"strings"
)
func InitConfig() {
......@@ -133,14 +135,52 @@ func InputForSet() {
numb = "2"
}
numbSelected := stdinUtils.GetInput("(1|2)", numb, "enter_language", enCheck, zhCheck)
if numbSelected == "1" {
// set lang
langNo := stdinUtils.GetInput("(1|2)", numb, "enter_language", enCheck, zhCheck)
if langNo == "1" {
conf.Language = "zh"
} else {
conf.Language = "en"
}
// set PATH environment vari
var addToPath bool
stdinUtils.InputForBool(&addToPath, true, "add_to_path")
if addToPath {
AddZdToPath()
}
SaveConfig(conf)
PrintCurrConfig()
}
func AddZdToPath() {
userProfile, _ := user.Current()
home := userProfile.HomeDir
if commonUtils.IsWin() {
} else {
path := fmt.Sprintf("%s%s%s", home, constant.PthSep, ".bash_profile")
content := fileUtils.ReadFile(path)
if strings.Contains(content, vari.ExeDir) { return }
cmd := fmt.Sprintf("echo 'export PATH=$PATH:%s' >> %s", vari.ExeDir, path)
out, err := shellUtils.ExeShell(cmd)
if err == nil {
msg := ""
if commonUtils.IsWin() {
msg = i118Utils.I118Prt.Sprintf("add_to_path_success_win")
} else {
msg = i118Utils.I118Prt.Sprintf("add_to_path_success_linux", path)
}
logUtils.PrintToWithColor(msg, color.FgRed)
} else {
logUtils.PrintToWithColor(
i118Utils.I118Prt.Sprintf("fail_to_exec_cmd", cmd, err.Error() + ": " + out), color.FgRed)
}
}
}
......@@ -182,4 +182,4 @@ func AddRootPath(path string) string {
path = vari.WorkDir + "data" + constant.PthSep + path
return path
}
}
\ No newline at end of file
......@@ -5,7 +5,6 @@ import (
"bytes"
"fmt"
commonUtils "github.com/easysoft/zendata/src/utils/common"
logUtils "github.com/easysoft/zendata/src/utils/log"
"io"
"os/exec"
"strings"
......@@ -57,7 +56,7 @@ func ExeShellWithOutput(cmdStr string) []string {
if err2 != nil || io.EOF == err2 {
break
}
logUtils.PrintTo(strings.TrimRight(line, "\n"))
fmt.Println(strings.TrimRight(line, "\n"))
output = append(output, line)
}
......
......@@ -60,6 +60,29 @@ func GetInput(regx string, defaultVal string, fmtStr string, params ...interface
}
}
func InputForBool(in *bool, defaultVal bool, fmtStr string, fmtParam ...interface{}) {
str := GetInput("(yes|no|y|n|)", "", fmtStr, fmtParam...)
if str == "" {
*in = defaultVal
msg := ""
if *in {
msg = "yes"
} else {
msg = "no"
}
logUtils.PrintTo(msg)
return
}
if str == "y" && str != "yes" {
*in = true
} else {
*in = false
}
}
func Scanf(a *string) {
reader := bufio.NewReader(os.Stdin)
data, _, _ := reader.ReadLine()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册