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