forked from Plemya-x/ALR
		
	update config module
This commit is contained in:
		@@ -59,8 +59,8 @@ type PackageFinder interface {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type Config interface {
 | 
			
		||||
	GetPaths(ctx context.Context) *config.Paths
 | 
			
		||||
	PagerStyle(ctx context.Context) string
 | 
			
		||||
	GetPaths() *config.Paths
 | 
			
		||||
	PagerStyle() string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type Builder struct {
 | 
			
		||||
@@ -88,7 +88,7 @@ func NewBuilder(
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (b *Builder) UpdateOptsFromPkg(pkg *db.Package, packages []string) {
 | 
			
		||||
	repodir := b.config.GetPaths(b.ctx).RepoDir
 | 
			
		||||
	repodir := b.config.GetPaths().RepoDir
 | 
			
		||||
	b.opts.Repository = pkg.Repository
 | 
			
		||||
	if pkg.BasePkgName != "" {
 | 
			
		||||
		b.opts.Script = filepath.Join(repodir, pkg.Repository, pkg.BasePkgName, "alr.sh")
 | 
			
		||||
@@ -149,7 +149,7 @@ func (b *Builder) BuildPackage(ctx context.Context) ([]string, []string, error)
 | 
			
		||||
		ctx,
 | 
			
		||||
		b.opts.Script,
 | 
			
		||||
		basePkg,
 | 
			
		||||
		b.config.PagerStyle(ctx),
 | 
			
		||||
		b.config.PagerStyle(),
 | 
			
		||||
		b.opts.Interactive,
 | 
			
		||||
	)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -392,7 +392,7 @@ func (b *Builder) getDirs(basePkg string) (types.Directories, error) {
 | 
			
		||||
		return types.Directories{}, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	baseDir := filepath.Join(b.config.GetPaths(b.ctx).PkgsDir, basePkg) // Определяем базовую директорию
 | 
			
		||||
	baseDir := filepath.Join(b.config.GetPaths().PkgsDir, basePkg) // Определяем базовую директорию
 | 
			
		||||
	return types.Directories{
 | 
			
		||||
		BaseDir:   baseDir,
 | 
			
		||||
		SrcDir:    filepath.Join(baseDir, "src"),
 | 
			
		||||
 
 | 
			
		||||
@@ -144,11 +144,11 @@ func (m *TestManager) IsInstalled(pkg string) (bool, error) {
 | 
			
		||||
 | 
			
		||||
type TestConfig struct{}
 | 
			
		||||
 | 
			
		||||
func (c *TestConfig) PagerStyle(ctx context.Context) string {
 | 
			
		||||
func (c *TestConfig) PagerStyle() string {
 | 
			
		||||
	return "native"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (c *TestConfig) GetPaths(ctx context.Context) *config.Paths {
 | 
			
		||||
func (c *TestConfig) GetPaths() *config.Paths {
 | 
			
		||||
	return &config.Paths{
 | 
			
		||||
		CacheDir: "/tmp",
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -67,7 +67,7 @@ type action struct {
 | 
			
		||||
// If repos is set to nil, the repos in the ALR config will be used.
 | 
			
		||||
func (rs *Repos) Pull(ctx context.Context, repos []types.Repo) error {
 | 
			
		||||
	if repos == nil {
 | 
			
		||||
		repos = rs.cfg.Repos(ctx)
 | 
			
		||||
		repos = rs.cfg.Repos()
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	for _, repo := range repos {
 | 
			
		||||
@@ -77,7 +77,7 @@ func (rs *Repos) Pull(ctx context.Context, repos []types.Repo) error {
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		slog.Info(gotext.Get("Pulling repository"), "name", repo.Name)
 | 
			
		||||
		repoDir := filepath.Join(rs.cfg.GetPaths(ctx).RepoDir, repo.Name)
 | 
			
		||||
		repoDir := filepath.Join(rs.cfg.GetPaths().RepoDir, repo.Name)
 | 
			
		||||
 | 
			
		||||
		var repoFS billy.Filesystem
 | 
			
		||||
		gitDir := filepath.Join(repoDir, ".git")
 | 
			
		||||
 
 | 
			
		||||
@@ -32,13 +32,13 @@ import (
 | 
			
		||||
 | 
			
		||||
type TestALRConfig struct{}
 | 
			
		||||
 | 
			
		||||
func (c *TestALRConfig) GetPaths(ctx context.Context) *config.Paths {
 | 
			
		||||
func (c *TestALRConfig) GetPaths() *config.Paths {
 | 
			
		||||
	return &config.Paths{
 | 
			
		||||
		DBPath: ":memory:",
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (c *TestALRConfig) Repos(ctx context.Context) []types.Repo {
 | 
			
		||||
func (c *TestALRConfig) Repos() []types.Repo {
 | 
			
		||||
	return []types.Repo{
 | 
			
		||||
		{
 | 
			
		||||
			Name: "test",
 | 
			
		||||
 
 | 
			
		||||
@@ -44,7 +44,7 @@ type TestALRConfig struct {
 | 
			
		||||
	PkgsDir  string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (c *TestALRConfig) GetPaths(ctx context.Context) *config.Paths {
 | 
			
		||||
func (c *TestALRConfig) GetPaths() *config.Paths {
 | 
			
		||||
	return &config.Paths{
 | 
			
		||||
		DBPath:   ":memory:",
 | 
			
		||||
		CacheDir: c.CacheDir,
 | 
			
		||||
@@ -53,7 +53,7 @@ func (c *TestALRConfig) GetPaths(ctx context.Context) *config.Paths {
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (c *TestALRConfig) Repos(ctx context.Context) []types.Repo {
 | 
			
		||||
func (c *TestALRConfig) Repos() []types.Repo {
 | 
			
		||||
	return []types.Repo{}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -17,16 +17,14 @@
 | 
			
		||||
package repos
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"context"
 | 
			
		||||
 | 
			
		||||
	"gitea.plemya-x.ru/Plemya-x/ALR/internal/config"
 | 
			
		||||
	database "gitea.plemya-x.ru/Plemya-x/ALR/internal/db"
 | 
			
		||||
	"gitea.plemya-x.ru/Plemya-x/ALR/internal/types"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type Config interface {
 | 
			
		||||
	GetPaths(ctx context.Context) *config.Paths
 | 
			
		||||
	Repos(ctx context.Context) []types.Repo
 | 
			
		||||
	GetPaths() *config.Paths
 | 
			
		||||
	Repos() []types.Repo
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type Repos struct {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user