diff --git a/.gitignore b/.gitignore index ba5cd9de2ba7960418a26dc6f3266cfc6c0ed2e9..adb6cd182845f85554c9492b141ba7793334c44b 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,4 @@ /runtime/protobuf/out/ /users/common/ *.exe +/tmp/cache/.data.db diff --git a/.zd.conf b/.zd.conf index 4a97cdbe90a54bc5acf2d40b62717eb01897b4be..9c2d7d57f9edeb5621d3745cdc482d38bfc43f5b 100644 --- a/.zd.conf +++ b/.zd.conf @@ -1,3 +1,3 @@ -Version = 2.2 +Version = 2.2 Language = zh diff --git a/cmd/command/main.go b/cmd/command/main.go index 041cc7ce3b1be4b2d3cf41d66af5fee2b9578753..929ce9c75081f7f9224ea37aa7af4eacd30188bb 100644 --- a/cmd/command/main.go +++ b/cmd/command/main.go @@ -114,9 +114,6 @@ func main() { flagSet.BoolVar(&example, "e", false, "") flagSet.BoolVar(&example, "example", false, "") - flagSet.BoolVar(&help, "h", false, "") - flagSet.BoolVar(&help, "help", false, "") - flagSet.BoolVar(&set, "S", false, "") flagSet.BoolVar(&set, "set", false, "") @@ -131,6 +128,9 @@ func main() { 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") } diff --git a/demo/default.yaml b/demo/default.yaml index aecc65840c725ab3a13f1c98a06b6b621bb73ed1..68c0c7486354daf665e6bc497056035b0d4a7886 100644 --- a/demo/default.yaml +++ b/demo/default.yaml @@ -104,9 +104,9 @@ fields: range: user.txt:R # 相对当前文件路径。 postfix: "\t" -# - field: field_yaml # 引用其他的定义文件整体内容。 -# range: 01_range.yaml{3} # 相对当前文件路径。 -# postfix: "\t" + - field: field_yaml # 引用其他的定义文件整体内容。 + range: 01_range.yaml{3} # 相对当前文件路径。 + postfix: "\t" - field: field_use_config # 引用其他的config定义文件。 config: number.yaml # 相对当前文件路径,config内包含单个字段。 diff --git a/demo/t.yaml b/demo/t.yaml index a64bf8982b73b5d44712cdb22a9a5c0af22877a3..d38073e0b138b991c74c6056c64664895d76b450 100644 --- a/demo/t.yaml +++ b/demo/t.yaml @@ -1,15 +1,32 @@ -title: zendata数据配置语法说明 -desc: - -author: zentao +title: range +desc: 描述 version: 1.0 fields: - field: f1 - from: uuid.v1.yaml - use: by_format + range: 1-6 + postfix: "\t" + + - field: nesting1 postfix: "\t" + union: true + fields: + - field: child1 + range: A-C + prefix: part1_ + postfix: ' | ' + + - field: child2 + range: 1-9 + prefix: part2_ + + - field: nesting2 + fields: + - field: child1 + range: A-C + prefix: part1_ + postfix: ' | ' - - field: f2 - from: ulid.v1.yaml - use: ulid{3} \ No newline at end of file + - field: child2 + range: 1-9 + prefix: part2_ \ No newline at end of file diff --git a/internal/agent/agent.go b/internal/agent/agent.go index 00552f79aab0b0240e83f538206e312af58671cd..c2dac77f27e36514bed6c2e4c303ec021cafa581 100644 --- a/internal/agent/agent.go +++ b/internal/agent/agent.go @@ -14,9 +14,9 @@ import ( ) var ( - configs []string - defaultFile string - configFile string + configs []string + defaultFile string + configFile string defaultDefContent []byte configDefContent []byte @@ -61,6 +61,8 @@ func DataHandler(writer http.ResponseWriter, req *http.Request) { defaultFile = "" configFile = "" } + + //writer.WriteHeader(http.StatusAccepted) } func genData() { @@ -85,4 +87,4 @@ func genData() { dur := tmEnd.Unix() - tmStart.Unix() logUtils.PrintTo(fmt.Sprintf("Duriation %d sec.", dur)) } -} \ No newline at end of file +} diff --git a/internal/pkg/action/generator.go b/internal/pkg/action/generator.go index 9ad7c618beef65372d1b14f96a92c50ec8eea868..c09b7f18a531200f2d21bf1cdfc57da787da896a 100644 --- a/internal/pkg/action/generator.go +++ b/internal/pkg/action/generator.go @@ -13,7 +13,7 @@ import ( "time" ) -func Generate(files []string, fieldsToExportStr, format, table string) { +func Generate(files []string, fieldsToExportStr, format, table string) (lines []interface{}) { startTime := time.Now().Unix() if len(files) == 0 { return @@ -28,7 +28,7 @@ func Generate(files []string, fieldsToExportStr, format, table string) { vari.ConfigFileDir = fileUtils.GetAbsDir(files[1]) } contents := gen.LoadFilesContents(files) - GenerateByContent(contents, fieldsToExportStr, format, table) + lines = GenerateByContent(contents, fieldsToExportStr, format, table) } else { // gen from protobuf buf, pth := gen.GenerateFromProtobuf(files[0]) @@ -94,7 +94,7 @@ func GenerateByContent(contents [][]byte, fieldsToExportStr, format, table strin } if !isFromExcel(format) { // returned is for preview, sql exec and article writing - lines = gen.Print(rows, format, table, colIsNumArr, fieldsToExport) + lines = gen.PrintLines(rows, format, table, colIsNumArr, fieldsToExport) } else { // for Excel and cvs gen.Write(rows, table, colIsNumArr, fieldsToExport) } diff --git a/internal/pkg/gen/list.go b/internal/pkg/gen/list.go index 6da41d50e5d77ba6259f4d6ddf82816bc8431657..a544935a88b439ddc16c5156642226afbadf1096 100644 --- a/internal/pkg/gen/list.go +++ b/internal/pkg/gen/list.go @@ -349,7 +349,7 @@ func CreateValuesFromYaml(field *model.DefField, yamlFile, stepStr string, repea rows = randomValuesArr(rows) } - items = Print(rows, constant.FormatData, "", colIsNumArr, fieldsToExport) + items = PrintLines(rows, constant.FormatData, "", colIsNumArr, fieldsToExport) if repeat > 0 { if repeat > len(items) { diff --git a/internal/pkg/gen/printer.go b/internal/pkg/gen/printer.go index eb66177fc83c37d42868a641acc3ca3156e8d99c..2ed4b7dbf9ef0c3656326a2519030543c5e60fe9 100644 --- a/internal/pkg/gen/printer.go +++ b/internal/pkg/gen/printer.go @@ -14,7 +14,7 @@ import ( "github.com/easysoft/zendata/pkg/utils/vari" ) -func Print(rows [][]string, format string, table string, colIsNumArr []bool, +func PrintLines(rows [][]string, format string, table string, colIsNumArr []bool, fields []string) (lines []interface{}) { var sqlHeader string diff --git a/internal/pkg/model/domain.go b/internal/pkg/model/domain.go index ad1afc37f9dd2e935fe5114ae48a48ff83941da2..222887a287dca9d32cef55b5da8641a7ab86653f 100644 --- a/internal/pkg/model/domain.go +++ b/internal/pkg/model/domain.go @@ -55,6 +55,7 @@ type DefField struct { RightPad string `yaml:"rightpad,omitempty"` Path string `yaml:"path,omitempty"` FileDir string `yaml:"fileDir,omitempty"` + Union bool `yaml:"union,omitempty"` Froms []DefField `yaml:"froms,flow,omitempty"` } diff --git a/pkg/utils/log/print.go b/pkg/utils/log/print.go index 205eb073b5a05b7b55c3305d14b634731c4f1c84..3bc33c3a29e73508cea0babd45c9ae46a8664b6d 100644 --- a/pkg/utils/log/print.go +++ b/pkg/utils/log/print.go @@ -51,7 +51,7 @@ func PrintUsage() { regx, _ = regexp.Compile(`zd.exe`) usage = regx.ReplaceAllString(usage, "zd") - regx, _ = regexp.Compile(`d:/zd/config `) + regx, _ = regexp.Compile(`d:\zd\config `) usage = regx.ReplaceAllString(usage, "/home/user/zd/config") } fmt.Printf("%s\n", usage) diff --git a/res/en/usage.txt b/res/en/usage.txt index 35065276825eb17096e1bb2b673a9ab5e31a15d5..6eb3d3f2b5e8c6e8cb4df22d9b32bb35c5d5d4c2 100644 --- a/res/en/usage.txt +++ b/res/en/usage.txt @@ -67,6 +67,6 @@ $zd.exe -p 80 -R d:\zd\config # Listen port 80. Use d:\zd\config as th Client Call: -$curl http:\\localhost:8848\?d=demo\default.yaml&c=demo\config.yaml&n=100&T=true # Specify the server config file via GET. -$curl http:\\localhost:8848\?default=demo\default.yaml&output=test.sql&table=user # Parameter names can be full. -$curl -i -X POST http:\\localhost:8848?lines=3 -F default=@demo\default.yaml # The config can be uploaded via POST. +$curl http://localhost:8848/data?d=demo/default.yaml&c=demo/config.yaml&n=100&T=true # Specify the server config file via GET. +$curl http://localhost:8848/data?default=demo/default.yaml&output=test.sql&table=user # Parameter names can be full. +$curl -i -X POST http://localhost:8848/data?lines=3 -F default=@demo/default.yaml # The config can be uploaded via POST. diff --git a/res/zh/usage.txt b/res/zh/usage.txt index 295b145a77d242793147c9558bbd6d69c580f1ad..638e4561023508e23cc2d97f797bd8a5f899cb15 100644 --- a/res/zh/usage.txt +++ b/res/zh/usage.txt @@ -62,6 +62,6 @@ $zd.exe -p 80 -R d:\zd\config # 监听80 客户端调用: -$curl http://localhost:8848/?d=demo/default.yaml&c=demo/config.yaml&n=100&T=true # 通过GET方式指定服务器端配置文件。 -$curl http://localhost:8848/?default=demo/default.yaml&output=test.sql&table=user # 参数名可以用全拼。 -$curl -i -X POST http://localhost:8848?lines=3 -F default=@demo/default.yaml # 可以通过POST方式上传配置文件。 +$curl http://localhost:8848/data?d=demo/default.yaml&c=demo/config.yaml&n=100&T=true # 通过GET方式指定服务器端配置文件。 +$curl http://localhost:8848/data?default=demo/default.yaml&output=test.sql&table=user # 参数名可以用全拼。 +$curl -i -X POST http://localhost:8848/data?lines=3 -F default=@demo/default.yaml # 可以通过POST方式上传配置文件。