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 | 	return | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func ListValidScopes(confRoot, confName string) ([]string, error) { | func HintValidScopes(confRoot, confName string) { | ||||||
| 	confRoot = filepath.Clean(confRoot) | 	confRoot = filepath.Clean(confRoot) | ||||||
| 	validScopes := []string{} | 	validScopes := []string{} | ||||||
| 	err := filepath.Walk(confRoot, func( | 	_ = filepath.Walk(confRoot, func( | ||||||
| 		path string, info os.FileInfo, err error, | 		path string, info os.FileInfo, err error, | ||||||
| 	) error { | 	) error { | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
|  | @ -254,7 +254,8 @@ func ListValidScopes(confRoot, confName string) ([]string, error) { | ||||||
| 		} | 		} | ||||||
| 		return nil | 		return nil | ||||||
| 	}) | 	}) | ||||||
| 	return validScopes, err | 	slog.Info("HINT: use valid scopes in commit message", | ||||||
|  | 		"valid scopes", validScopes) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func CheckExpire(conf *Conf) error { | func CheckExpire(conf *Conf) error { | ||||||
|  |  | ||||||
|  | @ -48,20 +48,16 @@ func mainImpl() error { | ||||||
| 	confPath, group, err := conf.ParseMsg(confRoot, confName, msg, tag) | 	confPath, group, err := conf.ParseMsg(confRoot, confName, msg, tag) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		slog.Error("parse msg", "error", err) | 		slog.Error("parse msg", "error", err) | ||||||
| 		validScopes, scopeErr := conf.ListValidScopes( | 		conf.HintValidScopes(confRoot, confName) | ||||||
| 			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) |  | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| 	slog.Info("try to load conf", "path", confPath) | 	slog.Info("try to load conf", "path", confPath) | ||||||
| 	confObj, err := conf.ParseConfFile(confPath) | 	confObj, err := conf.ParseConfFile(confPath) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		slog.Error("parse conf", "error", err) | 		slog.Error("parse conf", "error", err) | ||||||
|  | 		if _, statErr := os.Stat(confPath); os.IsNotExist(statErr) { | ||||||
|  | 			conf.HintValidScopes(confRoot, confName) | ||||||
|  | 		} | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| 	slog.Debug("conf loaded", "conf", confObj) | 	slog.Debug("conf loaded", "conf", confObj) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user