54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
package cmd
|
|
|
|
import (
|
|
"complie-erlang/parser/zm_lib"
|
|
"fmt"
|
|
"github.com/spf13/cobra"
|
|
"log"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
type ErrCode struct {
|
|
debug bool
|
|
|
|
ErrPath string
|
|
Plugin string // 代码根目录
|
|
|
|
}
|
|
|
|
func (s *ErrCode) run(_ *cobra.Command, arg []string) {
|
|
pluginPathByWd, err := zm_lib.GetPluginPathByWd(s.Plugin)
|
|
if err != nil {
|
|
log.Printf("[warn] plugin path no find:%s", err.Error())
|
|
pluginPathByWd = ""
|
|
}
|
|
errPath := filepath.Join(pluginPathByWd, s.ErrPath)
|
|
|
|
fmt.Printf("errPath:%s %s\n", pluginPathByWd, errPath)
|
|
errorLanguageBytes, err := os.ReadFile(errPath)
|
|
if err != nil {
|
|
log.Printf("[error] read errPath:%s %s\n", errPath, err.Error())
|
|
return
|
|
}
|
|
|
|
fmt.Printf("errPath:%s %s\n", errorLanguageBytes, errPath)
|
|
|
|
}
|
|
|
|
func init() {
|
|
var singleSet = new(ErrCode)
|
|
var logsCmd = &cobra.Command{
|
|
Use: "err_code",
|
|
Short: "根据proto 文件构建 功能模版",
|
|
Long: `构建功能数据`,
|
|
Run: singleSet.run,
|
|
}
|
|
|
|
logsCmd.PersistentFlags().BoolVar(&singleSet.debug, "debug", false, "是否启动调试模式")
|
|
logsCmd.PersistentFlags().StringVar(&singleSet.ErrPath, "path", ".cfg/ErrorLanguage.txt", "错误码地址(相对于根目录)")
|
|
logsCmd.PersistentFlags().StringVar(&singleSet.Plugin, "plugin", "plugin", "代码根目录")
|
|
|
|
rootCmd.AddCommand(logsCmd)
|
|
}
|