refactor(cmd/joj3): split parse msg & parse conf file
This commit is contained in:
parent
f8a7ae6067
commit
9cd0e44678
|
@ -144,7 +144,7 @@ func parseConventionalCommit(commit string) (*ConventionalCommit, error) {
|
|||
return cc, nil
|
||||
}
|
||||
|
||||
func parseConfFile(path string) (conf Conf, err error) {
|
||||
func ParseConfFile(path string) (conf Conf, err error) {
|
||||
d := &multiconfig.DefaultLoader{}
|
||||
d.Loader = multiconfig.MultiLoader(
|
||||
&multiconfig.TagLoader{},
|
||||
|
@ -191,7 +191,7 @@ func parseConfFile(path string) (conf Conf, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func ParseMsg(confRoot, confName, msg string) (conf Conf, group string, err error) {
|
||||
func ParseMsg(confRoot, confName, msg string) (confPath, group string, err error) {
|
||||
slog.Info("parse msg", "msg", msg)
|
||||
conventionalCommit, err := parseConventionalCommit(msg)
|
||||
if err != nil {
|
||||
|
@ -199,7 +199,7 @@ func ParseMsg(confRoot, confName, msg string) (conf Conf, group string, err erro
|
|||
}
|
||||
slog.Info("conventional commit", "commit", conventionalCommit)
|
||||
confRoot = filepath.Clean(confRoot)
|
||||
confPath := filepath.Clean(fmt.Sprintf("%s/%s/%s",
|
||||
confPath = filepath.Clean(fmt.Sprintf("%s/%s/%s",
|
||||
confRoot, conventionalCommit.Scope, confName))
|
||||
relPath, err := filepath.Rel(confRoot, confPath)
|
||||
if err != nil {
|
||||
|
@ -209,11 +209,6 @@ func ParseMsg(confRoot, confName, msg string) (conf Conf, group string, err erro
|
|||
err = fmt.Errorf("invalid scope as path: %s", conventionalCommit.Scope)
|
||||
return
|
||||
}
|
||||
slog.Info("try to load conf", "path", confPath)
|
||||
conf, err = parseConfFile(confPath)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
groupKeywords := []string{"joj"}
|
||||
for _, groupKeyword := range groupKeywords {
|
||||
if strings.Contains(
|
||||
|
@ -222,7 +217,6 @@ func ParseMsg(confRoot, confName, msg string) (conf Conf, group string, err erro
|
|||
break
|
||||
}
|
||||
}
|
||||
slog.Debug("conf loaded", "conf", conf)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ func mainImpl() error {
|
|||
return err
|
||||
}
|
||||
}
|
||||
confObj, group, err := conf.ParseMsg(confRoot, confName, msg)
|
||||
confPath, group, err := conf.ParseMsg(confRoot, confName, msg)
|
||||
if err != nil {
|
||||
slog.Error("parse msg", "error", err)
|
||||
validScopes, scopeErr := conf.ListValidScopes(
|
||||
|
@ -58,6 +58,13 @@ func mainImpl() error {
|
|||
"valid scopes", validScopes)
|
||||
return err
|
||||
}
|
||||
slog.Info("try to load conf", "path", confPath)
|
||||
confObj, err := conf.ParseConfFile(confPath)
|
||||
if err != nil {
|
||||
slog.Error("parse conf", "error", err)
|
||||
return err
|
||||
}
|
||||
slog.Debug("conf loaded", "conf", confObj)
|
||||
if err := setupSlog(confObj.LogPath); err != nil { // after conf is loaded
|
||||
slog.Error("setup slog", "error", err)
|
||||
return err
|
||||
|
|
Loading…
Reference in New Issue
Block a user