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

new features for 1.1

上级 8b22902c
...@@ -47,16 +47,13 @@ func Generate(deflt string, yml string, total int, fieldsToExportStr string, out ...@@ -47,16 +47,13 @@ func Generate(deflt string, yml string, total int, fieldsToExportStr string, out
WriteToFile(out, content) WriteToFile(out, content)
} }
if vari.Ip != "" || vari.Port != 0 || vari.Root != ""{ if vari.Ip != "" || vari.Port != 0 {
if vari.Ip == "" { if vari.Ip == "" {
vari.Ip = commonUtils.GetIp() vari.Ip = commonUtils.GetIp()
} }
if vari.Port == 0 { if vari.Port == 0 {
vari.Port = constant.DefaultPort vari.Port = constant.DefaultPort
} }
if vari.Root == "" {
vari.Root = constant.DefaultRoot
}
logUtils.PrintToWithColor(i118Utils.I118Prt.Sprintf("start_server"), color.FgCyan) logUtils.PrintToWithColor(i118Utils.I118Prt.Sprintf("start_server"), color.FgCyan)
...@@ -127,7 +124,7 @@ func Print(rows [][]string, format string, table string, colTypes []bool, fields ...@@ -127,7 +124,7 @@ func Print(rows [][]string, format string, table string, colTypes []bool, fields
} }
respJson := "[]" respJson := "[]"
if format == constant.FormatJson || vari.HttpService { if format == constant.FormatJson || vari.Ip != "" || vari.Port != 0 {
if vari.WithHead { if vari.WithHead {
mapArr := RowsToMap(rows, fields) mapArr := RowsToMap(rows, fields)
jsonObj, _ := json.Marshal(mapArr) jsonObj, _ := json.Marshal(mapArr)
......
...@@ -39,7 +39,7 @@ func loadResField(field *model.DefField, res *map[string]map[string][]string) { ...@@ -39,7 +39,7 @@ func loadResField(field *model.DefField, res *map[string]map[string][]string) {
} }
} }
func getResProp(from string) (string, string) { func getResProp(from string) (string, string) { // from resource
resFile := "" resFile := ""
resType := "" resType := ""
...@@ -62,14 +62,17 @@ func getResProp(from string) (string, string) { ...@@ -62,14 +62,17 @@ func getResProp(from string) (string, string) {
resType = "excel" resType = "excel"
} }
if strings.Index(resFile, "system") == -1 { // no system cls if strings.Index(resFile, "system") == -1 { // no system resource
resFile = vari.InputDir + resFile resFile = vari.WorkDir + resFile
if !fileUtils.FileExist(resFile) { // not in work dir
resFile = vari.InputDir + resFile
if !fileUtils.FileExist(resFile) { // not in input dir if !fileUtils.FileExist(resFile) { // not in input dir (same dir as yaml file in)
resFile = vari.ExeDir + resFile resFile = vari.ExeDir + resFile
if !fileUtils.FileExist(resFile) { // not in exe dir if !fileUtils.FileExist(resFile) { // not in exe dir
resFile = "" resFile = ""
}
} }
} }
} else { } else {
......
...@@ -2,15 +2,11 @@ package configUtils ...@@ -2,15 +2,11 @@ package configUtils
import ( import (
"github.com/easysoft/zendata/src/utils/display" "github.com/easysoft/zendata/src/utils/display"
fileUtils "github.com/easysoft/zendata/src/utils/file"
"github.com/easysoft/zendata/src/utils/i118" "github.com/easysoft/zendata/src/utils/i118"
"github.com/easysoft/zendata/src/utils/vari" "github.com/easysoft/zendata/src/utils/vari"
) )
func InitConfig() { func InitConfig() {
vari.ExeDir = fileUtils.GetExeDir()
vari.WorkDir = fileUtils.GetWorkDir()
InitScreenSize() InitScreenSize()
i118Utils.InitI118(vari.Config.Language) i118Utils.InitI118(vari.Config.Language)
......
...@@ -133,7 +133,7 @@ func ReadResData(path string) string { ...@@ -133,7 +133,7 @@ func ReadResData(path string) string {
return jsonStr return jsonStr
} }
func GetExeDir() string { // where ztf command in func GetExeDir() string { // where zd.exe file in
var dir string var dir string
arg1 := strings.ToLower(os.Args[0]) arg1 := strings.ToLower(os.Args[0])
...@@ -154,7 +154,7 @@ func GetExeDir() string { // where ztf command in ...@@ -154,7 +154,7 @@ func GetExeDir() string { // where ztf command in
return dir return dir
} }
func GetWorkDir() string { // where ztf command in func GetWorkDir() string { // where run command in
dir, _ := os.Getwd() dir, _ := os.Getwd()
dir, _ = filepath.Abs(dir) dir, _ = filepath.Abs(dir)
dir = UpdateDir(dir) dir = UpdateDir(dir)
......
...@@ -32,5 +32,4 @@ var ( ...@@ -32,5 +32,4 @@ var (
JsonResp string = "[]" JsonResp string = "[]"
Ip string Ip string
Port int Port int
Root string
) )
...@@ -5,6 +5,7 @@ import ( ...@@ -5,6 +5,7 @@ import (
"github.com/easysoft/zendata/src/action" "github.com/easysoft/zendata/src/action"
configUtils "github.com/easysoft/zendata/src/utils/config" configUtils "github.com/easysoft/zendata/src/utils/config"
constant "github.com/easysoft/zendata/src/utils/const" constant "github.com/easysoft/zendata/src/utils/const"
fileUtils "github.com/easysoft/zendata/src/utils/file"
logUtils "github.com/easysoft/zendata/src/utils/log" logUtils "github.com/easysoft/zendata/src/utils/log"
stringUtils "github.com/easysoft/zendata/src/utils/string" stringUtils "github.com/easysoft/zendata/src/utils/string"
"github.com/easysoft/zendata/src/utils/vari" "github.com/easysoft/zendata/src/utils/vari"
...@@ -23,6 +24,7 @@ var ( ...@@ -23,6 +24,7 @@ var (
count int count int
fields string fields string
root string
input string input string
output string output string
table string table string
...@@ -86,8 +88,8 @@ func main() { ...@@ -86,8 +88,8 @@ func main() {
flagSet.StringVar(&vari.Ip, "bind", "", "") flagSet.StringVar(&vari.Ip, "bind", "", "")
flagSet.IntVar(&vari.Port, "p", 0, "") flagSet.IntVar(&vari.Port, "p", 0, "")
flagSet.IntVar(&vari.Port, "port", 0, "") flagSet.IntVar(&vari.Port, "port", 0, "")
flagSet.StringVar(&vari.Root, "r", "", "") flagSet.StringVar(&root, "r", "", "")
flagSet.StringVar(&vari.Root, "root", "", "") flagSet.StringVar(&root, "root", "", "")
flagSet.BoolVar(&example, "e", false, "") flagSet.BoolVar(&example, "e", false, "")
flagSet.BoolVar(&example, "example", false, "") flagSet.BoolVar(&example, "example", false, "")
...@@ -120,6 +122,13 @@ func main() { ...@@ -120,6 +122,13 @@ func main() {
func gen(args []string) { func gen(args []string) {
flagSet.SetOutput(ioutil.Discard) flagSet.SetOutput(ioutil.Discard)
if err := flagSet.Parse(args[2:]); err == nil { if err := flagSet.Parse(args[2:]); err == nil {
vari.ExeDir = fileUtils.GetExeDir()
vari.WorkDir = fileUtils.GetWorkDir()
if root != "" {
vari.WorkDir = root
}
// vari.InputDir will init for different gen type
if vari.HeadSep != "" { if vari.HeadSep != "" {
vari.WithHead = true vari.WithHead = true
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册