feat(cmd/joj3): hint valid scopes on file not found
All checks were successful
build / build (push) Successful in 1m21s
build / build (pull_request) Successful in 1m19s
build / trigger-build-image (push) Has been skipped
build / trigger-build-image (pull_request) Has been skipped

This commit is contained in:
张泊明518370910136 2024-10-18 02:07:40 -04:00 committed by 张泊明518370910136
parent b75a756998
commit d8fe809598
2 changed files with 8 additions and 11 deletions

View File

@ -228,10 +228,10 @@ func ParseMsg(confRoot, confName, msg, tag string) (confPath, group string, err
return
}
func ListValidScopes(confRoot, confName string) ([]string, error) {
func HintValidScopes(confRoot, confName string) {
confRoot = filepath.Clean(confRoot)
validScopes := []string{}
err := filepath.Walk(confRoot, func(
_ = filepath.Walk(confRoot, func(
path string, info os.FileInfo, err error,
) error {
if err != nil {
@ -254,7 +254,8 @@ func ListValidScopes(confRoot, confName string) ([]string, error) {
}
return nil
})
return validScopes, err
slog.Info("HINT: use valid scopes in commit message",
"valid scopes", validScopes)
}
func CheckExpire(conf *Conf) error {

View File

@ -48,20 +48,16 @@ func mainImpl() error {
confPath, group, err := conf.ParseMsg(confRoot, confName, msg, tag)
if err != nil {
slog.Error("parse msg", "error", err)
validScopes, scopeErr := conf.ListValidScopes(
confRoot, confName)
if scopeErr != nil {
slog.Error("list valid scopes", "error", scopeErr)
return err
}
slog.Info("HINT: use valid scopes in commit message",
"valid scopes", validScopes)
conf.HintValidScopes(confRoot, confName)
return err
}
slog.Info("try to load conf", "path", confPath)
confObj, err := conf.ParseConfFile(confPath)
if err != nil {
slog.Error("parse conf", "error", err)
if _, statErr := os.Stat(confPath); os.IsNotExist(statErr) {
conf.HintValidScopes(confRoot, confName)
}
return err
}
slog.Debug("conf loaded", "conf", confObj)