调整结构
This commit is contained in:
@@ -63,6 +63,7 @@ func ExecuteSingleDir(args []string) {
|
||||
}
|
||||
|
||||
for _, filename := range erlFiles {
|
||||
// 根据配置解析出 文件数据
|
||||
parseTemKey, err := worker1.ParseTemKey(filename, cfgPublic)
|
||||
if err != nil {
|
||||
log.Fatalf("loading templates: %v", err)
|
||||
|
||||
@@ -20,7 +20,10 @@ func ParseErlangFile(filePath string) (*ModuleInfo, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("读取文件失败: %v", err)
|
||||
}
|
||||
return ParseErlangFileByBytes(filePath, content)
|
||||
}
|
||||
|
||||
func ParseErlangFileByBytes(filePath string, content []byte) (*ModuleInfo, error) {
|
||||
lines := strings.Split(string(content), "\n")
|
||||
moduleInfo := &ModuleInfo{
|
||||
FilePath: filePath,
|
||||
|
||||
@@ -23,11 +23,13 @@ func NewSingleFile(templater *template.Template) *SingleFile {
|
||||
|
||||
func (s *SingleFile) ParseTemKey(filename string, Keyword config.ErlangTemKey) ([]string, error) {
|
||||
|
||||
// 解析整个文件
|
||||
erlangFile, err := parser.ParseErlangFile(filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 格式化 模板参数
|
||||
var result []string
|
||||
for _, function := range erlangFile.Functions {
|
||||
if len(function.KeyMap[Keyword.Name]) == 0 {
|
||||
@@ -64,6 +66,8 @@ func (s *SingleFile) ParseTemKey(filename string, Keyword config.ErlangTemKey) (
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// 去除空行
|
||||
func removeEmptyLinesUniversal(text string) string {
|
||||
var result strings.Builder
|
||||
scanner := bufio.NewScanner(strings.NewReader(text))
|
||||
@@ -81,6 +85,11 @@ func removeEmptyLinesUniversal(text string) string {
|
||||
|
||||
// FindConfigXMLPath 1. 打印当前 exe 文件夹内的 config.xml 文件的绝对路径
|
||||
func (s *SingleFile) FindConfigXMLPath(cfgFile string) (string, error) {
|
||||
// 判断是否是绝对路径若是则直接返回
|
||||
if filepath.IsAbs(cfgFile) {
|
||||
return cfgFile, nil
|
||||
}
|
||||
|
||||
// 获取可执行文件所在目录
|
||||
exePath, err := os.Executable()
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user