Добавление возможности обновления системным пакетным менеджером при alr up
All checks were successful
Pre-commit / pre-commit (push) Successful in 5m39s
All checks were successful
Pre-commit / pre-commit (push) Successful in 5m39s
This commit is contained in:
@@ -76,6 +76,7 @@ var configKeys = []string{
|
||||
"autoPull",
|
||||
"logLevel",
|
||||
"ignorePkgUpdates",
|
||||
"updateSystemOnUpgrade",
|
||||
}
|
||||
|
||||
func SetConfig() *cli.Command {
|
||||
@@ -137,6 +138,12 @@ func SetConfig() *cli.Command {
|
||||
}
|
||||
}
|
||||
deps.Cfg.System.SetIgnorePkgUpdates(updates)
|
||||
case "updateSystemOnUpgrade":
|
||||
boolValue, err := strconv.ParseBool(value)
|
||||
if err != nil {
|
||||
return cliutils.FormatCliExit(gotext.Get("invalid boolean value for %s: %s", key, value), err)
|
||||
}
|
||||
deps.Cfg.System.SetUpdateSystemOnUpgrade(boolValue)
|
||||
case "repo", "repos":
|
||||
return cliutils.FormatCliExit(gotext.Get("use 'repo add/remove' commands to manage repositories"), nil)
|
||||
default:
|
||||
@@ -206,6 +213,8 @@ func GetConfig() *cli.Command {
|
||||
} else {
|
||||
fmt.Println(strings.Join(updates, ", "))
|
||||
}
|
||||
case "updateSystemOnUpgrade":
|
||||
fmt.Println(deps.Cfg.UpdateSystemOnUpgrade())
|
||||
case "repo", "repos":
|
||||
repos := deps.Cfg.Repos()
|
||||
if len(repos) == 0 {
|
||||
|
@@ -56,6 +56,7 @@ func defaultConfigKoanf() *koanf.Koanf {
|
||||
"ignorePkgUpdates": []string{},
|
||||
"logLevel": "info",
|
||||
"autoPull": true,
|
||||
"updateSystemOnUpgrade": false,
|
||||
"repos": []types.Repo{
|
||||
{
|
||||
Name: "alr-default",
|
||||
@@ -114,6 +115,11 @@ func (c *ALRConfig) Load() error {
|
||||
}
|
||||
}
|
||||
|
||||
// Выполняем миграцию конфигурации при необходимости
|
||||
if err := c.migrateConfig(); err != nil {
|
||||
return fmt.Errorf("failed to migrate config: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -125,6 +131,45 @@ func (c *ALRConfig) ToYAML() (string, error) {
|
||||
return string(data), nil
|
||||
}
|
||||
|
||||
func (c *ALRConfig) migrateConfig() error {
|
||||
// Проверяем, существует ли конфигурационный файл
|
||||
if _, err := os.Stat(constants.SystemConfigPath); os.IsNotExist(err) {
|
||||
// Если файла нет, но конфигурация уже загружена (из defaults или env),
|
||||
// создаем файл с настройкой по умолчанию
|
||||
needsCreation := false
|
||||
|
||||
// Проверяем, установлена ли переменная окружения ALR_UPDATESYSTEMONUPGRADE
|
||||
if os.Getenv("ALR_UPDATESYSTEMONUPGRADE") == "" {
|
||||
// Если переменная не установлена, проверяем наличие пакетов ALR
|
||||
// чтобы определить, нужно ли включить эту опцию для обновления
|
||||
needsCreation = true
|
||||
}
|
||||
|
||||
if needsCreation {
|
||||
// Устанавливаем значение false по умолчанию для новой опции
|
||||
c.System.SetUpdateSystemOnUpgrade(false)
|
||||
// Сохраняем конфигурацию
|
||||
if err := c.System.Save(); err != nil {
|
||||
// Если не удается сохранить - это не критично, продолжаем работу
|
||||
return nil
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Если файл существует, проверяем, есть ли в нем новая опция
|
||||
if !c.System.k.Exists("updateSystemOnUpgrade") {
|
||||
// Если опции нет, добавляем ее со значением по умолчанию
|
||||
c.System.SetUpdateSystemOnUpgrade(false)
|
||||
// Сохраняем обновленную конфигурацию
|
||||
if err := c.System.Save(); err != nil {
|
||||
// Если не удается сохранить - это не критично, продолжаем работу
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 }
|
||||
@@ -133,4 +178,5 @@ func (c *ALRConfig) SetRepos(repos []types.Repo) { c.System.SetRepos(repos) }
|
||||
func (c *ALRConfig) IgnorePkgUpdates() []string { return c.cfg.IgnorePkgUpdates }
|
||||
func (c *ALRConfig) LogLevel() string { return c.cfg.LogLevel }
|
||||
func (c *ALRConfig) UseRootCmd() bool { return c.cfg.UseRootCmd }
|
||||
func (c *ALRConfig) UpdateSystemOnUpgrade() bool { return c.cfg.UpdateSystemOnUpgrade }
|
||||
func (c *ALRConfig) GetPaths() *Paths { return c.paths }
|
||||
|
@@ -142,3 +142,10 @@ func (c *SystemConfig) SetRepos(v []types.Repo) {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *SystemConfig) SetUpdateSystemOnUpgrade(v bool) {
|
||||
err := c.k.Set("updateSystemOnUpgrade", v)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
@@ -21,13 +21,14 @@ package types
|
||||
|
||||
// Config represents the ALR configuration file
|
||||
type Config struct {
|
||||
RootCmd string `json:"rootCmd" koanf:"rootCmd"`
|
||||
UseRootCmd bool `json:"useRootCmd" koanf:"useRootCmd"`
|
||||
PagerStyle string `json:"pagerStyle" koanf:"pagerStyle"`
|
||||
IgnorePkgUpdates []string `json:"ignorePkgUpdates" koanf:"ignorePkgUpdates"`
|
||||
Repos []Repo `json:"repo" koanf:"repo"`
|
||||
AutoPull bool `json:"autoPull" koanf:"autoPull"`
|
||||
LogLevel string `json:"logLevel" koanf:"logLevel"`
|
||||
RootCmd string `json:"rootCmd" koanf:"rootCmd"`
|
||||
UseRootCmd bool `json:"useRootCmd" koanf:"useRootCmd"`
|
||||
PagerStyle string `json:"pagerStyle" koanf:"pagerStyle"`
|
||||
IgnorePkgUpdates []string `json:"ignorePkgUpdates" koanf:"ignorePkgUpdates"`
|
||||
Repos []Repo `json:"repo" koanf:"repo"`
|
||||
AutoPull bool `json:"autoPull" koanf:"autoPull"`
|
||||
LogLevel string `json:"logLevel" koanf:"logLevel"`
|
||||
UpdateSystemOnUpgrade bool `json:"updateSystemOnUpgrade" koanf:"updateSystemOnUpgrade"`
|
||||
}
|
||||
|
||||
// Repo represents a ALR repo within a configuration file
|
||||
|
13
upgrade.go
13
upgrade.go
@@ -84,6 +84,19 @@ func UpgradeCmd() *cli.Command {
|
||||
}
|
||||
defer deps.Defer()
|
||||
|
||||
// Обновляем систему, если это включено в конфигурации
|
||||
if deps.Cfg.UpdateSystemOnUpgrade() {
|
||||
slog.Info(gotext.Get("Updating system packages..."))
|
||||
err = deps.Manager.UpgradeAll(&manager.Opts{
|
||||
NoConfirm: !c.Bool("interactive"),
|
||||
Args: manager.Args,
|
||||
})
|
||||
if err != nil {
|
||||
return cliutils.FormatCliExit(gotext.Get("Error updating system packages"), err)
|
||||
}
|
||||
slog.Info(gotext.Get("System packages updated successfully"))
|
||||
}
|
||||
|
||||
builder, err := build.NewMainBuilder(
|
||||
deps.Cfg,
|
||||
deps.Manager,
|
||||
|
Reference in New Issue
Block a user