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

exec params

上级 b3eacc6e
192.168.0.1,
192.168.1.2,
192.168.2.3,
192.168.3.4,
192.168.4.5,
192.168.5.6,
192.168.6.7,
192.168.7.8,
192.168.8.9,
192.168.9.10,
192.168.10.11,
192.168.11.12,
192.168.12.13,
192.168.13.14,
01
12
23
34
45
56
67
78
89
910
1011
1112
1213
1314
......@@ -18,8 +18,4 @@ fields:
note: 测试Excel数据
from: system.address.v1.city
select: name
where: state like '%山东%'
- field: field4
note: 测试Excel数据
range: a-z,0-9
\ No newline at end of file
where: state like '%山东%'
\ No newline at end of file
$>ztf.exe set 根据系统提示,设置工具语言属性。
$>ztf.exe gen -d sample/test.yaml -c 15 -field field1 -o sample/output.txt -f text 执行数据生成命令。使用定义文件sample/test.yaml,生成15行数据,以text格式的输出到sample/output.txt文件中。
\ No newline at end of file
$>ztf.exe -s 根据系统提示,设置工具语言属性。
$>ztf.exe -y sample/test.yaml -c 15 -field field1 -o sample/output.txt -f text
执行数据生成命令。使用配置文件sample/test.yaml,生成15行数据,以text格式的输出到sample/output.txt文件中。
$>ztf.exe -d sample/common.yaml -y sample/test.yaml -c 15 -field field1 -o sample/output.txt -f text
执行数据生成命令。使用文件sample/test.yam覆盖默认配置sample/common.yaml中的内容。
\ No newline at end of file
help -h 查看帮助信息。
set -s 设置工具语言属性。用户对当前目录需要有写权限。
gen 根据定义文件生成数据。
-d -def 指定定义文件
-c -count 指定生成数据的条数
-field 指定输入的字段,用逗号分隔
-o -out 指定输出文件
-f format 指定输出格式,支持text、json、xml和sql语句几种格式
-t -table 输出格式为table时,用于指定insert语句的表名
--verbose 增加此参数,显示详细调试信息。
-help -h 查看帮助信息。
-set -s 设置工具语言属性。用户对当前目录需要有写权限。
默认根据定义文件生成数据。
-d -def 指定定义文件
-c -count 指定生成数据的条数
-field 指定输入的字段,用逗号分隔
-o -out 指定输出文件
-f format 指定输出格式,支持text、json、xml和sql语句几种格式
-t -table 输出格式为table时,用于指定insert语句的表名
--verbose 增加此参数,显示详细调试信息。
为了方便在任意目录中执行%s命令,建议将其加入环境变量中,具体方法参照以下地址。
https://www.ztesting.net/book/ztf-doc/add-to-path-46.html
\ No newline at end of file
......@@ -9,22 +9,20 @@ import (
constant "github.com/easysoft/zendata/src/utils/const"
i118Utils "github.com/easysoft/zendata/src/utils/i118"
logUtils "github.com/easysoft/zendata/src/utils/log"
stringUtils "github.com/easysoft/zendata/src/utils/string"
"github.com/easysoft/zendata/src/utils/vari"
"os"
"path/filepath"
"strconv"
"strings"
"time"
)
func Generate(defFile string, total int, fieldsToExportStr string, out string, format string, table string) {
func Generate(deflt string, yml string, total int, fieldsToExportStr string, out string, format string, table string) {
startTime := time.Now().Unix()
vari.InputDir = filepath.Dir(defFile) + string(os.PathSeparator)
vari.InputDir = filepath.Dir(yml) + string(os.PathSeparator)
constant.Total = total
fieldsToExport := strings.Split(fieldsToExportStr, ",")
rows, colTypes := gen.GenerateForDefinition(defFile, fieldsToExport, total)
rows, colTypes := gen.GenerateForDefinition(yml, fieldsToExport, total)
content := Print(rows, format, table, colTypes, fieldsToExport)
WriteToFile(out, content)
......@@ -34,7 +32,7 @@ func Generate(defFile string, total int, fieldsToExportStr string, out string, f
}
func Print(rows [][]string, format string, table string, colTypes []bool, fields []string) string {
width := stringUtils.GetNumbWidth(len(rows))
//width := stringUtils.GetNumbWidth(len(rows))
content := ""
sql := ""
......@@ -63,8 +61,7 @@ func Print(rows [][]string, format string, table string, colTypes []bool, fields
if format == "text" && i < len(rows) - 1 { content = content + line + "\n" }
idStr := fmt.Sprintf("%" + strconv.Itoa(width) + "d", i+1)
logUtils.Screen(fmt.Sprintf("%s: %s", idStr, line))
logUtils.Screen(fmt.Sprintf("%s", line))
testData.Table.Rows = append(testData.Table.Rows, row)
......
......@@ -19,10 +19,11 @@ func GenerateFieldValuesFromExcel(path string, field *model.DefField) (map[strin
values := map[string][]string{}
idx := strings.LastIndex(field.From, ".")
arr := strings.Split(field.From, ".")
dbName := arr[len(arr) - 2]
tableName := field.From[idx + 1:]
arr := strings.Split(field.From, ".")
dbName := arr[len(arr) - 3] + "_" + arr[len(arr) - 2]
list := make([]string, 0)
selectCol := ""
ConvertExcelToSQLiteIfNeeded(dbName, path)
......@@ -249,9 +250,11 @@ func isExcelChanged(path string) bool {
if changed {
if !found {
sqlStr = fmt.Sprintf("INSERT INTO excel_change(name, changeTime) VALUES('%s', %d)", path, fileChangeTime)
sqlStr = fmt.Sprintf("INSERT INTO %s(name, changeTime) VALUES('%s', %d)",
constant.SqliteTrackTable, path, fileChangeTime)
} else {
sqlStr = fmt.Sprintf("UPDATE excel_change SET changeTime = %d WHERE name = '%s'", fileChangeTime, path)
sqlStr = fmt.Sprintf("UPDATE %s SET changeTime = %d WHERE name = '%s'",
constant.SqliteTrackTable, fileChangeTime, path)
}
_, err = db.Exec(sqlStr)
......
......@@ -9,11 +9,12 @@ import (
"github.com/fatih/color"
"os"
"os/signal"
"strings"
"syscall"
)
var (
deflt string
yml string
count int
fields string
......@@ -21,6 +22,10 @@ var (
output string
table = "text"
format = "text"
viewRes string
viewDetail string
help bool
flagSet *flag.FlagSet
......@@ -37,6 +42,12 @@ func main() {
flagSet = flag.NewFlagSet("zd", flag.ContinueOnError)
flagSet.StringVar(&deflt, "d", "", "")
flagSet.StringVar(&deflt, "deflt", "", "")
flagSet.StringVar(&yml, "y", "", "")
flagSet.StringVar(&yml, "yml", "", "")
flagSet.StringVar(&input, "i", "", "")
flagSet.StringVar(&input, "input", "", "")
......@@ -54,14 +65,14 @@ func main() {
flagSet.StringVar(&format, "f", "", "")
flagSet.StringVar(&format, "format", "", "")
flagSet.StringVar(&viewRes, "v", "", "")
flagSet.StringVar(&viewDetail, "vv", "", "")
flagSet.BoolVar(&vari.Verbose, "v", false, "")
flagSet.BoolVar(&vari.Verbose, "verbose", false, "")
flagSet.BoolVar(&help, "h", false, "")
flagSet.BoolVar(&help, "help", false, "")
if len(os.Args) == 1 {
os.Args = append(os.Args, "help")
os.Args = append(os.Args, "-help")
} else if os.Args[1][0:1] == "-" {
args := []string{os.Args[0], "gen"}
args = append(args, os.Args[1:]...)
......@@ -69,30 +80,21 @@ func main() {
}
switch os.Args[1] {
case "set", "-set":
case "-s", "-set":
action.Set()
case "gen":
gen(os.Args)
//case "upgrade":
// upgrade(os.Args)
default:
case "-h", "-help":
logUtils.PrintUsage()
default:
gen(os.Args)
}
}
//func upgrade(args []string) {
// if err := flagSet.Parse(args[2:]); err == nil {
// action.Upgrade()
// }
//}
func gen(args []string) {
if err := flagSet.Parse(args[2:]); err == nil {
if strings.Index(strings.ToLower(input), ".sql") > 0 {
if input != "" {
action.ParseSql(input, output)
} else {
action.Generate(input, count, fields, output, format, table)
action.Generate(deflt, yml, count, fields, output, format, table)
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册