整理打印
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
/test_plugin/
|
||||||
+5
-1
@@ -78,6 +78,8 @@ func (s *Pb2Port) run(_ *cobra.Command, arg []string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
abs1, _ := filepath.Abs(s.out)
|
||||||
|
fmt.Printf("[warn] 原文件已存在 > %s:1\n", abs1)
|
||||||
s.out = filepath.Base(s.out)[:len(filepath.Base(s.out))-len(filepath.Ext(s.out))]
|
s.out = filepath.Base(s.out)[:len(filepath.Base(s.out))-len(filepath.Ext(s.out))]
|
||||||
s.out = s.out + "_gen.erl"
|
s.out = s.out + "_gen.erl"
|
||||||
}
|
}
|
||||||
@@ -91,7 +93,9 @@ func (s *Pb2Port) run(_ *cobra.Command, arg []string) {
|
|||||||
log.Printf("Err 写入文件失败: %v", err)
|
log.Printf("Err 写入文件失败: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fmt.Println("ok")
|
|
||||||
|
abs, _ := filepath.Abs(s.out)
|
||||||
|
fmt.Printf(" \n生成文件\n > %s:0\n", abs)
|
||||||
}
|
}
|
||||||
func init() {
|
func init() {
|
||||||
var singleSet = new(Pb2Port)
|
var singleSet = new(Pb2Port)
|
||||||
|
|||||||
+19
-2
@@ -4,6 +4,8 @@ import (
|
|||||||
"complie-erlang/config"
|
"complie-erlang/config"
|
||||||
tm "complie-erlang/template"
|
tm "complie-erlang/template"
|
||||||
"complie-erlang/worker"
|
"complie-erlang/worker"
|
||||||
|
"fmt"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
@@ -62,7 +64,7 @@ func ExecuteSingleDir(args []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, filename := range erlFiles {
|
for _, filename := range erlFiles {
|
||||||
log.Printf("[info] 检索到文件: %v %s\n", cfgPublic.Filename, filename)
|
fmt.Printf("[info] 检索到文件: %v %s:1\n", cfgPublic.Filename, filename)
|
||||||
// 根据配置解析出 文件数据
|
// 根据配置解析出 文件数据
|
||||||
parseTemKey, err := worker1.ParseTemKey(filename, cfgPublic)
|
parseTemKey, err := worker1.ParseTemKey(filename, cfgPublic)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -89,8 +91,23 @@ func ExecuteSingleDir(args []string) {
|
|||||||
log.Printf("[warn] 生成文件失败: %v %s", err, outFileNema)
|
log.Printf("[warn] 生成文件失败: %v %s", err, outFileNema)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
log.Printf("[info] 生成文件: %s\n", outFileNema)
|
fmt.Printf("[info] 生成文件: %s:1\n\n", outFileNema)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
var logsCmd = &cobra.Command{
|
||||||
|
Use: "cfg",
|
||||||
|
Short: "配置生成",
|
||||||
|
Long: `根据 标注 构建 功能配置模版`,
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
if len(args) == 0 {
|
||||||
|
args = []string{"config.yaml"}
|
||||||
|
}
|
||||||
|
ExecuteSingleDir(args)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
rootCmd.AddCommand(logsCmd)
|
||||||
|
}
|
||||||
|
|||||||
@@ -124,6 +124,14 @@ func parseFunctions(lines []string, exportedFunctions map[string]bool) []ErlangF
|
|||||||
inFunction = false
|
inFunction = false
|
||||||
currentFunction = ErlangFunction{}
|
currentFunction = ErlangFunction{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 函数结束条件:行以 ; 结束,且括号和花括号匹配
|
||||||
|
if strings.HasSuffix(trimmedLine, ";") && braceCount == 0 && parenCount == 0 {
|
||||||
|
currentFunction.EndLine = i + 1
|
||||||
|
functions = append(functions, currentFunction.ParseComments())
|
||||||
|
inFunction = false
|
||||||
|
currentFunction = ErlangFunction{}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// 不在函数中时,遇到非注释行就清空注释缓存
|
// 不在函数中时,遇到非注释行就清空注释缓存
|
||||||
if trimmedLine != "" && !strings.HasPrefix(trimmedLine, "%") {
|
if trimmedLine != "" && !strings.HasPrefix(trimmedLine, "%") {
|
||||||
|
|||||||
@@ -51,3 +51,22 @@ func FprintfArgsMap(layer int, out io.Writer, argsMap map[string]any) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FindPathByWd 返回目录基于执行目录
|
||||||
|
func FindPathByWd(path string) (string, error) {
|
||||||
|
return FindPathByBasePath(os.Getwd, path)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindPathByExecutable 返回目录基于exe路径
|
||||||
|
func FindPathByExecutable(path string) (string, error) {
|
||||||
|
return FindPathByBasePath(os.Executable, path)
|
||||||
|
}
|
||||||
|
|
||||||
|
func FindPathByBasePath(basefun func() (basePath string, err error), path string) (string, error) {
|
||||||
|
basePath, err := basefun()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
path = filepath.Join(filepath.Dir(basePath), path)
|
||||||
|
return path, nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package template
|
package template
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
)
|
)
|
||||||
@@ -18,6 +19,16 @@ var DefaultFuncMap = template.FuncMap{
|
|||||||
splits := strings.Split(str, "/")
|
splits := strings.Split(str, "/")
|
||||||
return splits[len(splits)-1]
|
return splits[len(splits)-1]
|
||||||
},
|
},
|
||||||
|
"exports": func(port []any) string {
|
||||||
|
var out []string
|
||||||
|
for _, p := range port {
|
||||||
|
p2 := p.(map[string]interface{})
|
||||||
|
splits := strings.Split(p2["Cmd"].(string), "/")
|
||||||
|
funcName := splits[len(splits)-1]
|
||||||
|
out = append(out, fmt.Sprintf("%s/5", funcName))
|
||||||
|
}
|
||||||
|
return strings.Join(out, ",")
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func hd(str []string) string {
|
func hd(str []string) string {
|
||||||
|
|||||||
Reference in New Issue
Block a user