diff --git a/build.go b/build.go index b31b5ad..b328975 100644 --- a/build.go +++ b/build.go @@ -65,10 +65,12 @@ func BuildCmd() *cli.Command { script = filepath.Join(config.GetPaths(ctx).RepoDir, c.String("package"), "alr.sh") } - err := repos.Pull(ctx, config.Config(ctx).Repos) - if err != nil { - slog.Error(gotext.Get("Error pulling repositories"), "err", err) - 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) + } } mgr := manager.Detect() diff --git a/info.go b/info.go index b633e40..5a4f290 100644 --- a/info.go +++ b/info.go @@ -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,10 +65,12 @@ func InfoCmd() *cli.Command { os.Exit(1) } - err := rs.Pull(ctx, cfg.Repos(ctx)) - if err != nil { - slog.Error(gotext.Get("Error pulling repositories")) - os.Exit(1) + if cfg.AutoPull(ctx) { + err := rs.Pull(ctx, cfg.Repos(ctx)) + if err != nil { + slog.Error(gotext.Get("Error pulling repos"), "err", err) + os.Exit(1) + } } found, _, err := rs.FindPkgs(ctx, args.Slice()) diff --git a/install.go b/install.go index d39e3d1..d1fdd1a 100644 --- a/install.go +++ b/install.go @@ -64,10 +64,12 @@ func InstallCmd() *cli.Command { os.Exit(1) } - err := repos.Pull(ctx, config.Config(ctx).Repos) - if err != nil { - slog.Error(gotext.Get("Error pulling repositories"), "err", err) - 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()) diff --git a/internal/config/config.go b/internal/config/config.go index 10231d6..f8457c6 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -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 +} diff --git a/internal/translations/default.pot b/internal/translations/default.pot index 6bbbc32..56f1c34 100644 --- a/internal/translations/default.pot +++ b/internal/translations/default.pot @@ -26,23 +26,23 @@ msgid "" "Build package from scratch even if there's an already built package available" msgstr "" -#: build.go:70 -msgid "Error pulling repositories" +#: build.go:71 +msgid "Error pulling repos" 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 "" @@ -66,10 +66,6 @@ msgstr "" msgid "Unable to create new cache directory" msgstr "" -#: fix.go:62 -msgid "Error pulling repos" -msgstr "" - #: fix.go:66 msgid "Done" msgstr "" @@ -110,43 +106,51 @@ msgstr "" msgid "Command info expected at least 1 argument, got %d" msgstr "" -#: info.go:71 +#: info.go:73 msgid "Error finding packages" msgstr "" -#: info.go:87 +#: info.go:89 msgid "Error parsing os-release file" msgstr "" -#: info.go:96 +#: info.go:98 msgid "Error resolving overrides" msgstr "" -#: info.go:105 info.go:111 +#: info.go:107 info.go:113 msgid "Error encoding script variables" msgstr "" +#: install.go:43 +msgid "Install a new package" +msgstr "" + #: install.go:57 msgid "Command install expected at least 1 argument, got %d" msgstr "" -#: install.go:90 +#: install.go:70 +msgid "Error pulling repositories" +msgstr "" + +#: install.go:92 msgid "Error getting packages" msgstr "" -#: install.go:99 +#: install.go:101 msgid "Error iterating over packages" msgstr "" -#: install.go:112 +#: install.go:114 msgid "Remove an installed package" msgstr "" -#: install.go:117 +#: install.go:119 msgid "Command remove expected at least 1 argument, got %d" msgstr "" -#: install.go:129 +#: install.go:131 msgid "Error removing packages" msgstr "" @@ -174,39 +178,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 "" @@ -255,7 +259,7 @@ msgstr "" 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 "" diff --git a/internal/translations/po/ru/default.po b/internal/translations/po/ru/default.po index 0048e81..a48e177 100644 --- a/internal/translations/po/ru/default.po +++ b/internal/translations/po/ru/default.po @@ -34,23 +34,23 @@ msgid "" "Build package from scratch even if there's an already built package available" msgstr "" -#: build.go:70 -msgid "Error pulling repositories" +#: build.go:71 +msgid "Error pulling repos" 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 "" @@ -74,10 +74,6 @@ msgstr "" msgid "Unable to create new cache directory" msgstr "" -#: fix.go:62 -msgid "Error pulling repos" -msgstr "" - #: fix.go:66 msgid "Done" msgstr "" @@ -118,43 +114,51 @@ msgstr "Показывать всю информацию, а не только msgid "Command info expected at least 1 argument, got %d" msgstr "" -#: info.go:71 +#: info.go:73 msgid "Error finding packages" msgstr "" -#: info.go:87 +#: info.go:89 msgid "Error parsing os-release file" msgstr "" -#: info.go:96 +#: info.go:98 msgid "Error resolving overrides" msgstr "" -#: info.go:105 info.go:111 +#: info.go:107 info.go:113 msgid "Error encoding script variables" msgstr "" +#: install.go:43 +msgid "Install a new package" +msgstr "" + #: install.go:57 msgid "Command install expected at least 1 argument, got %d" msgstr "" -#: install.go:90 +#: install.go:70 +msgid "Error pulling repositories" +msgstr "" + +#: install.go:92 msgid "Error getting packages" msgstr "" -#: install.go:99 +#: install.go:101 msgid "Error iterating over packages" msgstr "" -#: install.go:112 +#: install.go:114 msgid "Remove an installed package" msgstr "" -#: install.go:117 +#: install.go:119 msgid "Command remove expected at least 1 argument, got %d" msgstr "" -#: install.go:129 +#: install.go:131 msgid "Error removing packages" msgstr "" @@ -182,39 +186,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 "" @@ -263,7 +267,7 @@ msgstr "" 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 "" diff --git a/internal/types/config.go b/internal/types/config.go index 241cfbe..62a6950 100644 --- a/internal/types/config.go +++ b/internal/types/config.go @@ -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 diff --git a/list.go b/list.go index 19ad7a6..6552f52 100644 --- a/list.go +++ b/list.go @@ -55,10 +55,13 @@ func ListCmd() *cli.Command { os.Exit(1) } rs := repos.New(cfg, db) - err = rs.Pull(ctx, cfg.Repos(ctx)) - if err != nil { - slog.Error(gotext.Get("Error pulling repositories"), "err", err) - os.Exit(1) + + 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" diff --git a/upgrade.go b/upgrade.go index 3002641..8ba22f6 100644 --- a/upgrade.go +++ b/upgrade.go @@ -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,10 +70,12 @@ func UpgradeCmd() *cli.Command { os.Exit(1) } - err = repos.Pull(ctx, config.Config(ctx).Repos) - if err != nil { - slog.Error(gotext.Get("Error pulling repos"), "err", err) - 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)