2 Commits

Author SHA1 Message Date
fd643ea6cd chore: run make fmt and make i18n 2025-01-22 18:12:26 +03:00
309ecf784f feat: add autoPull in config 2025-01-22 18:10:57 +03:00
11 changed files with 119 additions and 85 deletions

View File

@@ -65,11 +65,13 @@ func BuildCmd() *cli.Command {
script = filepath.Join(config.GetPaths(ctx).RepoDir, c.String("package"), "alr.sh")
}
if config.GetInstance(ctx).AutoPull(ctx) {
err := repos.Pull(ctx, config.Config(ctx).Repos)
if err != nil {
slog.Error(gotext.Get("Error pulling repositories"), "err", err)
os.Exit(1)
}
}
mgr := manager.Detect()
if mgr == nil {

2
gen.go
View File

@@ -34,7 +34,7 @@ func GenCmd() *cli.Command {
Usage: gotext.Get("Generate a ALR script from a template"),
Aliases: []string{"gen"},
Subcommands: []*cli.Command{
&cli.Command{
{
Name: "pip",
Usage: gotext.Get("Generate a ALR script for a pip module"),
Flags: []cli.Flag{

View File

@@ -36,7 +36,7 @@ import (
)
func HelperCmd() *cli.Command {
var helperListCmd = &cli.Command{
helperListCmd := &cli.Command{
Name: "list",
Usage: gotext.Get("List all the available helper commands"),
Aliases: []string{"ls"},

View File

@@ -52,6 +52,11 @@ func InfoCmd() *cli.Command {
cfg := config.New()
db := db.New(cfg)
err := db.Init(ctx)
if err != nil {
slog.Error(gotext.Get("Error initialization database"), "err", err)
os.Exit(1)
}
rs := repos.New(cfg, db)
args := c.Args()
@@ -60,11 +65,13 @@ func InfoCmd() *cli.Command {
os.Exit(1)
}
if cfg.AutoPull(ctx) {
err := rs.Pull(ctx, cfg.Repos(ctx))
if err != nil {
slog.Error(gotext.Get("Error pulling repositories"))
slog.Error(gotext.Get("Error pulling repos"), "err", err)
os.Exit(1)
}
}
found, _, err := rs.FindPkgs(ctx, args.Slice())
if err != nil {

View File

@@ -37,7 +37,6 @@ import (
)
func InstallCmd() *cli.Command {
return &cli.Command{
Name: "install",
Usage: gotext.Get("Install a new package"),
@@ -64,11 +63,13 @@ func InstallCmd() *cli.Command {
os.Exit(1)
}
if config.GetInstance(ctx).AutoPull(ctx) {
err := repos.Pull(ctx, config.Config(ctx).Repos)
if err != nil {
slog.Error(gotext.Get("Error pulling repositories"), "err", err)
os.Exit(1)
}
}
found, notFound, err := repos.FindPkgs(ctx, args.Slice())
if err != nil {

View File

@@ -45,6 +45,7 @@ var defaultConfig = &types.Config{
RootCmd: "sudo",
PagerStyle: "native",
IgnorePkgUpdates: []string{},
AutoPull: true,
Repos: []types.Repo{
{
Name: "default",
@@ -162,3 +163,10 @@ func (c *ALRConfig) IgnorePkgUpdates(ctx context.Context) []string {
})
return c.cfg.IgnorePkgUpdates
}
func (c *ALRConfig) AutoPull(ctx context.Context) bool {
c.cfgOnce.Do(func() {
c.Load(ctx)
})
return c.cfg.AutoPull
}

View File

@@ -26,23 +26,23 @@ msgid ""
"Build package from scratch even if there's an already built package available"
msgstr ""
#: build.go:70
#: build.go:71
msgid "Error pulling repositories"
msgstr ""
#: build.go:76
#: build.go:78
msgid "Unable to detect a supported package manager on the system"
msgstr ""
#: build.go:87
#: build.go:89
msgid "Error building package"
msgstr ""
#: build.go:93
#: build.go:95
msgid "Error getting working directory"
msgstr ""
#: build.go:101
#: build.go:103
msgid "Error moving the package"
msgstr ""
@@ -106,47 +106,55 @@ msgstr ""
msgid "Show all information, not just for the current distro"
msgstr ""
#: info.go:59
#: info.go:57
msgid "Error initialization database"
msgstr ""
#: info.go:64
msgid "Command info expected at least 1 argument, got %d"
msgstr ""
#: info.go:71
#: info.go:78
msgid "Error finding packages"
msgstr ""
#: info.go:87
#: info.go:94
msgid "Error parsing os-release file"
msgstr ""
#: info.go:96
#: info.go:103
msgid "Error resolving overrides"
msgstr ""
#: info.go:105 info.go:111
#: info.go:112 info.go:118
msgid "Error encoding script variables"
msgstr ""
#: install.go:57
#: install.go:42
msgid "Install a new package"
msgstr ""
#: install.go:56
msgid "Command install expected at least 1 argument, got %d"
msgstr ""
#: install.go:90
#: install.go:91
msgid "Error getting packages"
msgstr ""
#: install.go:99
#: install.go:100
msgid "Error iterating over packages"
msgstr ""
#: install.go:112
#: install.go:113
msgid "Remove an installed package"
msgstr ""
#: install.go:117
#: install.go:118
msgid "Command remove expected at least 1 argument, got %d"
msgstr ""
#: install.go:129
#: install.go:130
msgid "Error removing packages"
msgstr ""
@@ -174,39 +182,39 @@ msgstr ""
msgid "Choose which optional package(s) to install"
msgstr ""
#: internal/config/config.go:63
#: internal/config/config.go:64
msgid "Error opening config file, using defaults"
msgstr ""
#: internal/config/config.go:76
#: internal/config/config.go:77
msgid "Error decoding config file, using defaults"
msgstr ""
#: internal/config/config.go:88
#: internal/config/config.go:89
msgid "Unable to detect user config directory"
msgstr ""
#: internal/config/config.go:96
#: internal/config/config.go:97
msgid "Unable to create ALR config directory"
msgstr ""
#: internal/config/config.go:105
#: internal/config/config.go:106
msgid "Unable to create ALR config file"
msgstr ""
#: internal/config/config.go:111
#: internal/config/config.go:112
msgid "Error encoding default configuration"
msgstr ""
#: internal/config/config.go:120
#: internal/config/config.go:121
msgid "Unable to detect cache directory"
msgstr ""
#: internal/config/config.go:130
#: internal/config/config.go:131
msgid "Unable to create repo cache directory"
msgstr ""
#: internal/config/config.go:136
#: internal/config/config.go:137
msgid "Unable to create package cache directory"
msgstr ""
@@ -251,11 +259,7 @@ msgstr ""
msgid "List ALR repo packages"
msgstr ""
#: list.go:54
msgid "Error initialization database"
msgstr ""
#: list.go:88
#: list.go:91
msgid "Error listing installed packages"
msgstr ""
@@ -437,6 +441,6 @@ msgstr ""
msgid "Upgrade all installed packages"
msgstr ""
#: upgrade.go:79
#: upgrade.go:83
msgid "Error checking for updates"
msgstr ""

View File

@@ -34,23 +34,23 @@ msgid ""
"Build package from scratch even if there's an already built package available"
msgstr ""
#: build.go:70
#: build.go:71
msgid "Error pulling repositories"
msgstr ""
#: build.go:76
#: build.go:78
msgid "Unable to detect a supported package manager on the system"
msgstr ""
#: build.go:87
#: build.go:89
msgid "Error building package"
msgstr "Ошибка при сборке пакета"
#: build.go:93
#: build.go:95
msgid "Error getting working directory"
msgstr ""
#: build.go:101
#: build.go:103
msgid "Error moving the package"
msgstr ""
@@ -114,47 +114,55 @@ msgstr "Напечатать информацию о пакете"
msgid "Show all information, not just for the current distro"
msgstr "Показывать всю информацию, а не только для текущего дистрибутива"
#: info.go:59
#: info.go:57
msgid "Error initialization database"
msgstr ""
#: info.go:64
msgid "Command info expected at least 1 argument, got %d"
msgstr ""
#: info.go:71
#: info.go:78
msgid "Error finding packages"
msgstr ""
#: info.go:87
#: info.go:94
msgid "Error parsing os-release file"
msgstr ""
#: info.go:96
#: info.go:103
msgid "Error resolving overrides"
msgstr ""
#: info.go:105 info.go:111
#: info.go:112 info.go:118
msgid "Error encoding script variables"
msgstr ""
#: install.go:57
#: install.go:42
msgid "Install a new package"
msgstr ""
#: install.go:56
msgid "Command install expected at least 1 argument, got %d"
msgstr ""
#: install.go:90
#: install.go:91
msgid "Error getting packages"
msgstr ""
#: install.go:99
#: install.go:100
msgid "Error iterating over packages"
msgstr ""
#: install.go:112
#: install.go:113
msgid "Remove an installed package"
msgstr ""
#: install.go:117
#: install.go:118
msgid "Command remove expected at least 1 argument, got %d"
msgstr ""
#: install.go:129
#: install.go:130
msgid "Error removing packages"
msgstr ""
@@ -182,39 +190,39 @@ msgstr ""
msgid "Choose which optional package(s) to install"
msgstr ""
#: internal/config/config.go:63
#: internal/config/config.go:64
msgid "Error opening config file, using defaults"
msgstr ""
#: internal/config/config.go:76
#: internal/config/config.go:77
msgid "Error decoding config file, using defaults"
msgstr ""
#: internal/config/config.go:88
#: internal/config/config.go:89
msgid "Unable to detect user config directory"
msgstr ""
#: internal/config/config.go:96
#: internal/config/config.go:97
msgid "Unable to create ALR config directory"
msgstr ""
#: internal/config/config.go:105
#: internal/config/config.go:106
msgid "Unable to create ALR config file"
msgstr ""
#: internal/config/config.go:111
#: internal/config/config.go:112
msgid "Error encoding default configuration"
msgstr ""
#: internal/config/config.go:120
#: internal/config/config.go:121
msgid "Unable to detect cache directory"
msgstr ""
#: internal/config/config.go:130
#: internal/config/config.go:131
msgid "Unable to create repo cache directory"
msgstr ""
#: internal/config/config.go:136
#: internal/config/config.go:137
msgid "Unable to create package cache directory"
msgstr ""
@@ -259,11 +267,7 @@ msgstr "ОШИБКА"
msgid "List ALR repo packages"
msgstr ""
#: list.go:54
msgid "Error initialization database"
msgstr ""
#: list.go:88
#: list.go:91
msgid "Error listing installed packages"
msgstr ""
@@ -446,6 +450,6 @@ msgstr ""
msgid "Upgrade all installed packages"
msgstr ""
#: upgrade.go:79
#: upgrade.go:83
msgid "Error checking for updates"
msgstr ""

View File

@@ -26,6 +26,7 @@ type Config struct {
IgnorePkgUpdates []string `toml:"ignorePkgUpdates"`
Repos []Repo `toml:"repo"`
Unsafe Unsafe `toml:"unsafe"`
AutoPull bool `toml:"autoPull"`
}
// Repo represents a ALR repo within a configuration file

View File

@@ -55,11 +55,14 @@ func ListCmd() *cli.Command {
os.Exit(1)
}
rs := repos.New(cfg, db)
if cfg.AutoPull(ctx) {
err = rs.Pull(ctx, cfg.Repos(ctx))
if err != nil {
slog.Error(gotext.Get("Error pulling repositories"), "err", err)
os.Exit(1)
}
}
where := "true"
args := []any(nil)

View File

@@ -56,6 +56,8 @@ func UpgradeCmd() *cli.Command {
Action: func(c *cli.Context) error {
ctx := c.Context
cfg := config.GetInstance(ctx)
info, err := distro.ParseOSRelease(ctx)
if err != nil {
slog.Error(gotext.Get("Error parsing os-release file"), "err", err)
@@ -68,11 +70,13 @@ func UpgradeCmd() *cli.Command {
os.Exit(1)
}
if cfg.AutoPull(ctx) {
err = repos.Pull(ctx, config.Config(ctx).Repos)
if err != nil {
slog.Error(gotext.Get("Error pulling repos"), "err", err)
os.Exit(1)
}
}
updates, err := checkForUpdates(ctx, mgr, info)
if err != nil {