Compare commits

..

No commits in common. "cbc6b9f452cd7a2d80a5441b39e2d28f02d6be07" and "5e7d4033e427528ef23f364b9ecf88426500dcf1" have entirely different histories.

30 changed files with 378 additions and 457 deletions

@ -11,7 +11,7 @@
<g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"> <g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">
<text x="33.5" y="15" fill="#010101" fill-opacity=".3">coverage</text> <text x="33.5" y="15" fill="#010101" fill-opacity=".3">coverage</text>
<text x="33.5" y="14">coverage</text> <text x="33.5" y="14">coverage</text>
<text x="86" y="15" fill="#010101" fill-opacity=".3">19.4%</text> <text x="86" y="15" fill="#010101" fill-opacity=".3">19.8%</text>
<text x="86" y="14">19.4%</text> <text x="86" y="14">19.8%</text>
</g> </g>
</svg> </svg>

Before

Width:  |  Height:  |  Size: 926 B

After

Width:  |  Height:  |  Size: 926 B

@ -12,7 +12,7 @@
<g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"> <g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">
<text x="37" y="15" fill="#010101" fill-opacity=".3">ru translate</text> <text x="37" y="15" fill="#010101" fill-opacity=".3">ru translate</text>
<text x="37" y="14">ru translate</text> <text x="37" y="14">ru translate</text>
<text x="100" y="15" fill="#010101" fill-opacity=".3">97.00%</text> <text x="100" y="15" fill="#010101" fill-opacity=".3">100.00%</text>
<text x="100" y="14">97.00%</text> <text x="100" y="14">100.00%</text>
</g> </g>
</svg> </svg>

Before

Width:  |  Height:  |  Size: 940 B

After

Width:  |  Height:  |  Size: 942 B

@ -68,15 +68,9 @@ func BuildCmd() *cli.Command {
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
ctx := c.Context ctx := c.Context
cfg := config.New() cfg := config.New()
err := cfg.Load()
if err != nil {
slog.Error(gotext.Get("Error loading config"), "err", err)
os.Exit(1)
}
db := database.New(cfg) db := database.New(cfg)
rs := repos.New(cfg, db) rs := repos.New(cfg, db)
err = db.Init(ctx) err := db.Init(ctx)
if err != nil { if err != nil {
slog.Error(gotext.Get("Error initialization database"), "err", err) slog.Error(gotext.Get("Error initialization database"), "err", err)
os.Exit(1) os.Exit(1)
@ -86,7 +80,7 @@ func BuildCmd() *cli.Command {
var packages []string var packages []string
repository := "default" repository := "default"
repoDir := cfg.GetPaths().RepoDir repoDir := cfg.GetPaths(ctx).RepoDir
switch { switch {
case c.IsSet("script"): case c.IsSet("script"):
@ -124,8 +118,8 @@ func BuildCmd() *cli.Command {
} }
// Проверка автоматического пулла репозиториев // Проверка автоматического пулла репозиториев
if cfg.AutoPull() { if cfg.AutoPull(ctx) {
err := rs.Pull(ctx, cfg.Repos()) err := rs.Pull(ctx, cfg.Repos(ctx))
if err != nil { if err != nil {
slog.Error(gotext.Get("Error pulling repositories"), "err", err) slog.Error(gotext.Get("Error pulling repositories"), "err", err)
os.Exit(1) os.Exit(1)

18
fix.go

@ -38,17 +38,11 @@ func FixCmd() *cli.Command {
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
ctx := c.Context ctx := c.Context
cfg := config.New() cfg := config.New()
err := cfg.Load() paths := cfg.GetPaths(ctx)
if err != nil {
slog.Error(gotext.Get("Error loading config"), "err", err)
os.Exit(1)
}
paths := cfg.GetPaths()
slog.Info(gotext.Get("Removing cache directory")) slog.Info(gotext.Get("Removing cache directory"))
err = os.RemoveAll(paths.CacheDir) err := os.RemoveAll(paths.CacheDir)
if err != nil { if err != nil {
slog.Error(gotext.Get("Unable to remove cache directory"), "err", err) slog.Error(gotext.Get("Unable to remove cache directory"), "err", err)
os.Exit(1) os.Exit(1)
@ -63,12 +57,6 @@ func FixCmd() *cli.Command {
} }
cfg = config.New() cfg = config.New()
err = cfg.Load()
if err != nil {
slog.Error(gotext.Get("Error loading config"), "err", err)
os.Exit(1)
}
db := database.New(cfg) db := database.New(cfg)
err = db.Init(ctx) err = db.Init(ctx)
if err != nil { if err != nil {
@ -76,7 +64,7 @@ func FixCmd() *cli.Command {
os.Exit(1) os.Exit(1)
} }
rs := repos.New(cfg, db) rs := repos.New(cfg, db)
err = rs.Pull(ctx, cfg.Repos()) err = rs.Pull(ctx, cfg.Repos(ctx))
if err != nil { if err != nil {
slog.Error(gotext.Get("Error pulling repos"), "err", err) slog.Error(gotext.Get("Error pulling repos"), "err", err)
os.Exit(1) os.Exit(1)

1
go.mod

@ -10,7 +10,6 @@ require (
github.com/PuerkitoBio/purell v1.2.0 github.com/PuerkitoBio/purell v1.2.0
github.com/alecthomas/assert/v2 v2.2.1 github.com/alecthomas/assert/v2 v2.2.1
github.com/alecthomas/chroma/v2 v2.9.1 github.com/alecthomas/chroma/v2 v2.9.1
github.com/caarlos0/env v3.5.0+incompatible
github.com/charmbracelet/bubbles v0.20.0 github.com/charmbracelet/bubbles v0.20.0
github.com/charmbracelet/bubbletea v1.2.4 github.com/charmbracelet/bubbletea v1.2.4
github.com/charmbracelet/lipgloss v1.0.0 github.com/charmbracelet/lipgloss v1.0.0

2
go.sum

@ -72,8 +72,6 @@ github.com/bodgit/sevenzip v1.3.0/go.mod h1:omwNcgZTEooWM8gA/IJ2Nk/+ZQ94+GsytRzO
github.com/bodgit/windows v1.0.0 h1:rLQ/XjsleZvx4fR1tB/UxQrK+SJ2OFHzfPjLWWOhDIA= github.com/bodgit/windows v1.0.0 h1:rLQ/XjsleZvx4fR1tB/UxQrK+SJ2OFHzfPjLWWOhDIA=
github.com/bodgit/windows v1.0.0/go.mod h1:a6JLwrB4KrTR5hBpp8FI9/9W9jJfeQ2h4XDXU74ZCdM= github.com/bodgit/windows v1.0.0/go.mod h1:a6JLwrB4KrTR5hBpp8FI9/9W9jJfeQ2h4XDXU74ZCdM=
github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
github.com/caarlos0/env v3.5.0+incompatible h1:Yy0UN8o9Wtr/jGHZDpCBLpNrzcFLLM2yixi/rBrKyJs=
github.com/caarlos0/env v3.5.0+incompatible/go.mod h1:tdCsowwCzMLdkqRYDlHpZCp2UooDD3MspDBjZ2AD02Y=
github.com/caarlos0/testfs v0.4.4 h1:3PHvzHi5Lt+g332CiShwS8ogTgS3HjrmzZxCm6JCDr8= github.com/caarlos0/testfs v0.4.4 h1:3PHvzHi5Lt+g332CiShwS8ogTgS3HjrmzZxCm6JCDr8=
github.com/caarlos0/testfs v0.4.4/go.mod h1:bRN55zgG4XCUVVHZCeU+/Tz1Q6AxEJOEJTliBy+1DMk= github.com/caarlos0/testfs v0.4.4/go.mod h1:bRN55zgG4XCUVVHZCeU+/Tz1Q6AxEJOEJTliBy+1DMk=
github.com/cavaliergopher/cpio v1.0.1 h1:KQFSeKmZhv0cr+kawA3a0xTQCU4QxXF1vhU7P7av2KM= github.com/cavaliergopher/cpio v1.0.1 h1:KQFSeKmZhv0cr+kawA3a0xTQCU4QxXF1vhU7P7av2KM=

20
info.go

@ -51,14 +51,8 @@ func InfoCmd() *cli.Command {
BashComplete: func(c *cli.Context) { BashComplete: func(c *cli.Context) {
ctx := c.Context ctx := c.Context
cfg := config.New() cfg := config.New()
err := cfg.Load()
if err != nil {
slog.Error(gotext.Get("Error loading config"), "err", err)
os.Exit(1)
}
db := database.New(cfg) db := database.New(cfg)
err = db.Init(ctx) err := db.Init(ctx)
if err != nil { if err != nil {
slog.Error(gotext.Get("Error initialization database"), "err", err) slog.Error(gotext.Get("Error initialization database"), "err", err)
os.Exit(1) os.Exit(1)
@ -86,14 +80,8 @@ func InfoCmd() *cli.Command {
ctx := c.Context ctx := c.Context
cfg := config.New() cfg := config.New()
err := cfg.Load()
if err != nil {
slog.Error(gotext.Get("Error loading config"), "err", err)
os.Exit(1)
}
db := database.New(cfg) db := database.New(cfg)
err = db.Init(ctx) err := db.Init(ctx)
if err != nil { if err != nil {
slog.Error(gotext.Get("Error initialization database"), "err", err) slog.Error(gotext.Get("Error initialization database"), "err", err)
os.Exit(1) os.Exit(1)
@ -106,8 +94,8 @@ func InfoCmd() *cli.Command {
os.Exit(1) os.Exit(1)
} }
if cfg.AutoPull() { if cfg.AutoPull(ctx) {
err := rs.Pull(ctx, cfg.Repos()) err := rs.Pull(ctx, cfg.Repos(ctx))
if err != nil { if err != nil {
slog.Error(gotext.Get("Error pulling repos"), "err", err) slog.Error(gotext.Get("Error pulling repos"), "err", err)
os.Exit(1) os.Exit(1)

@ -65,22 +65,16 @@ func InstallCmd() *cli.Command {
} }
cfg := config.New() cfg := config.New()
err := cfg.Load()
if err != nil {
slog.Error(gotext.Get("Error loading config"), "err", err)
os.Exit(1)
}
db := database.New(cfg) db := database.New(cfg)
rs := repos.New(cfg, db) rs := repos.New(cfg, db)
err = db.Init(ctx) err := db.Init(ctx)
if err != nil { if err != nil {
slog.Error(gotext.Get("Error initialization database"), "err", err) slog.Error(gotext.Get("Error initialization database"), "err", err)
os.Exit(1) os.Exit(1)
} }
if cfg.AutoPull() { if cfg.AutoPull(ctx) {
err := rs.Pull(ctx, cfg.Repos()) err := rs.Pull(ctx, cfg.Repos(ctx))
if err != nil { if err != nil {
slog.Error(gotext.Get("Error pulling repositories"), "err", err) slog.Error(gotext.Get("Error pulling repositories"), "err", err)
os.Exit(1) os.Exit(1)

@ -20,21 +20,25 @@
package config package config
import ( import (
"context"
"log/slog" "log/slog"
"os" "os"
"path/filepath" "path/filepath"
"reflect" "sync"
"github.com/caarlos0/env"
"github.com/leonelquinteros/gotext"
"github.com/pelletier/go-toml/v2" "github.com/pelletier/go-toml/v2"
"github.com/leonelquinteros/gotext"
"gitea.plemya-x.ru/Plemya-x/ALR/internal/types" "gitea.plemya-x.ru/Plemya-x/ALR/internal/types"
) )
type ALRConfig struct { type ALRConfig struct {
cfg *types.Config cfg *types.Config
paths *Paths paths *Paths
cfgOnce sync.Once
pathsOnce sync.Once
} }
var defaultConfig = &types.Config{ var defaultConfig = &types.Config{
@ -49,152 +53,147 @@ func New() *ALRConfig {
return &ALRConfig{} return &ALRConfig{}
} }
func readConfig(path string) (*types.Config, error) { func (c *ALRConfig) Load(ctx context.Context) {
file, err := os.Open(path) cfgFl, err := os.Open(c.GetPaths(ctx).ConfigPath)
if err != nil { if err != nil {
return nil, err slog.Warn(gotext.Get("Error opening config file, using defaults"), "err", err)
} c.cfg = defaultConfig
defer file.Close()
config := types.Config{}
if err := toml.NewDecoder(file).Decode(&config); err != nil {
return nil, err
}
return &config, nil
}
func mergeStructs(dst, src interface{}) {
srcVal := reflect.ValueOf(src)
if srcVal.IsNil() {
return return
} }
srcVal = srcVal.Elem() defer cfgFl.Close()
dstVal := reflect.ValueOf(dst).Elem()
for i := range srcVal.NumField() { // Copy the default configuration into config
srcField := srcVal.Field(i) defCopy := *defaultConfig
srcFieldName := srcVal.Type().Field(i).Name config := &defCopy
config.Repos = nil
dstField := dstVal.FieldByName(srcFieldName) err = toml.NewDecoder(cfgFl).Decode(config)
if dstField.IsValid() && dstField.CanSet() {
dstField.Set(srcField)
}
}
}
const systemConfigPath = "/etc/alr/alr.toml"
func (c *ALRConfig) Load() error {
systemConfig, err := readConfig(
systemConfigPath,
)
if err != nil { if err != nil {
slog.Debug("Cannot read system config", "err", err) slog.Warn(gotext.Get("Error decoding config file, using defaults"), "err", err)
c.cfg = defaultConfig
return
} }
cfgDir, err := os.UserConfigDir()
if err != nil {
slog.Debug("Cannot read user config directory")
}
userConfigPath := filepath.Join(cfgDir, "alr", "alr.toml")
userConfig, err := readConfig(
userConfigPath,
)
if err != nil {
slog.Debug("Cannot read user config")
}
config := &types.Config{}
mergeStructs(config, defaultConfig)
mergeStructs(config, systemConfig)
mergeStructs(config, userConfig)
err = env.Parse(config)
if err != nil {
return err
}
c.cfg = config c.cfg = config
cacheDir, err := os.UserCacheDir()
if err != nil {
return err
}
c.paths = &Paths{}
c.paths.UserConfigPath = userConfigPath
c.paths.CacheDir = filepath.Join(cacheDir, "alr")
c.paths.RepoDir = filepath.Join(c.paths.CacheDir, "repo")
c.paths.PkgsDir = filepath.Join(c.paths.CacheDir, "pkgs")
c.paths.DBPath = filepath.Join(c.paths.CacheDir, "db")
c.initPaths()
return nil
}
func (c *ALRConfig) RootCmd() string {
return c.cfg.RootCmd
}
func (c *ALRConfig) PagerStyle() string {
return c.cfg.PagerStyle
}
func (c *ALRConfig) AutoPull() bool {
return c.cfg.AutoPull
}
func (c *ALRConfig) AllowRunAsRoot() bool {
return c.cfg.Unsafe.AllowRunAsRoot
}
func (c *ALRConfig) Repos() []types.Repo {
return c.cfg.Repos
}
func (c *ALRConfig) SetRepos(repos []types.Repo) {
c.cfg.Repos = repos
}
func (c *ALRConfig) IgnorePkgUpdates() []string {
return c.cfg.IgnorePkgUpdates
}
func (c *ALRConfig) LogLevel() string {
return c.cfg.LogLevel
}
func (c *ALRConfig) GetPaths() *Paths {
return c.paths
} }
func (c *ALRConfig) initPaths() { func (c *ALRConfig) initPaths() {
err := os.MkdirAll(filepath.Dir(c.paths.UserConfigPath), 0o755) paths := &Paths{}
cfgDir, err := os.UserConfigDir()
if err != nil { if err != nil {
slog.Error(gotext.Get("Unable to create config directory"), "err", err) slog.Error(gotext.Get("Unable to detect user config directory"), "err", err)
os.Exit(1) os.Exit(1)
} }
err = os.MkdirAll(c.paths.RepoDir, 0o755) paths.ConfigDir = filepath.Join(cfgDir, "alr")
err = os.MkdirAll(paths.ConfigDir, 0o755)
if err != nil {
slog.Error(gotext.Get("Unable to create ALR config directory"), "err", err)
os.Exit(1)
}
paths.ConfigPath = filepath.Join(paths.ConfigDir, "alr.toml")
if _, err := os.Stat(paths.ConfigPath); err != nil {
cfgFl, err := os.Create(paths.ConfigPath)
if err != nil {
slog.Error(gotext.Get("Unable to create ALR config file"), "err", err)
os.Exit(1)
}
err = toml.NewEncoder(cfgFl).Encode(&defaultConfig)
if err != nil {
slog.Error(gotext.Get("Error encoding default configuration"), "err", err)
os.Exit(1)
}
cfgFl.Close()
}
cacheDir, err := os.UserCacheDir()
if err != nil {
slog.Error(gotext.Get("Unable to detect cache directory"), "err", err)
os.Exit(1)
}
paths.CacheDir = filepath.Join(cacheDir, "alr")
paths.RepoDir = filepath.Join(paths.CacheDir, "repo")
paths.PkgsDir = filepath.Join(paths.CacheDir, "pkgs")
err = os.MkdirAll(paths.RepoDir, 0o755)
if err != nil { if err != nil {
slog.Error(gotext.Get("Unable to create repo cache directory"), "err", err) slog.Error(gotext.Get("Unable to create repo cache directory"), "err", err)
os.Exit(1) os.Exit(1)
} }
err = os.MkdirAll(c.paths.PkgsDir, 0o755) err = os.MkdirAll(paths.PkgsDir, 0o755)
if err != nil { if err != nil {
slog.Error(gotext.Get("Unable to create package cache directory"), "err", err) slog.Error(gotext.Get("Unable to create package cache directory"), "err", err)
os.Exit(1) os.Exit(1)
} }
paths.DBPath = filepath.Join(paths.CacheDir, "db")
c.paths = paths
} }
func (c *ALRConfig) SaveUserConfig() error { func (c *ALRConfig) GetPaths(ctx context.Context) *Paths {
f, err := os.Create(c.paths.UserConfigPath) c.pathsOnce.Do(func() {
if err != nil { c.initPaths()
return err })
} return c.paths
}
func (c *ALRConfig) Repos(ctx context.Context) []types.Repo {
c.cfgOnce.Do(func() {
c.Load(ctx)
})
return c.cfg.Repos
}
func (c *ALRConfig) SetRepos(ctx context.Context, repos []types.Repo) {
c.cfgOnce.Do(func() {
c.Load(ctx)
})
c.cfg.Repos = repos
}
func (c *ALRConfig) IgnorePkgUpdates(ctx context.Context) []string {
c.cfgOnce.Do(func() {
c.Load(ctx)
})
return c.cfg.IgnorePkgUpdates
}
func (c *ALRConfig) AutoPull(ctx context.Context) bool {
c.cfgOnce.Do(func() {
c.Load(ctx)
})
return c.cfg.AutoPull
}
func (c *ALRConfig) PagerStyle(ctx context.Context) string {
c.cfgOnce.Do(func() {
c.Load(ctx)
})
return c.cfg.PagerStyle
}
func (c *ALRConfig) AllowRunAsRoot(ctx context.Context) bool {
c.cfgOnce.Do(func() {
c.Load(ctx)
})
return c.cfg.Unsafe.AllowRunAsRoot
}
func (c *ALRConfig) RootCmd(ctx context.Context) string {
c.cfgOnce.Do(func() {
c.Load(ctx)
})
return c.cfg.RootCmd
}
func (c *ALRConfig) Save(f *os.File) error {
return toml.NewEncoder(f).Encode(c.cfg) return toml.NewEncoder(f).Encode(c.cfg)
} }

@ -21,9 +21,10 @@ package config
// Paths contains various paths used by ALR // Paths contains various paths used by ALR
type Paths struct { type Paths struct {
UserConfigPath string ConfigDir string
CacheDir string ConfigPath string
RepoDir string CacheDir string
PkgsDir string RepoDir string
DBPath string PkgsDir string
DBPath string
} }

@ -59,7 +59,7 @@ type version struct {
} }
type Config interface { type Config interface {
GetPaths() *config.Paths GetPaths(ctx context.Context) *config.Paths
} }
type Database struct { type Database struct {
@ -82,7 +82,7 @@ func (d *Database) Init(ctx context.Context) error {
} }
func (d *Database) Connect(ctx context.Context) error { func (d *Database) Connect(ctx context.Context) error {
dsn := d.config.GetPaths().DBPath dsn := d.config.GetPaths(ctx).DBPath
db, err := sqlx.Open("sqlite", dsn) db, err := sqlx.Open("sqlite", dsn)
if err != nil { if err != nil {
return err return err

@ -33,7 +33,7 @@ import (
type TestALRConfig struct{} type TestALRConfig struct{}
func (c *TestALRConfig) GetPaths() *config.Paths { func (c *TestALRConfig) GetPaths(ctx context.Context) *config.Paths {
return &config.Paths{ return &config.Paths{
DBPath: ":memory:", DBPath: ":memory:",
} }

@ -38,7 +38,7 @@ import (
type TestALRConfig struct{} type TestALRConfig struct{}
func (c *TestALRConfig) GetPaths() *config.Paths { func (c *TestALRConfig) GetPaths(ctx context.Context) *config.Paths {
return &config.Paths{ return &config.Paths{
CacheDir: "/tmp", CacheDir: "/tmp",
} }

@ -28,7 +28,7 @@ import (
) )
type Config interface { type Config interface {
GetPaths() *config.Paths GetPaths(ctx context.Context) *config.Paths
} }
type DownloadCache struct { type DownloadCache struct {
@ -43,7 +43,7 @@ func New(cfg Config) *DownloadCache {
func (dc *DownloadCache) BasePath(ctx context.Context) string { func (dc *DownloadCache) BasePath(ctx context.Context) string {
return filepath.Join( return filepath.Join(
dc.cfg.GetPaths().CacheDir, "dl", dc.cfg.GetPaths(ctx).CacheDir, "dl",
) )
} }

@ -36,7 +36,7 @@ type TestALRConfig struct {
CacheDir string CacheDir string
} }
func (c *TestALRConfig) GetPaths() *config.Paths { func (c *TestALRConfig) GetPaths(ctx context.Context) *config.Paths {
return &config.Paths{ return &config.Paths{
CacheDir: c.CacheDir, CacheDir: c.CacheDir,
} }

@ -62,25 +62,6 @@ func New() *Logger {
} }
} }
func slogLevelToLog(level slog.Level) log.Level {
switch level {
case slog.LevelDebug:
return log.DebugLevel
case slog.LevelInfo:
return log.InfoLevel
case slog.LevelWarn:
return log.WarnLevel
case slog.LevelError:
return log.ErrorLevel
}
return log.FatalLevel
}
func (l *Logger) SetLevel(level slog.Level) {
l.lOut.(*log.Logger).SetLevel(slogLevelToLog(level))
l.lErr.(*log.Logger).SetLevel(slogLevelToLog(level))
}
func (l *Logger) Enabled(ctx context.Context, level slog.Level) bool { func (l *Logger) Enabled(ctx context.Context, level slog.Level) bool {
if level <= slog.LevelInfo { if level <= slog.LevelInfo {
return l.lOut.Enabled(ctx, level) return l.lOut.Enabled(ctx, level)
@ -109,9 +90,7 @@ func (l *Logger) WithGroup(name string) slog.Handler {
return &sl return &sl
} }
func SetupDefault() *Logger { func SetupDefault() {
l := New() logger := slog.New(New())
logger := slog.New(l)
slog.SetDefault(logger) slog.SetDefault(logger)
return l
} }

@ -30,39 +30,35 @@ msgid ""
"Build package from scratch even if there's an already built package available" "Build package from scratch even if there's an already built package available"
msgstr "" msgstr ""
#: build.go:73 #: build.go:75
msgid "Error loading config"
msgstr ""
#: build.go:81
msgid "Error initialization database" msgid "Error initialization database"
msgstr "" msgstr ""
#: build.go:110 #: build.go:104
msgid "Package not found" msgid "Package not found"
msgstr "" msgstr ""
#: build.go:130 #: build.go:124
msgid "Error pulling repositories" msgid "Error pulling repositories"
msgstr "" msgstr ""
#: build.go:138 #: build.go:132
msgid "Unable to detect a supported package manager on the system" msgid "Unable to detect a supported package manager on the system"
msgstr "" msgstr ""
#: build.go:144 #: build.go:138
msgid "Error parsing os release" msgid "Error parsing os release"
msgstr "" msgstr ""
#: build.go:166 #: build.go:160
msgid "Error building package" msgid "Error building package"
msgstr "" msgstr ""
#: build.go:173 #: build.go:167
msgid "Error getting working directory" msgid "Error getting working directory"
msgstr "" msgstr ""
#: build.go:182 #: build.go:176
msgid "Error moving the package" msgid "Error moving the package"
msgstr "" msgstr ""
@ -70,27 +66,27 @@ msgstr ""
msgid "Attempt to fix problems with ALR" msgid "Attempt to fix problems with ALR"
msgstr "" msgstr ""
#: fix.go:49 #: fix.go:43
msgid "Removing cache directory" msgid "Removing cache directory"
msgstr "" msgstr ""
#: fix.go:53 #: fix.go:47
msgid "Unable to remove cache directory" msgid "Unable to remove cache directory"
msgstr "" msgstr ""
#: fix.go:57 #: fix.go:51
msgid "Rebuilding cache" msgid "Rebuilding cache"
msgstr "" msgstr ""
#: fix.go:61 #: fix.go:55
msgid "Unable to create new cache directory" msgid "Unable to create new cache directory"
msgstr "" msgstr ""
#: fix.go:81 #: fix.go:69
msgid "Error pulling repos" msgid "Error pulling repos"
msgstr "" msgstr ""
#: fix.go:85 #: fix.go:73
msgid "Done" msgid "Done"
msgstr "" msgstr ""
@ -126,31 +122,31 @@ msgstr ""
msgid "Show all information, not just for the current distro" msgid "Show all information, not just for the current distro"
msgstr "" msgstr ""
#: info.go:69 #: info.go:63
msgid "Error getting packages" msgid "Error getting packages"
msgstr "" msgstr ""
#: info.go:78 #: info.go:72
msgid "Error iterating over packages" msgid "Error iterating over packages"
msgstr "" msgstr ""
#: info.go:105 #: info.go:93
msgid "Command info expected at least 1 argument, got %d" msgid "Command info expected at least 1 argument, got %d"
msgstr "" msgstr ""
#: info.go:119 #: info.go:107
msgid "Error finding packages" msgid "Error finding packages"
msgstr "" msgstr ""
#: info.go:144 #: info.go:132
msgid "Error parsing os-release file" msgid "Error parsing os-release file"
msgstr "" msgstr ""
#: info.go:153 #: info.go:141
msgid "Error resolving overrides" msgid "Error resolving overrides"
msgstr "" msgstr ""
#: info.go:162 info.go:168 #: info.go:150 info.go:156
msgid "Error encoding script variables" msgid "Error encoding script variables"
msgstr "" msgstr ""
@ -162,15 +158,15 @@ msgstr ""
msgid "Command install expected at least 1 argument, got %d" msgid "Command install expected at least 1 argument, got %d"
msgstr "" msgstr ""
#: install.go:157 #: install.go:151
msgid "Remove an installed package" msgid "Remove an installed package"
msgstr "" msgstr ""
#: install.go:162 #: install.go:156
msgid "Command remove expected at least 1 argument, got %d" msgid "Command remove expected at least 1 argument, got %d"
msgstr "" msgstr ""
#: install.go:174 #: install.go:168
msgid "Error removing packages" msgid "Error removing packages"
msgstr "" msgstr ""
@ -254,15 +250,39 @@ msgstr ""
msgid "OPTIONS" msgid "OPTIONS"
msgstr "" msgstr ""
#: internal/config/config.go:176 #: internal/config/config.go:59
msgid "Unable to create config directory" msgid "Error opening config file, using defaults"
msgstr "" msgstr ""
#: internal/config/config.go:182 #: internal/config/config.go:72
msgid "Error decoding config file, using defaults"
msgstr ""
#: internal/config/config.go:84
msgid "Unable to detect user config directory"
msgstr ""
#: internal/config/config.go:92
msgid "Unable to create ALR config directory"
msgstr ""
#: internal/config/config.go:101
msgid "Unable to create ALR config file"
msgstr ""
#: internal/config/config.go:107
msgid "Error encoding default configuration"
msgstr ""
#: internal/config/config.go:116
msgid "Unable to detect cache directory"
msgstr ""
#: internal/config/config.go:126
msgid "Unable to create repo cache directory" msgid "Unable to create repo cache directory"
msgstr "" msgstr ""
#: internal/config/config.go:188 #: internal/config/config.go:132
msgid "Unable to create package cache directory" msgid "Unable to create package cache directory"
msgstr "" msgstr ""
@ -307,7 +327,7 @@ msgstr ""
msgid "List ALR repo packages" msgid "List ALR repo packages"
msgstr "" msgstr ""
#: list.go:98 #: list.go:92
msgid "Error listing installed packages" msgid "Error listing installed packages"
msgstr "" msgstr ""
@ -323,17 +343,17 @@ msgstr ""
msgid "Enable interactive questions and prompts" msgid "Enable interactive questions and prompts"
msgstr "" msgstr ""
#: main.go:96 #: main.go:92
msgid "" msgid ""
"Running ALR as root is forbidden as it may cause catastrophic damage to your " "Running ALR as root is forbidden as it may cause catastrophic damage to your "
"system" "system"
msgstr "" msgstr ""
#: main.go:154 #: main.go:125
msgid "Show help" msgid "Show help"
msgstr "" msgstr ""
#: main.go:158 #: main.go:129
msgid "Error while running app" msgid "Error while running app"
msgstr "" msgstr ""
@ -441,43 +461,47 @@ msgid ""
"updating ALR if something doesn't work." "updating ALR if something doesn't work."
msgstr "" msgstr ""
#: repo.go:40 #: repo.go:41
msgid "Add a new repository" msgid "Add a new repository"
msgstr "" msgstr ""
#: repo.go:47 #: repo.go:48
msgid "Name of the new repo" msgid "Name of the new repo"
msgstr "" msgstr ""
#: repo.go:53 #: repo.go:54
msgid "URL of the new repo" msgid "URL of the new repo"
msgstr "" msgstr ""
#: repo.go:86 repo.go:156 #: repo.go:82 repo.go:147
msgid "Error saving config" msgid "Error opening config file"
msgstr "" msgstr ""
#: repo.go:111 #: repo.go:88 repo.go:153 repo.go:165
msgid "Error encoding config"
msgstr ""
#: repo.go:113
msgid "Remove an existing repository" msgid "Remove an existing repository"
msgstr "" msgstr ""
#: repo.go:118 #: repo.go:120
msgid "Name of the repo to be deleted" msgid "Name of the repo to be deleted"
msgstr "" msgstr ""
#: repo.go:142 #: repo.go:139
msgid "Repo does not exist" msgid "Repo does not exist"
msgstr "" msgstr ""
#: repo.go:150 #: repo.go:159
msgid "Error removing repo directory" msgid "Error removing repo directory"
msgstr "" msgstr ""
#: repo.go:167 #: repo.go:176
msgid "Error removing packages from database" msgid "Error removing packages from database"
msgstr "" msgstr ""
#: repo.go:179 #: repo.go:188
msgid "Pull all repositories that have changed" msgid "Pull all repositories that have changed"
msgstr "" msgstr ""
@ -505,11 +529,11 @@ msgstr ""
msgid "Format output using a Go template" msgid "Format output using a Go template"
msgstr "" msgstr ""
#: search.go:88 search.go:105 #: search.go:82 search.go:99
msgid "Error parsing format template" msgid "Error parsing format template"
msgstr "" msgstr ""
#: search.go:113 #: search.go:107
msgid "Error executing template" msgid "Error executing template"
msgstr "" msgstr ""
@ -517,10 +541,10 @@ msgstr ""
msgid "Upgrade all installed packages" msgid "Upgrade all installed packages"
msgstr "" msgstr ""
#: upgrade.go:96 #: upgrade.go:90
msgid "Error checking for updates" msgid "Error checking for updates"
msgstr "" msgstr ""
#: upgrade.go:118 #: upgrade.go:112
msgid "There is nothing to do." msgid "There is nothing to do."
msgstr "" msgstr ""

@ -37,40 +37,35 @@ msgid ""
"Build package from scratch even if there's an already built package available" "Build package from scratch even if there's an already built package available"
msgstr "Создайте пакет с нуля, даже если уже имеется готовый пакет" msgstr "Создайте пакет с нуля, даже если уже имеется готовый пакет"
#: build.go:73 #: build.go:75
#, fuzzy
msgid "Error loading config"
msgstr "Ошибка при кодировании конфигурации"
#: build.go:81
msgid "Error initialization database" msgid "Error initialization database"
msgstr "Ошибка инициализации базы данных" msgstr "Ошибка инициализации базы данных"
#: build.go:110 #: build.go:104
msgid "Package not found" msgid "Package not found"
msgstr "Пакет не найден" msgstr "Пакет не найден"
#: build.go:130 #: build.go:124
msgid "Error pulling repositories" msgid "Error pulling repositories"
msgstr "Ошибка при извлечении репозиториев" msgstr "Ошибка при извлечении репозиториев"
#: build.go:138 #: build.go:132
msgid "Unable to detect a supported package manager on the system" msgid "Unable to detect a supported package manager on the system"
msgstr "Не удалось обнаружить поддерживаемый менеджер пакетов в системе" msgstr "Не удалось обнаружить поддерживаемый менеджер пакетов в системе"
#: build.go:144 #: build.go:138
msgid "Error parsing os release" msgid "Error parsing os release"
msgstr "Ошибка при разборе файла выпуска операционной системы" msgstr "Ошибка при разборе файла выпуска операционной системы"
#: build.go:166 #: build.go:160
msgid "Error building package" msgid "Error building package"
msgstr "Ошибка при сборке пакета" msgstr "Ошибка при сборке пакета"
#: build.go:173 #: build.go:167
msgid "Error getting working directory" msgid "Error getting working directory"
msgstr "Ошибка при получении рабочего каталога" msgstr "Ошибка при получении рабочего каталога"
#: build.go:182 #: build.go:176
msgid "Error moving the package" msgid "Error moving the package"
msgstr "Ошибка при перемещении пакета" msgstr "Ошибка при перемещении пакета"
@ -78,27 +73,27 @@ msgstr "Ошибка при перемещении пакета"
msgid "Attempt to fix problems with ALR" msgid "Attempt to fix problems with ALR"
msgstr "Попытка устранить проблемы с ALR" msgstr "Попытка устранить проблемы с ALR"
#: fix.go:49 #: fix.go:43
msgid "Removing cache directory" msgid "Removing cache directory"
msgstr "Удаление каталога кэша" msgstr "Удаление каталога кэша"
#: fix.go:53 #: fix.go:47
msgid "Unable to remove cache directory" msgid "Unable to remove cache directory"
msgstr "Не удалось удалить каталог кэша" msgstr "Не удалось удалить каталог кэша"
#: fix.go:57 #: fix.go:51
msgid "Rebuilding cache" msgid "Rebuilding cache"
msgstr "Восстановление кэша" msgstr "Восстановление кэша"
#: fix.go:61 #: fix.go:55
msgid "Unable to create new cache directory" msgid "Unable to create new cache directory"
msgstr "Не удалось создать новый каталог кэша" msgstr "Не удалось создать новый каталог кэша"
#: fix.go:81 #: fix.go:69
msgid "Error pulling repos" msgid "Error pulling repos"
msgstr "Ошибка при извлечении репозиториев" msgstr "Ошибка при извлечении репозиториев"
#: fix.go:85 #: fix.go:73
msgid "Done" msgid "Done"
msgstr "Сделано" msgstr "Сделано"
@ -134,31 +129,31 @@ msgstr "Отобразить информацию о пакете"
msgid "Show all information, not just for the current distro" msgid "Show all information, not just for the current distro"
msgstr "Показывать всю информацию, не только для текущего дистрибутива" msgstr "Показывать всю информацию, не только для текущего дистрибутива"
#: info.go:69 #: info.go:63
msgid "Error getting packages" msgid "Error getting packages"
msgstr "Ошибка при получении пакетов" msgstr "Ошибка при получении пакетов"
#: info.go:78 #: info.go:72
msgid "Error iterating over packages" msgid "Error iterating over packages"
msgstr "Ошибка при переборе пакетов" msgstr "Ошибка при переборе пакетов"
#: info.go:105 #: info.go:93
msgid "Command info expected at least 1 argument, got %d" msgid "Command info expected at least 1 argument, got %d"
msgstr "Для команды info ожидался хотя бы 1 аргумент, получено %d" msgstr "Для команды info ожидался хотя бы 1 аргумент, получено %d"
#: info.go:119 #: info.go:107
msgid "Error finding packages" msgid "Error finding packages"
msgstr "Ошибка при поиске пакетов" msgstr "Ошибка при поиске пакетов"
#: info.go:144 #: info.go:132
msgid "Error parsing os-release file" msgid "Error parsing os-release file"
msgstr "Ошибка при разборе файла выпуска операционной системы" msgstr "Ошибка при разборе файла выпуска операционной системы"
#: info.go:153 #: info.go:141
msgid "Error resolving overrides" msgid "Error resolving overrides"
msgstr "Ошибка устранения переорпеделений" msgstr "Ошибка устранения переорпеделений"
#: info.go:162 info.go:168 #: info.go:150 info.go:156
msgid "Error encoding script variables" msgid "Error encoding script variables"
msgstr "Ошибка кодирования переменных скрита" msgstr "Ошибка кодирования переменных скрита"
@ -170,15 +165,15 @@ msgstr "Установить новый пакет"
msgid "Command install expected at least 1 argument, got %d" msgid "Command install expected at least 1 argument, got %d"
msgstr "Для команды install ожидался хотя бы 1 аргумент, получено %d" msgstr "Для команды install ожидался хотя бы 1 аргумент, получено %d"
#: install.go:157 #: install.go:151
msgid "Remove an installed package" msgid "Remove an installed package"
msgstr "Удалить установленный пакет" msgstr "Удалить установленный пакет"
#: install.go:162 #: install.go:156
msgid "Command remove expected at least 1 argument, got %d" msgid "Command remove expected at least 1 argument, got %d"
msgstr "Для команды remove ожидался хотя бы 1 аргумент, получено %d" msgstr "Для команды remove ожидался хотя бы 1 аргумент, получено %d"
#: install.go:174 #: install.go:168
msgid "Error removing packages" msgid "Error removing packages"
msgstr "Ошибка при удалении пакетов" msgstr "Ошибка при удалении пакетов"
@ -262,16 +257,43 @@ msgstr "КАТЕГОРИЯ"
msgid "OPTIONS" msgid "OPTIONS"
msgstr "ПАРАМЕТРЫ" msgstr "ПАРАМЕТРЫ"
#: internal/config/config.go:176 #: internal/config/config.go:59
#, fuzzy msgid "Error opening config file, using defaults"
msgid "Unable to create config directory" msgstr ""
"Ошибка при открытии конфигурационного файла, используются значения по "
"умолчанию"
#: internal/config/config.go:72
msgid "Error decoding config file, using defaults"
msgstr ""
"Ошибка при декодировании конфигурационного файла, используются значения по "
"умолчанию"
#: internal/config/config.go:84
msgid "Unable to detect user config directory"
msgstr "Не удалось обнаружить каталог конфигурации пользователя"
#: internal/config/config.go:92
msgid "Unable to create ALR config directory"
msgstr "Не удалось создать каталог конфигурации ALR" msgstr "Не удалось создать каталог конфигурации ALR"
#: internal/config/config.go:182 #: internal/config/config.go:101
msgid "Unable to create ALR config file"
msgstr "Не удалось создать конфигурационный файл ALR"
#: internal/config/config.go:107
msgid "Error encoding default configuration"
msgstr "Ошибка кодирования конфигурации по умолчанию"
#: internal/config/config.go:116
msgid "Unable to detect cache directory"
msgstr "Не удалось обнаружить каталог кэша"
#: internal/config/config.go:126
msgid "Unable to create repo cache directory" msgid "Unable to create repo cache directory"
msgstr "Не удалось создать каталог кэша репозитория" msgstr "Не удалось создать каталог кэша репозитория"
#: internal/config/config.go:188 #: internal/config/config.go:132
msgid "Unable to create package cache directory" msgid "Unable to create package cache directory"
msgstr "Не удалось создать каталог кэша пакетов" msgstr "Не удалось создать каталог кэша пакетов"
@ -317,7 +339,7 @@ msgstr "ОШИБКА"
msgid "List ALR repo packages" msgid "List ALR repo packages"
msgstr "Список пакетов репозитория ALR" msgstr "Список пакетов репозитория ALR"
#: list.go:98 #: list.go:92
msgid "Error listing installed packages" msgid "Error listing installed packages"
msgstr "Ошибка при составлении списка установленных пакетов" msgstr "Ошибка при составлении списка установленных пакетов"
@ -333,7 +355,7 @@ msgstr "Аргументы, которые будут переданы мене
msgid "Enable interactive questions and prompts" msgid "Enable interactive questions and prompts"
msgstr "Включение интерактивных вопросов и запросов" msgstr "Включение интерактивных вопросов и запросов"
#: main.go:96 #: main.go:92
msgid "" msgid ""
"Running ALR as root is forbidden as it may cause catastrophic damage to your " "Running ALR as root is forbidden as it may cause catastrophic damage to your "
"system" "system"
@ -341,11 +363,11 @@ msgstr ""
"Запуск ALR от имени root запрещён, так как это может привести к " "Запуск ALR от имени root запрещён, так как это может привести к "
"катастрофическому повреждению вашей системы" "катастрофическому повреждению вашей системы"
#: main.go:154 #: main.go:125
msgid "Show help" msgid "Show help"
msgstr "Показать справку" msgstr "Показать справку"
#: main.go:158 #: main.go:129
msgid "Error while running app" msgid "Error while running app"
msgstr "Ошибка при запуске приложения" msgstr "Ошибка при запуске приложения"
@ -459,44 +481,47 @@ msgstr ""
"Минимальная версия ALR для ALR-репозитория выше текущей версии. Попробуйте " "Минимальная версия ALR для ALR-репозитория выше текущей версии. Попробуйте "
"обновить ALR, если что-то не работает." "обновить ALR, если что-то не работает."
#: repo.go:40 #: repo.go:41
msgid "Add a new repository" msgid "Add a new repository"
msgstr "Добавить новый репозиторий" msgstr "Добавить новый репозиторий"
#: repo.go:47 #: repo.go:48
msgid "Name of the new repo" msgid "Name of the new repo"
msgstr "Название нового репозитория" msgstr "Название нового репозитория"
#: repo.go:53 #: repo.go:54
msgid "URL of the new repo" msgid "URL of the new repo"
msgstr "URL-адрес нового репозитория" msgstr "URL-адрес нового репозитория"
#: repo.go:86 repo.go:156 #: repo.go:82 repo.go:147
#, fuzzy msgid "Error opening config file"
msgid "Error saving config" msgstr "Ошибка при открытии конфигурационного файла"
#: repo.go:88 repo.go:153 repo.go:165
msgid "Error encoding config"
msgstr "Ошибка при кодировании конфигурации" msgstr "Ошибка при кодировании конфигурации"
#: repo.go:111 #: repo.go:113
msgid "Remove an existing repository" msgid "Remove an existing repository"
msgstr "Удалить существующий репозиторий" msgstr "Удалить существующий репозиторий"
#: repo.go:118 #: repo.go:120
msgid "Name of the repo to be deleted" msgid "Name of the repo to be deleted"
msgstr "Название репозитория удалён" msgstr "Название репозитория удалён"
#: repo.go:142 #: repo.go:139
msgid "Repo does not exist" msgid "Repo does not exist"
msgstr "Репозитория не существует" msgstr "Репозитория не существует"
#: repo.go:150 #: repo.go:159
msgid "Error removing repo directory" msgid "Error removing repo directory"
msgstr "Ошибка при удалении каталога репозитория" msgstr "Ошибка при удалении каталога репозитория"
#: repo.go:167 #: repo.go:176
msgid "Error removing packages from database" msgid "Error removing packages from database"
msgstr "Ошибка при удалении пакетов из базы данных" msgstr "Ошибка при удалении пакетов из базы данных"
#: repo.go:179 #: repo.go:188
msgid "Pull all repositories that have changed" msgid "Pull all repositories that have changed"
msgstr "Скачать все изменённые репозитории" msgstr "Скачать все изменённые репозитории"
@ -524,11 +549,11 @@ msgstr "Иcкать по provides"
msgid "Format output using a Go template" msgid "Format output using a Go template"
msgstr "Формат выходных данных с использованием шаблона Go" msgstr "Формат выходных данных с использованием шаблона Go"
#: search.go:88 search.go:105 #: search.go:82 search.go:99
msgid "Error parsing format template" msgid "Error parsing format template"
msgstr "Ошибка при разборе шаблона" msgstr "Ошибка при разборе шаблона"
#: search.go:113 #: search.go:107
msgid "Error executing template" msgid "Error executing template"
msgstr "Ошибка при выполнении шаблона" msgstr "Ошибка при выполнении шаблона"
@ -536,39 +561,14 @@ msgstr "Ошибка при выполнении шаблона"
msgid "Upgrade all installed packages" msgid "Upgrade all installed packages"
msgstr "Обновить все установленные пакеты" msgstr "Обновить все установленные пакеты"
#: upgrade.go:96 #: upgrade.go:90
msgid "Error checking for updates" msgid "Error checking for updates"
msgstr "Ошибка при проверке обновлений" msgstr "Ошибка при проверке обновлений"
#: upgrade.go:118 #: upgrade.go:112
msgid "There is nothing to do." msgid "There is nothing to do."
msgstr "Здесь нечего делать." msgstr "Здесь нечего делать."
#~ msgid "Error opening config file, using defaults"
#~ msgstr ""
#~ "Ошибка при открытии конфигурационного файла, используются значения по "
#~ "умолчанию"
#~ msgid "Error decoding config file, using defaults"
#~ msgstr ""
#~ "Ошибка при декодировании конфигурационного файла, используются значения "
#~ "по умолчанию"
#~ msgid "Unable to detect user config directory"
#~ msgstr "Не удалось обнаружить каталог конфигурации пользователя"
#~ msgid "Unable to create ALR config file"
#~ msgstr "Не удалось создать конфигурационный файл ALR"
#~ msgid "Error encoding default configuration"
#~ msgstr "Ошибка кодирования конфигурации по умолчанию"
#~ msgid "Unable to detect cache directory"
#~ msgstr "Не удалось обнаружить каталог кэша"
#~ msgid "Error opening config file"
#~ msgstr "Ошибка при открытии конфигурационного файла"
#~ msgid "Error parsing system language" #~ msgid "Error parsing system language"
#~ msgstr "Ошибка при парсинге языка системы" #~ msgstr "Ошибка при парсинге языка системы"

@ -21,13 +21,12 @@ package types
// Config represents the ALR configuration file // Config represents the ALR configuration file
type Config struct { type Config struct {
RootCmd string `toml:"rootCmd" env:"ALR_ROOT_CMD"` RootCmd string `toml:"rootCmd"`
PagerStyle string `toml:"pagerStyle" env:"ALR_PAGER_STYLE"` PagerStyle string `toml:"pagerStyle"`
IgnorePkgUpdates []string `toml:"ignorePkgUpdates"` IgnorePkgUpdates []string `toml:"ignorePkgUpdates"`
Repos []Repo `toml:"repo"` Repos []Repo `toml:"repo"`
Unsafe Unsafe `toml:"unsafe"` Unsafe Unsafe `toml:"unsafe"`
AutoPull bool `toml:"autoPull" env:"ALR_AUTOPULL"` AutoPull bool `toml:"autoPull"`
LogLevel string `toml:"logLevel" env:"ALR_LOG_LEVEL"`
} }
// Repo represents a ALR repo within a configuration file // Repo represents a ALR repo within a configuration file
@ -37,5 +36,5 @@ type Repo struct {
} }
type Unsafe struct { type Unsafe struct {
AllowRunAsRoot bool `toml:"allowRunAsRoot" env:"ALR_UNSAFE_ALLOW_RUN_AS_ROOT"` AllowRunAsRoot bool `toml:"allowRunAsRoot"`
} }

14
list.go

@ -49,22 +49,16 @@ func ListCmd() *cli.Command {
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
ctx := c.Context ctx := c.Context
cfg := config.New() cfg := config.New()
err := cfg.Load()
if err != nil {
slog.Error(gotext.Get("Error loading config"), "err", err)
os.Exit(1)
}
db := database.New(cfg) db := database.New(cfg)
err = db.Init(ctx) err := db.Init(ctx)
if err != nil { if err != nil {
slog.Error(gotext.Get("Error initialization database"), "err", err) slog.Error(gotext.Get("Error initialization database"), "err", err)
os.Exit(1) os.Exit(1)
} }
rs := repos.New(cfg, db) rs := repos.New(cfg, db)
if cfg.AutoPull() { if cfg.AutoPull(ctx) {
err = rs.Pull(ctx, cfg.Repos()) err = rs.Pull(ctx, cfg.Repos(ctx))
if err != nil { if err != nil {
slog.Error(gotext.Get("Error pulling repositories"), "err", err) slog.Error(gotext.Get("Error pulling repositories"), "err", err)
os.Exit(1) os.Exit(1)
@ -116,7 +110,7 @@ func ListCmd() *cli.Command {
return err return err
} }
if slices.Contains(cfg.IgnorePkgUpdates(), pkg.Name) { if slices.Contains(cfg.IgnorePkgUpdates(ctx), pkg.Name) {
continue continue
} }

45
main.go

@ -84,15 +84,11 @@ func GetApp() *cli.App {
SearchCmd(), SearchCmd(),
}, },
Before: func(c *cli.Context) error { Before: func(c *cli.Context) error {
ctx := c.Context
cfg := config.New() cfg := config.New()
err := cfg.Load()
if err != nil {
slog.Error(gotext.Get("Error loading config"), "err", err)
os.Exit(1)
}
cmd := c.Args().First() cmd := c.Args().First()
if cmd != "helper" && !cfg.AllowRunAsRoot() && os.Geteuid() == 0 { if cmd != "helper" && !cfg.AllowRunAsRoot(ctx) && os.Geteuid() == 0 {
slog.Error(gotext.Get("Running ALR as root is forbidden as it may cause catastrophic damage to your system")) slog.Error(gotext.Get("Running ALR as root is forbidden as it may cause catastrophic damage to your system"))
os.Exit(1) os.Exit(1)
} }
@ -108,42 +104,17 @@ func GetApp() *cli.App {
} }
} }
func setLogLevel(newLevel string) {
level := slog.LevelInfo
switch newLevel {
case "DEBUG":
level = slog.LevelDebug
case "INFO":
level = slog.LevelInfo
case "WARN":
level = slog.LevelWarn
case "ERROR":
level = slog.LevelError
}
logger, ok := slog.Default().Handler().(*logger.Logger)
if !ok {
panic("unexpected")
}
logger.SetLevel(level)
}
func main() { func main() {
logger.SetupDefault()
setLogLevel(os.Getenv("ALR_LOG_LEVEL"))
translations.Setup() translations.Setup()
logger.SetupDefault()
ctx := context.Background()
app := GetApp() app := GetApp()
cfg := config.New() cfg := config.New()
err := cfg.Load()
if err != nil { ctx := context.Background()
slog.Error(gotext.Get("Error loading config"), "err", err)
os.Exit(1)
}
setLogLevel(cfg.LogLevel())
// Set the root command to the one set in the ALR config // Set the root command to the one set in the ALR config
manager.DefaultRootCmd = cfg.RootCmd() manager.DefaultRootCmd = cfg.RootCmd(ctx)
ctx, cancel := signal.NotifyContext(ctx, syscall.SIGINT, syscall.SIGTERM) ctx, cancel := signal.NotifyContext(ctx, syscall.SIGINT, syscall.SIGTERM)
defer cancel() defer cancel()
@ -153,7 +124,7 @@ func main() {
cli.CommandHelpTemplate = cliutils.GetCommandHelpTemplate() cli.CommandHelpTemplate = cliutils.GetCommandHelpTemplate()
cli.HelpFlag.(*cli.BoolFlag).Usage = gotext.Get("Show help") cli.HelpFlag.(*cli.BoolFlag).Usage = gotext.Get("Show help")
err = app.RunContext(ctx, os.Args) err := app.RunContext(ctx, os.Args)
if err != nil { if err != nil {
slog.Error(gotext.Get("Error while running app"), "err", err) slog.Error(gotext.Get("Error while running app"), "err", err)
} }

@ -59,8 +59,8 @@ type PackageFinder interface {
} }
type Config interface { type Config interface {
GetPaths() *config.Paths GetPaths(ctx context.Context) *config.Paths
PagerStyle() string PagerStyle(ctx context.Context) string
} }
type Builder struct { type Builder struct {
@ -88,7 +88,7 @@ func NewBuilder(
} }
func (b *Builder) UpdateOptsFromPkg(pkg *db.Package, packages []string) { func (b *Builder) UpdateOptsFromPkg(pkg *db.Package, packages []string) {
repodir := b.config.GetPaths().RepoDir repodir := b.config.GetPaths(b.ctx).RepoDir
b.opts.Repository = pkg.Repository b.opts.Repository = pkg.Repository
if pkg.BasePkgName != "" { if pkg.BasePkgName != "" {
b.opts.Script = filepath.Join(repodir, pkg.Repository, pkg.BasePkgName, "alr.sh") 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, ctx,
b.opts.Script, b.opts.Script,
basePkg, basePkg,
b.config.PagerStyle(), b.config.PagerStyle(ctx),
b.opts.Interactive, b.opts.Interactive,
) )
if err != nil { if err != nil {
@ -392,7 +392,7 @@ func (b *Builder) getDirs(basePkg string) (types.Directories, error) {
return types.Directories{}, err return types.Directories{}, err
} }
baseDir := filepath.Join(b.config.GetPaths().PkgsDir, basePkg) // Определяем базовую директорию baseDir := filepath.Join(b.config.GetPaths(b.ctx).PkgsDir, basePkg) // Определяем базовую директорию
return types.Directories{ return types.Directories{
BaseDir: baseDir, BaseDir: baseDir,
SrcDir: filepath.Join(baseDir, "src"), SrcDir: filepath.Join(baseDir, "src"),

@ -144,11 +144,11 @@ func (m *TestManager) IsInstalled(pkg string) (bool, error) {
type TestConfig struct{} type TestConfig struct{}
func (c *TestConfig) PagerStyle() string { func (c *TestConfig) PagerStyle(ctx context.Context) string {
return "native" return "native"
} }
func (c *TestConfig) GetPaths() *config.Paths { func (c *TestConfig) GetPaths(ctx context.Context) *config.Paths {
return &config.Paths{ return &config.Paths{
CacheDir: "/tmp", CacheDir: "/tmp",
} }

@ -67,7 +67,7 @@ type action struct {
// If repos is set to nil, the repos in the ALR config will be used. // 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 { func (rs *Repos) Pull(ctx context.Context, repos []types.Repo) error {
if repos == nil { if repos == nil {
repos = rs.cfg.Repos() repos = rs.cfg.Repos(ctx)
} }
for _, repo := range 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) slog.Info(gotext.Get("Pulling repository"), "name", repo.Name)
repoDir := filepath.Join(rs.cfg.GetPaths().RepoDir, repo.Name) repoDir := filepath.Join(rs.cfg.GetPaths(ctx).RepoDir, repo.Name)
var repoFS billy.Filesystem var repoFS billy.Filesystem
gitDir := filepath.Join(repoDir, ".git") gitDir := filepath.Join(repoDir, ".git")

@ -32,13 +32,13 @@ import (
type TestALRConfig struct{} type TestALRConfig struct{}
func (c *TestALRConfig) GetPaths() *config.Paths { func (c *TestALRConfig) GetPaths(ctx context.Context) *config.Paths {
return &config.Paths{ return &config.Paths{
DBPath: ":memory:", DBPath: ":memory:",
} }
} }
func (c *TestALRConfig) Repos() []types.Repo { func (c *TestALRConfig) Repos(ctx context.Context) []types.Repo {
return []types.Repo{ return []types.Repo{
{ {
Name: "test", Name: "test",

@ -44,7 +44,7 @@ type TestALRConfig struct {
PkgsDir string PkgsDir string
} }
func (c *TestALRConfig) GetPaths() *config.Paths { func (c *TestALRConfig) GetPaths(ctx context.Context) *config.Paths {
return &config.Paths{ return &config.Paths{
DBPath: ":memory:", DBPath: ":memory:",
CacheDir: c.CacheDir, CacheDir: c.CacheDir,
@ -53,7 +53,7 @@ func (c *TestALRConfig) GetPaths() *config.Paths {
} }
} }
func (c *TestALRConfig) Repos() []types.Repo { func (c *TestALRConfig) Repos(ctx context.Context) []types.Repo {
return []types.Repo{} return []types.Repo{}
} }

@ -17,14 +17,16 @@
package repos package repos
import ( import (
"context"
"gitea.plemya-x.ru/Plemya-x/ALR/internal/config" "gitea.plemya-x.ru/Plemya-x/ALR/internal/config"
database "gitea.plemya-x.ru/Plemya-x/ALR/internal/db" database "gitea.plemya-x.ru/Plemya-x/ALR/internal/db"
"gitea.plemya-x.ru/Plemya-x/ALR/internal/types" "gitea.plemya-x.ru/Plemya-x/ALR/internal/types"
) )
type Config interface { type Config interface {
GetPaths() *config.Paths GetPaths(ctx context.Context) *config.Paths
Repos() []types.Repo Repos(ctx context.Context) []types.Repo
} }
type Repos struct { type Repos struct {

61
repo.go

@ -25,6 +25,7 @@ import (
"path/filepath" "path/filepath"
"github.com/leonelquinteros/gotext" "github.com/leonelquinteros/gotext"
"github.com/pelletier/go-toml/v2"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
"golang.org/x/exp/slices" "golang.org/x/exp/slices"
@ -60,13 +61,7 @@ func AddRepoCmd() *cli.Command {
repoURL := c.String("url") repoURL := c.String("url")
cfg := config.New() cfg := config.New()
err := cfg.Load() reposSlice := cfg.Repos(ctx)
if err != nil {
slog.Error(gotext.Get("Error loading config"), "err", err)
os.Exit(1)
}
reposSlice := cfg.Repos()
for _, repo := range reposSlice { for _, repo := range reposSlice {
if repo.URL == repoURL { if repo.URL == repoURL {
@ -79,11 +74,18 @@ func AddRepoCmd() *cli.Command {
Name: name, Name: name,
URL: repoURL, URL: repoURL,
}) })
cfg.SetRepos(reposSlice)
err = cfg.SaveUserConfig() cfg.SetRepos(ctx, reposSlice)
cfgFl, err := os.Create(cfg.GetPaths(ctx).ConfigPath)
if err != nil { if err != nil {
slog.Error(gotext.Get("Error saving config"), "err", err) slog.Error(gotext.Get("Error opening config file"), "err", err)
os.Exit(1)
}
err = cfg.Save(cfgFl)
if err != nil {
slog.Error(gotext.Get("Error encoding config"), "err", err)
os.Exit(1) os.Exit(1)
} }
@ -94,7 +96,7 @@ func AddRepoCmd() *cli.Command {
} }
rs := repos.New(cfg, db) rs := repos.New(cfg, db)
err = rs.Pull(ctx, cfg.Repos()) err = rs.Pull(ctx, cfg.Repos(ctx))
if err != nil { if err != nil {
slog.Error(gotext.Get("Error pulling repos"), "err", err) slog.Error(gotext.Get("Error pulling repos"), "err", err)
os.Exit(1) os.Exit(1)
@ -123,15 +125,10 @@ func RemoveRepoCmd() *cli.Command {
name := c.String("name") name := c.String("name")
cfg := config.New() cfg := config.New()
err := cfg.Load()
if err != nil {
slog.Error(gotext.Get("Error loading config"), "err", err)
os.Exit(1)
}
found := false found := false
index := 0 index := 0
reposSlice := cfg.Repos() reposSlice := cfg.Repos(ctx)
for i, repo := range reposSlice { for i, repo := range reposSlice {
if repo.Name == name { if repo.Name == name {
index = i index = i
@ -143,17 +140,29 @@ func RemoveRepoCmd() *cli.Command {
os.Exit(1) os.Exit(1)
} }
cfg.SetRepos(slices.Delete(reposSlice, index, index+1)) cfg.SetRepos(ctx, slices.Delete(reposSlice, index, index+1))
err = os.RemoveAll(filepath.Join(cfg.GetPaths().RepoDir, name)) cfgFl, err := os.Create(cfg.GetPaths(ctx).ConfigPath)
if err != nil {
slog.Error(gotext.Get("Error opening config file"), "err", err)
os.Exit(1)
}
err = toml.NewEncoder(cfgFl).Encode(&cfg)
if err != nil {
slog.Error(gotext.Get("Error encoding config"), "err", err)
os.Exit(1)
}
err = os.RemoveAll(filepath.Join(cfg.GetPaths(ctx).RepoDir, name))
if err != nil { if err != nil {
slog.Error(gotext.Get("Error removing repo directory"), "err", err) slog.Error(gotext.Get("Error removing repo directory"), "err", err)
os.Exit(1) os.Exit(1)
} }
err = cfg.SaveUserConfig() err = cfg.Save(cfgFl)
if err != nil { if err != nil {
slog.Error(gotext.Get("Error saving config"), "err", err) slog.Error(gotext.Get("Error encoding config"), "err", err)
os.Exit(1) os.Exit(1)
} }
@ -181,19 +190,13 @@ func RefreshCmd() *cli.Command {
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
ctx := c.Context ctx := c.Context
cfg := config.New() cfg := config.New()
err := cfg.Load()
if err != nil {
slog.Error(gotext.Get("Error loading config"), "err", err)
os.Exit(1)
}
db := database.New(cfg) db := database.New(cfg)
err = db.Init(ctx) err := db.Init(ctx)
if err != nil { if err != nil {
os.Exit(1) os.Exit(1)
} }
rs := repos.New(cfg, db) rs := repos.New(cfg, db)
err = rs.Pull(ctx, cfg.Repos()) err = rs.Pull(ctx, cfg.Repos(ctx))
if err != nil { if err != nil {
slog.Error(gotext.Get("Error pulling repos"), "err", err) slog.Error(gotext.Get("Error pulling repos"), "err", err)
os.Exit(1) os.Exit(1)

@ -65,14 +65,8 @@ func SearchCmd() *cli.Command {
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
ctx := c.Context ctx := c.Context
cfg := config.New() cfg := config.New()
err := cfg.Load()
if err != nil {
slog.Error(gotext.Get("Error loading config"), "err", err)
os.Exit(1)
}
db := database.New(cfg) db := database.New(cfg)
err = db.Init(ctx) err := db.Init(ctx)
defer db.Close() defer db.Close()
if err != nil { if err != nil {

@ -57,15 +57,9 @@ func UpgradeCmd() *cli.Command {
ctx := c.Context ctx := c.Context
cfg := config.New() cfg := config.New()
err := cfg.Load()
if err != nil {
slog.Error(gotext.Get("Error loading config"), "err", err)
os.Exit(1)
}
db := database.New(cfg) db := database.New(cfg)
rs := repos.New(cfg, db) rs := repos.New(cfg, db)
err = db.Init(ctx) err := db.Init(ctx)
if err != nil { if err != nil {
slog.Error(gotext.Get("Error initialization database"), "err", err) slog.Error(gotext.Get("Error initialization database"), "err", err)
os.Exit(1) os.Exit(1)
@ -83,8 +77,8 @@ func UpgradeCmd() *cli.Command {
os.Exit(1) os.Exit(1)
} }
if cfg.AutoPull() { if cfg.AutoPull(ctx) {
err = rs.Pull(ctx, cfg.Repos()) err = rs.Pull(ctx, cfg.Repos(ctx))
if err != nil { if err != nil {
slog.Error(gotext.Get("Error pulling repos"), "err", err) slog.Error(gotext.Get("Error pulling repos"), "err", err)
os.Exit(1) os.Exit(1)