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

new features for 1.1

上级 dc7a504e
title: ip
title: IP地址
desc: 含有多种实现的示例。
author: wwccss
version: 1.0
......
title: number
desc:
desc: 数字分组
author: wwccss
version: 1.0
......
-- sqlite
CREATE TABLE user (
field_common VARCHAR (500)
);
-- DROP TABLE IF EXISTS `zt_action`;
CREATE TABLE IF NOT EXISTS `zt_action` (
`id` mediumint(8) unsigned NOT NULL auto_increment,
......@@ -17,51 +22,3 @@ CREATE TABLE IF NOT EXISTS `zt_action` (
KEY `project` (`project`),
KEY `objectID` (`objectID`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- DROP TABLE IF EXISTS `zt_block`;
CREATE TABLE IF NOT EXISTS `zt_block` (
`id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
`account` char(30) NOT NULL,
`module` varchar(20) NOT NULL,
`title` varchar(100) NOT NULL,
`source` varchar(20) NOT NULL,
`block` varchar(20) NOT NULL,
`params` text NOT NULL,
`order` tinyint(3) unsigned NOT NULL DEFAULT '0',
`grid` tinyint(3) unsigned NOT NULL DEFAULT '0',
`height` smallint(5) unsigned NOT NULL DEFAULT '0',
`hidden` tinyint(1) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `accountModuleOrder` (`account`,`module`,`order`),
KEY `account` (`account`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE `wp_posts` (
`ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`post_author` bigint(20) unsigned NOT NULL DEFAULT '0',
`post_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`post_date_gmt` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`post_content` longtext COLLATE utf8mb4_unicode_520_ci NOT NULL,
`post_title` text COLLATE utf8mb4_unicode_520_ci NOT NULL,
`post_excerpt` text COLLATE utf8mb4_unicode_520_ci NOT NULL,
`post_status` varchar(20) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT 'publish',
`comment_status` varchar(20) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT 'open',
`ping_status` varchar(20) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT 'open',
`post_password` varchar(255) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '',
`post_name` varchar(200) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '',
`to_ping` text COLLATE utf8mb4_unicode_520_ci NOT NULL,
`pinged` text COLLATE utf8mb4_unicode_520_ci NOT NULL,
`post_modified` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`post_modified_gmt` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`post_content_filtered` longtext COLLATE utf8mb4_unicode_520_ci NOT NULL,
`post_parent` bigint(20) unsigned NOT NULL DEFAULT '0',
`guid` varchar(255) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '',
`menu_order` int(11) NOT NULL DEFAULT '0',
`post_type` varchar(20) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT 'post',
`post_mime_type` varchar(100) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '',
`comment_count` bigint(20) NOT NULL DEFAULT '0',
PRIMARY KEY (`ID`),
KEY `post_name` (`post_name`(191)),
KEY `type_status_date` (`post_type`,`post_status`,`post_date`,`ID`),
KEY `post_parent` (`post_parent`),
KEY `post_author` (`post_author`)
) ENGINE=InnoDB AUTO_INCREMENT=3843 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
\ No newline at end of file
title: zendata config syntax
desc:
# File composition
# zendata defines the format for each field in YAML file.
# YAML file is composed of file description and field definition.
# File description
# title: A short text to summarize the data type defined by this file.
# desc: Detailed text to describe the data type defined in this file, optional.
# author: Optional.
# version: Version number, optional.
# Field list
# Field is defined in fields.
# A YAML file contains one or more fields.
# Field list starts from -field.
# A child field can be defined by fields.
# Field definition
# field: Field name; letters, digits, underlines and dots only.
# range: List range; the most important definition.
# loop: The number of loops; define how many times a field can loop.
# loopfix: The connector for each loop.
# format: Support formatted output.
# prefix: Prefix of this field.
# postfix: Postfix of this field.
# length: The length of this field. If separators are not used, specify the field length in bytes.
# leftpad: Left-padded characters. If the length is not enough, specify a character. The default is space.
# rightpad: Right-padded characters. If the length is not enough, specify a character.
# config: Refer to the definition in other file.
# from: Refer to a definition file.
# use: Use instances defined in the referred file.
# select: If refer to an excel table, you can query a field in it.
# where: If refer to an excel table, you can use query conditions.
# range definition
# Use commas to connect elements. e.g. range: 1,2,3.
# Elements can be a range, e.g. range:1-10, A-Z.
# Use colons to define steps, e.g. range:1-10:2.
# Steps can be decimals, e.g. range: 1-10:0.1.
# Intervals can be set as random by R, e.g. range: 1-10:R. Set either random or a specified step.
# Use a file to specify a list, e.g. range: list.txt. If the file name is a relative path, it is based on the config file.
# Use {n} to repeat a element, e.g. range: user1{100},user2{100}.
# Use [], if intervals and elements are repeated, e.g. range: [user1,user2,user3]{100}.
author: zentao
version: 1.0
fields:
- field: field_common # The list type by default. Separated by commas.
range: 1-10, 20-25, 27, 29, 30 # 1,2,3...,10,20,21,22...,25,27,29.30
prefix: int_ # Prefix
postfix: \t # Postfix
- field: field_step # Interval steps can be specified.
range: 1-10:2, 1-2:0.1 # 1,3,5,7,9,1, 1.1,1.2...,2
- field: field_random # Use R to specify randomly. Set either R or a specified step.
range: 1-10:R # 1,5,8...
- field: field_file # Read a list from a file and set it as random.
range: _users.txt:R # Using the lines of users.txt as range and set it as random.
- field: field_loop # Self-loop field.
range: a-z # a_b_c | d_e_f | g_h_i
loop: 3 # Loop three times.
loopfix: _ # The connector for each loop.
postfix: |
- field: field_repeat # Use {} to define repeated elements.
range: user-1{3},[user2,user3]{2} # user-1,user-1,user-1,user2,user3,user2,user3
- field: field_format # Output as formatted strings.
range: 1-10 # passwd 1,passwd 2,passwd 3 ... passwd10。
format: "passwd%02d"
- field: field_use_another_file # Other definition file can be referred.
config: _numb_field.yaml # Refer to the definition in nubmer.yaml of the current directory.
- field: field_use_ranges_file # Other definition file can be referred, in which more than one ranges are defined.
from: _numb_ranges.yaml # Refer to the definition in _numb_ranges.yaml of the current directory.
use: medium # use medium range.
- field: field_use_instance # Refer to other definition file which defines multiple instances.
from: system.ip.v1.yaml # Refer to data/system/ip/v1.yaml.
use: privateB,privateC # Use the two instances of privateC and privateB defined in this file.
- field: field_use_excel # Read the data from the data source of excel.
from: system.address.v1.china # Read the book named china in data/system/address/v1.xlsx.
select: city # Query the field city.
where: zipCode>250000 AND zipCode<274001 # Query condition.
- field: field_with_children # Embeded field.
fields:
- field: child1
range: a-z
prefix: part1_
postfix: '|'
- field: child2
range: A-Z
prefix: part2_
postfix: '|'
- field: child_with_child
prefix: part3_
postfix:
fields:
- field: field_grandson
prefix: int_
range: 10-20
postfix:
$zd
zendata is a generic data generator. You can use YAML file to define the data format and use zendata to create it.
Parameters
-d --default The default config file for data format.
-c --config The current config file for data format, and it can override the config in the default file.
-o --output The file name of the data generated. You can specify the output format by the extension name.
For example json, xml and sql. The text data in the original format is output by default.
-n --lines The number of lines of data to be generated. The default is 10.
-F --field This parameter can be used to specify the fields, separated by commas. The default is all fields.
-t --table If the output format is sql, using it to specify the table name to insert data to.
-H --human Output a readable format, print the field name, and use the tab key to split.
-p --port Run the HTTP on the specified port. The data in JSON format can be obtained via http://ip/ port.
Only data generation is supported.
-b --bind Listen IP addresses. All IP addresses are listened by default.
-r --root The root directory when running HTTP. The client can call the config file under the root directory.
If not specified, take the directory where the zd executable file is located.
-i --input Specify a sql schema file and output the YAML config file for each table.
You need to specify an output directory by using -o.
-s --server Database server type. Support mysql|oracle|sqlite|sqlserver.
The default is mysql. This parameter can be used to parse YAML files or generate SQL.
-D --decode Referring to the specified configuration file, parse the data file specified by -i and output json.
Also you can output the readable format via -H.
-e --example Print the data format config file of the example.
-l --list List all supported data formats.
-v --view View the detailed definition of a data format.
-h --help Print help.
Command Line Examples
$>zd.exe -d demo/default.yaml # Generate 10 lines of data according to the config file specified by -d.
$>zd.exe -c demo/default.yaml # Generate 10 lines of data according to the config file specified by -c.
$>zd.exe -d demo/default.yaml -c demo/test.yaml -n 100 # Using the parameter of -c and -d at the same time.
$>zd.exe -d demo/default.yaml -c demo/test.yaml -n 100 -o test.txt # Output data in original format.
$>zd.exe -d demo/default.yaml -c demo/test.yaml -n 100 -o test.json # Output data in JSON.
$>zd.exe -d demo/default.yaml -c demo/test.yaml -n 100 -o test.xml # Output data in XML.
$>zd.exe -d demo/default.yaml -n 100 -o test.sql -t user -s mysql # Output the sql inserted into the table user.
$>zd.exe -i db.sql -s mysql -o db # Generate YAML files for each table by parsing db.sql and store them in the db directory.
$>zd.exe -c demo/default.yaml -i test.txt --decode # Parse the file specified by -i according to the config of -d.
Service Example
$zd.exe -p 80 -r d:\zd\config # Listen port 80. Use d:\zd\config as the root.
Client Call
$curl http://loclahost/?d=default.yaml&c=config.yaml&n=100&o=test.sql&t=user # Specify the server config file via GET.
$curl http://loclahost/?default=default.yamloutput=test.sql&table=user # Parameter names can be full.
$curl -d "default=...&config=...&lines=10" http://localhost/ # The config can be uploaded via POST.
......@@ -24,7 +24,7 @@
},
{
"id": "enter_language",
"translation": "Enter the language you want to use:\n1. English %s\n2. Chinese %s"
"translation": "1) 请选择您要使用的语言,中文请输入数字1。\n2) Please select the language. Input 2 for English."
},
{
"id": "current_config",
......@@ -91,7 +91,11 @@
},
{
"id": "start_server",
"translation": "Success yo start zendata http service, press CTRL+C to exist. \n You may use http://%s:%s to retrieve the data,for example: \n curl http://%s:%s/?default=demo/default.yaml&config=demo/test.yaml&lines=100."
"translation": "Success yo start zendata http service, press CTRL+C to exist. \nYou may use http://%s:%s to retrieve the data,for example: \n curl http://%s:%s/?default=demo/default.yaml&config=demo/test.yaml&lines=100."
},
{
"id": "excel_data",
"translation": "Excel Data."
}
]
}
\ No newline at end of file
......@@ -19,7 +19,7 @@
},
{
"id": "enter_language",
"translation": "请输入你期望使用的语言:\n1. 英文 %s\n2. 中文 %s"
"translation": "1) 请选择您要使用的语言,中文请输入数字1。\n2) Please select the language. Input 2 for English."
},
{
"id": "current_config",
......@@ -82,7 +82,11 @@
},
{
"id": "start_server",
"translation": "zendata http服务已经成功运行,按CTRL+C键推出。\n 您可以通过http://%s:%d地址来调用,比如:\n curl http://%s:%d/?default=demo/default.yaml&config=demo/test.yaml&lines=100."
"translation": "zendata http服务已经成功运行,按CTRL+C键推出。\n您可以通过http://%s:%s地址来调用,比如:\n curl http://%s:%s/?default=demo/default.yaml&config=demo/test.yaml&lines=100."
},
{
"id": "excel_data",
"translation": "Excel数据源。"
}
]
}
\ No newline at end of file
......@@ -8,6 +8,7 @@ import (
"gopkg.in/yaml.v3"
"io/ioutil"
"regexp"
"strings"
"time"
)
......@@ -55,10 +56,15 @@ func getCreateStatement(file string) map[string]string {
re := regexp.MustCompile("(?siU)(CREATE TABLE.*;)")
arr := re.FindAllString(string(content), -1)
for _, item := range arr {
re := regexp.MustCompile("(?iU)CREATE TABLE.*`(.+)`")
arr2 := re.FindAllStringSubmatch(item, -1)
statements[arr2[0][1]] = item
re := regexp.MustCompile("(?i)CREATE TABLE.*\\s+(.+)\\s+\\(") // get table name
firstLine := strings.Split(item, "\n")[0]
arr2 := re.FindAllStringSubmatch(firstLine, -1)
if len(arr2) > 0 && len(arr2[0]) > 1 {
tableName := arr2[0][1]
tableName = strings.ReplaceAll(tableName, "`", "")
statements[tableName] = item
}
}
return statements
......@@ -67,10 +73,15 @@ func getCreateStatement(file string) map[string]string {
func getColumnsFromCreateStatement(sent string) []string {
fieldLines := make([]string, 0)
re := regexp.MustCompile("(?iU)`(.+)`\\s.*,")
re := regexp.MustCompile("(?iU)\\s*(\\S+)\\s.*\n")
arr := re.FindAllStringSubmatch(string(sent), -1)
for _, item := range arr {
fieldLines = append(fieldLines, item[1])
line := strings.ToLower(item[0])
if !strings.Contains(line, " table ") && !strings.Contains(line, " key ") {
field := item[1]
field = strings.ReplaceAll(field, "`", "")
fieldLines = append(fieldLines, field)
}
}
return fieldLines
......
package service
import (
"fmt"
"github.com/360EntSecGroup-Skylar/excelize/v2"
"github.com/easysoft/zendata/src/model"
constant "github.com/easysoft/zendata/src/utils/const"
i118Utils "github.com/easysoft/zendata/src/utils/i118"
logUtils "github.com/easysoft/zendata/src/utils/log"
"github.com/easysoft/zendata/src/utils/vari"
"github.com/mattn/go-runewidth"
"gopkg.in/yaml.v3"
"io/ioutil"
"os"
"strings"
)
const (
size = 4
)
func ListRes() {
res := map[string][size]string{}
path := vari.ExeDir + "data" + string(os.PathSeparator) + "system"
GetFilesAndDirs(path, &res)
msg := ""
nameWidth := 0
titleWidth := 0
for key, arr := range res {
path := arr[0]
if key == "yaml" {
arr[2], arr[3] = readYamlInfo(path)
} else if key == "excel" {
arr[2], arr[3] = readExcelInfo(path)
}
res[key] = arr
lent := runewidth.StringWidth(arr[1])
if lent > nameWidth {
nameWidth = lent
}
lent2 := runewidth.StringWidth(arr[2])
if lent2 > titleWidth {
titleWidth = lent2
}
}
for _, arr := range res {
name := arr[1]
name = name + strings.Repeat(" ", nameWidth - runewidth.StringWidth(name))
title := arr[2]
title = title + strings.Repeat(" ", titleWidth - runewidth.StringWidth(title))
msg = msg + fmt.Sprintf("%s %s %s\n", name, title, arr[3])
}
logUtils.Screen(msg)
}
func GetFilesAndDirs(path string, res *map[string][size]string) {
dir, err := ioutil.ReadDir(path)
if err != nil {
return
}
for _, fi := range dir {
if fi.IsDir() {
GetFilesAndDirs(path + constant.PthSep + fi.Name(), res)
} else {
name := fi.Name()
arr := [size]string{}
if strings.HasSuffix(name, ".yaml"){
arr[0] = path + constant.PthSep + name
arr[1] = path[strings.LastIndex(path, "system"):] + constant.PthSep + name
(*res)["yaml"] = arr
} else if strings.HasSuffix(name, ".xlsx") {
arr[0] = path + constant.PthSep + name
arr[1] = path[strings.LastIndex(path, "system"):] + constant.PthSep + name
(*res)["excel"] = arr
}
}
}
}
func readYamlInfo(path string) (title string, desc string) {
configDef := model.DefData{}
yamlContent, err := ioutil.ReadFile(path)
if err != nil {
logUtils.Screen(i118Utils.I118Prt.Sprintf("fail_to_read_file", path))
return
}
err = yaml.Unmarshal(yamlContent, &configDef)
if err != nil {
logUtils.Screen(i118Utils.I118Prt.Sprintf("fail_to_parse_file", path))
return
}
title = configDef.Title
desc = configDef.Desc
return
}
func readExcelInfo(path string) (title string, desc string) {
excel, err := excelize.OpenFile(path)
if err != nil {
logUtils.Screen(i118Utils.I118Prt.Sprintf("fail_to_read_file", path))
return
}
for index, sheet := range excel.GetSheetList() {
if index > 0 {
title = title + "|"
}
title = title + sheet
}
desc = i118Utils.I118Prt.Sprintf("excel_data")
return
}
\ No newline at end of file
package service
import (
"fmt"
"github.com/easysoft/zendata/src/model"
constant "github.com/easysoft/zendata/src/utils/const"
fileUtils "github.com/easysoft/zendata/src/utils/file"
i118Utils "github.com/easysoft/zendata/src/utils/i118"
logUtils "github.com/easysoft/zendata/src/utils/log"
"github.com/easysoft/zendata/src/utils/vari"
"github.com/mattn/go-runewidth"
"gopkg.in/yaml.v3"
"io/ioutil"
"strings"
)
func ViewRes(res string) {
msg := ""
resType, resPath := fileUtils.ConvertResPath(res)
if resType == "yaml" {
typ, inst, ranges := readYamlData(resPath)
if typ == "inst" {
printInst(inst)
} else if typ == "range" {
printRanges(ranges)
}
} else if resType == "excel" {
}
logUtils.Screen(msg)
}
func readYamlData(path string) (typ string, insts model.ResInsts, ranges model.ResRanges) {
if strings.Index(path, "system") > -1 {
path = vari.ExeDir + "data" + constant.PthSep + path
} else {
path = vari.ExeDir + constant.PthSep + path
}
yamlContent, err := ioutil.ReadFile(path)
if err != nil {
logUtils.Screen(i118Utils.I118Prt.Sprintf("fail_to_read_file", path))
return
}
err = yaml.Unmarshal(yamlContent, &insts)
if err == nil && insts.Instances != nil && len(insts.Instances) > 0 {
typ = "inst"
} else {
err = yaml.Unmarshal(yamlContent, &ranges)
typ = "range"
}
return
}
func readExcelSheet(path string) (str string) {
//excel, err := excelize.OpenFile(path)
//if err != nil {
// logUtils.Screen(i118Utils.I118Prt.Sprintf("fail_to_read_file", path))
// return
//}
//
//for index, sheet := range excel.GetSheetList() {
// if index > 0 {
// title = title + "|"
// }
// title = title + sheet
//}
//
//desc = i118Utils.I118Prt.Sprintf("excel_data")
return
}
func readExcelData(path string) (str string) {
//excel, err := excelize.OpenFile(path)
//if err != nil {
// logUtils.Screen(i118Utils.I118Prt.Sprintf("fail_to_read_file", path))
// return
//}
//
//for index, sheet := range excel.GetSheetList() {
// if index > 0 {
// title = title + "|"
// }
// title = title + sheet
//}
//
//desc = i118Utils.I118Prt.Sprintf("excel_data")
return
}
func printInst(inst model.ResInsts) {
msg := ""
msg = msg + inst.Title + " " + inst.Desc + "\n"
width := 0
for _, item := range inst.Instances {
lent := runewidth.StringWidth(item.Instance)
if lent > width {
width = lent
}
}
for idx, item := range inst.Instances {
if idx > 0 { msg = msg + "\n" }
msg = msg + fmt.Sprintf("%d. %s - %s",
idx+1, item.Instance + strings.Repeat(" ", width -len(item.Instance)), item.Note)
}
logUtils.Screen(msg)
}
func printRanges(ranges model.ResRanges) {
msg := ""
msg = msg + ranges.Title + " " + ranges.Desc + "\n"
width := 0
for name, _ := range ranges.Ranges {
lent := runewidth.StringWidth(name)
if lent > width {
width = lent
}
}
i := 0
for name, item := range ranges.Ranges {
if i > 0 { msg = msg + "\n" }
msg = msg + fmt.Sprintf("%d. %s - %s", i+1, name + strings.Repeat(" ", width -len(name)), item)
i++
}
logUtils.Screen(msg)
}
\ No newline at end of file
package configUtils
import (
"github.com/easysoft/zendata/src/utils/display"
"github.com/easysoft/zendata/src/utils/i118"
"fmt"
"github.com/easysoft/zendata/src/model"
commonUtils "github.com/easysoft/zendata/src/utils/common"
constant "github.com/easysoft/zendata/src/utils/const"
fileUtils "github.com/easysoft/zendata/src/utils/file"
i118Utils "github.com/easysoft/zendata/src/utils/i118"
logUtils "github.com/easysoft/zendata/src/utils/log"
shellUtils "github.com/easysoft/zendata/src/utils/shell"
stdinUtils "github.com/easysoft/zendata/src/utils/stdin"
"github.com/easysoft/zendata/src/utils/vari"
"github.com/fatih/color"
"gopkg.in/ini.v1"
"os"
"reflect"
)
func InitConfig() {
InitScreenSize()
vari.ExeDir = fileUtils.GetExeDir()
CheckConfigPermission()
if commonUtils.IsWin() {
shellUtils.ExeShell("chcp 65001")
}
constant.ConfigFile = vari.ExeDir + constant.ConfigFile
vari.Config = getInst()
i118Utils.InitI118(vari.Config.Language)
}
func InitScreenSize() {
w, h := display.GetScreenSize()
vari.ScreenWidth = w
vari.ScreenHeight = h
}
\ No newline at end of file
func SaveConfig(conf model.Config) error {
fileUtils.MkDirIfNeeded(fileUtils.GetExeDir() + "conf")
conf.Version = constant.ConfigVer
cfg := ini.Empty()
cfg.ReflectFrom(&conf)
cfg.SaveTo(constant.ConfigFile)
vari.Config = ReadCurrConfig()
return nil
}
func PrintCurrConfig() {
logUtils.PrintToWithColor("\n"+i118Utils.I118Prt.Sprintf("current_config"), color.FgCyan)
val := reflect.ValueOf(vari.Config)
typeOfS := val.Type()
for i := 0; i < reflect.ValueOf(vari.Config).NumField(); i++ {
if !commonUtils.IsWin() && i > 4 {
break
}
val := val.Field(i)
name := typeOfS.Field(i).Name
fmt.Printf(" %s: %v \n", name, val.Interface())
}
}
func ReadCurrConfig() model.Config {
config := model.Config{}
configPath := constant.ConfigFile
if !fileUtils.FileExist(configPath) {
config.Language = "en"
i118Utils.InitI118("en")
return config
}
ini.MapTo(&config, constant.ConfigFile)
return config
}
func getInst() model.Config {
isSetAction := len(os.Args) > 1 && (os.Args[1] == "set" || os.Args[1] == "-set")
if !isSetAction {
CheckConfigReady()
}
ini.MapTo(&vari.Config, constant.ConfigFile)
if vari.Config.Version != constant.ConfigVer { // old config file, re-init
if vari.Config.Language != "en" && vari.Config.Language != "zh" {
vari.Config.Language = "en"
}
SaveConfig(vari.Config)
}
return vari.Config
}
func CheckConfigPermission() {
//err := syscall.Access(vari.ExeDir, syscall.O_RDWR)
err := fileUtils.MkDirIfNeeded(vari.ExeDir + "conf")
if err != nil {
logUtils.PrintToWithColor(
fmt.Sprintf("Permission denied, please change the dir %s.", vari.ExeDir), color.FgRed)
os.Exit(0)
}
}
func CheckConfigReady() {
if !fileUtils.FileExist(constant.ConfigFile) {
InputForSet()
}
}
func InputForSet() {
conf := ReadCurrConfig()
//logUtils.PrintToWithColor(i118Utils.I118Prt.Sprintf("begin_config"), color.FgCyan)
enCheck := ""
var numb string
if conf.Language == "en" {
enCheck = "*"
numb = "1"
}
zhCheck := ""
if conf.Language == "zh" {
zhCheck = "*"
numb = "2"
}
numbSelected := stdinUtils.GetInput("(1|2)", numb, "enter_language", enCheck, zhCheck)
if numbSelected == "1" {
conf.Language = "en"
} else {
conf.Language = "zh"
}
SaveConfig(conf)
PrintCurrConfig()
}
......@@ -6,6 +6,8 @@ import (
)
var (
PthSep = string(os.PathSeparator)
ConfigVer = 1
ConfigFile = fmt.Sprintf("conf%szdata.conf", string(os.PathSeparator))
......
......@@ -241,3 +241,24 @@ func GetAbsDir(path string) string {
return abs
}
func ConvertResPath(path string) (resType, resFile string) {
index := strings.LastIndex(path, ".yaml")
if index > -1 { // yaml, system.ip.v1.yaml
left := path[:index]
left = strings.ReplaceAll(left, ".", constant.PthSep)
resFile = left + ".yaml"
resType = "yaml"
} else { // excel, system.address.v1.city
index = strings.LastIndex(path, ".")
left := path[:index]
left = strings.ReplaceAll(left, ".", constant.PthSep)
resFile = left + ".xlsx"
resType = "excel"
}
return
}
......@@ -8,7 +8,6 @@ import (
commonUtils "github.com/easysoft/zendata/src/utils/common"
configUtils "github.com/easysoft/zendata/src/utils/config"
constant "github.com/easysoft/zendata/src/utils/const"
fileUtils "github.com/easysoft/zendata/src/utils/file"
i118Utils "github.com/easysoft/zendata/src/utils/i118"
logUtils "github.com/easysoft/zendata/src/utils/log"
stringUtils "github.com/easysoft/zendata/src/utils/string"
......@@ -36,6 +35,7 @@ var (
table string
format = constant.FormatText
listRes bool
viewRes string
viewDetail string
......@@ -77,8 +77,11 @@ func main() {
flagSet.StringVar(&table, "t", "table_name", "")
flagSet.StringVar(&table, "table", "table_name", "")
flagSet.BoolVar(&listRes, "l", false, "")
flagSet.BoolVar(&listRes, "list", false, "")
flagSet.StringVar(&viewRes, "v", "", "")
flagSet.StringVar(&viewDetail, "vv", "", "")
flagSet.StringVar(&viewRes, "view", "", "")
flagSet.StringVar(&vari.HeadSep, "H", "", "")
flagSet.StringVar(&vari.HeadSep, "human", "", "")
......@@ -117,6 +120,14 @@ func main() {
default:
flagSet.SetOutput(ioutil.Discard)
if err := flagSet.Parse(os.Args[1:]); err == nil {
if listRes {
service.ListRes()
return
} else if viewRes != "" {
service.ViewRes(viewRes)
return
}
if vari.Ip != "" || vari.Port != 0 {
vari.RunMode = constant.RunModeServer
} else if input != "" {
......@@ -132,13 +143,10 @@ func main() {
func toGen() {
if vari.RunMode == constant.RunModeServer {
vari.ExeDir = fileUtils.GetExeDir()
StartServer()
} else if vari.RunMode == constant.RunModeParse {
action.ParseSql(input, output)
} else if vari.RunMode == constant.RunModeGen {
vari.ExeDir = fileUtils.GetExeDir()
if root != "" {
vari.ExeDir = root
}
......
cd build
cp zd-x86.exe zd.exe
zip -r zd-win-x86-1.1.zip zd.exe data demo
zip -r zd-win-x86-1.1.zip zd.exe conf data demo
rm zd.exe
cp zd-amd64.exe zd.exe
zip -r zd-win-amd64-1.1.zip zd.exe data demo
zip -r zd-win-amd64-1.1.zip zd.exe conf data demo
rm zd.exe
cp zd-linux zd
tar -zcvf zd-linux-1.1.tar.gz zd data demo
tar -zcvf zd-linux-1.1.tar.gz zd conf data demo
rm zd
cp zd-mac zd
zip -r zd-mac-1.1.zip zd data demo
zip -r zd-mac-1.1.zip zd conf data demo
rm zd
cd ..
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册