feat(cmd/joj3): hint valid scopes on file not found #67
|  | @ -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 { | ||||
|  |  | |||
|  | @ -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) | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user