forked from Plemya-x/ALR
		
	chore: make usage strings translatable
This commit is contained in:
		
							
								
								
									
										126
									
								
								build.go
									
									
									
									
									
								
							
							
						
						
									
										126
									
								
								build.go
									
									
									
									
									
								
							@@ -35,73 +35,75 @@ import (
 | 
			
		||||
	"gitea.plemya-x.ru/Plemya-x/ALR/pkg/repos"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var buildCmd = &cli.Command{
 | 
			
		||||
	Name:  "build",
 | 
			
		||||
	Usage: "Build a local package",
 | 
			
		||||
	Flags: []cli.Flag{
 | 
			
		||||
		&cli.StringFlag{
 | 
			
		||||
			Name:    "script",
 | 
			
		||||
			Aliases: []string{"s"},
 | 
			
		||||
			Value:   "alr.sh",
 | 
			
		||||
			Usage:   "Path to the build script",
 | 
			
		||||
func BuildCmd() *cli.Command {
 | 
			
		||||
	return &cli.Command{
 | 
			
		||||
		Name:  "build",
 | 
			
		||||
		Usage: gotext.Get("Build a local package"),
 | 
			
		||||
		Flags: []cli.Flag{
 | 
			
		||||
			&cli.StringFlag{
 | 
			
		||||
				Name:    "script",
 | 
			
		||||
				Aliases: []string{"s"},
 | 
			
		||||
				Value:   "alr.sh",
 | 
			
		||||
				Usage:   gotext.Get("Path to the build script"),
 | 
			
		||||
			},
 | 
			
		||||
			&cli.StringFlag{
 | 
			
		||||
				Name:    "package",
 | 
			
		||||
				Aliases: []string{"p"},
 | 
			
		||||
				Usage:   gotext.Get("Name of the package to build and its repo (example: default/go-bin)"),
 | 
			
		||||
			},
 | 
			
		||||
			&cli.BoolFlag{
 | 
			
		||||
				Name:    "clean",
 | 
			
		||||
				Aliases: []string{"c"},
 | 
			
		||||
				Usage:   gotext.Get("Build package from scratch even if there's an already built package available"),
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		&cli.StringFlag{
 | 
			
		||||
			Name:    "package",
 | 
			
		||||
			Aliases: []string{"p"},
 | 
			
		||||
			Usage:   "Name of the package to build and its repo (example: default/go-bin)",
 | 
			
		||||
		},
 | 
			
		||||
		&cli.BoolFlag{
 | 
			
		||||
			Name:    "clean",
 | 
			
		||||
			Aliases: []string{"c"},
 | 
			
		||||
			Usage:   "Build package from scratch even if there's an already built package available",
 | 
			
		||||
		},
 | 
			
		||||
	},
 | 
			
		||||
	Action: func(c *cli.Context) error {
 | 
			
		||||
		ctx := c.Context
 | 
			
		||||
		Action: func(c *cli.Context) error {
 | 
			
		||||
			ctx := c.Context
 | 
			
		||||
 | 
			
		||||
		script := c.String("script")
 | 
			
		||||
		if c.String("package") != "" {
 | 
			
		||||
			script = filepath.Join(config.GetPaths(ctx).RepoDir, c.String("package"), "alr.sh")
 | 
			
		||||
		}
 | 
			
		||||
			script := c.String("script")
 | 
			
		||||
			if c.String("package") != "" {
 | 
			
		||||
				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)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		mgr := manager.Detect()
 | 
			
		||||
		if mgr == nil {
 | 
			
		||||
			slog.Error(gotext.Get("Unable to detect a supported package manager on the system"))
 | 
			
		||||
			os.Exit(1)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		pkgPaths, _, err := build.BuildPackage(ctx, types.BuildOpts{
 | 
			
		||||
			Script:      script,
 | 
			
		||||
			Manager:     mgr,
 | 
			
		||||
			Clean:       c.Bool("clean"),
 | 
			
		||||
			Interactive: c.Bool("interactive"),
 | 
			
		||||
		})
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			slog.Error(gotext.Get("Error building package"), "err", err)
 | 
			
		||||
			os.Exit(1)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		wd, err := os.Getwd()
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			slog.Error(gotext.Get("Error getting working directory"), "err", err)
 | 
			
		||||
			os.Exit(1)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		for _, pkgPath := range pkgPaths {
 | 
			
		||||
			name := filepath.Base(pkgPath)
 | 
			
		||||
			err = osutils.Move(pkgPath, filepath.Join(wd, name))
 | 
			
		||||
			err := repos.Pull(ctx, config.Config(ctx).Repos)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				slog.Error(gotext.Get("Error moving the package"), "err", err)
 | 
			
		||||
				slog.Error(gotext.Get("Error pulling repositories"), "err", err)
 | 
			
		||||
				os.Exit(1)
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return nil
 | 
			
		||||
	},
 | 
			
		||||
			mgr := manager.Detect()
 | 
			
		||||
			if mgr == nil {
 | 
			
		||||
				slog.Error(gotext.Get("Unable to detect a supported package manager on the system"))
 | 
			
		||||
				os.Exit(1)
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			pkgPaths, _, err := build.BuildPackage(ctx, types.BuildOpts{
 | 
			
		||||
				Script:      script,
 | 
			
		||||
				Manager:     mgr,
 | 
			
		||||
				Clean:       c.Bool("clean"),
 | 
			
		||||
				Interactive: c.Bool("interactive"),
 | 
			
		||||
			})
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				slog.Error(gotext.Get("Error building package"), "err", err)
 | 
			
		||||
				os.Exit(1)
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			wd, err := os.Getwd()
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				slog.Error(gotext.Get("Error getting working directory"), "err", err)
 | 
			
		||||
				os.Exit(1)
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			for _, pkgPath := range pkgPaths {
 | 
			
		||||
				name := filepath.Base(pkgPath)
 | 
			
		||||
				err = osutils.Move(pkgPath, filepath.Join(wd, name))
 | 
			
		||||
				if err != nil {
 | 
			
		||||
					slog.Error(gotext.Get("Error moving the package"), "err", err)
 | 
			
		||||
					os.Exit(1)
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			return nil
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										56
									
								
								fix.go
									
									
									
									
									
								
							
							
						
						
									
										56
									
								
								fix.go
									
									
									
									
									
								
							@@ -31,39 +31,41 @@ import (
 | 
			
		||||
	"gitea.plemya-x.ru/Plemya-x/ALR/pkg/repos"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var fixCmd = &cli.Command{
 | 
			
		||||
	Name:  "fix",
 | 
			
		||||
	Usage: "Attempt to fix problems with ALR",
 | 
			
		||||
	Action: func(c *cli.Context) error {
 | 
			
		||||
		ctx := c.Context
 | 
			
		||||
func FixCmd() *cli.Command {
 | 
			
		||||
	return &cli.Command{
 | 
			
		||||
		Name:  "fix",
 | 
			
		||||
		Usage: gotext.Get("Attempt to fix problems with ALR"),
 | 
			
		||||
		Action: func(c *cli.Context) error {
 | 
			
		||||
			ctx := c.Context
 | 
			
		||||
 | 
			
		||||
		db.Close()
 | 
			
		||||
		paths := config.GetPaths(ctx)
 | 
			
		||||
			db.Close()
 | 
			
		||||
			paths := config.GetPaths(ctx)
 | 
			
		||||
 | 
			
		||||
		slog.Info(gotext.Get("Removing cache directory"))
 | 
			
		||||
			slog.Info(gotext.Get("Removing cache directory"))
 | 
			
		||||
 | 
			
		||||
		err := os.RemoveAll(paths.CacheDir)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			slog.Error(gotext.Get("Unable to remove cache directory"), "err", err)
 | 
			
		||||
			os.Exit(1)
 | 
			
		||||
		}
 | 
			
		||||
			err := os.RemoveAll(paths.CacheDir)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				slog.Error(gotext.Get("Unable to remove cache directory"), "err", err)
 | 
			
		||||
				os.Exit(1)
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
		slog.Info(gotext.Get("Rebuilding cache"))
 | 
			
		||||
			slog.Info(gotext.Get("Rebuilding cache"))
 | 
			
		||||
 | 
			
		||||
		err = os.MkdirAll(paths.CacheDir, 0o755)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			slog.Error(gotext.Get("Unable to create new cache directory"), "err", err)
 | 
			
		||||
			os.Exit(1)
 | 
			
		||||
		}
 | 
			
		||||
			err = os.MkdirAll(paths.CacheDir, 0o755)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				slog.Error(gotext.Get("Unable to create new cache directory"), "err", err)
 | 
			
		||||
				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)
 | 
			
		||||
		}
 | 
			
		||||
			err = repos.Pull(ctx, config.Config(ctx).Repos)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				slog.Error(gotext.Get("Error pulling repos"), "err", err)
 | 
			
		||||
				os.Exit(1)
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
		slog.Info(gotext.Get("Done"))
 | 
			
		||||
			slog.Info(gotext.Get("Done"))
 | 
			
		||||
 | 
			
		||||
		return nil
 | 
			
		||||
	},
 | 
			
		||||
			return nil
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										71
									
								
								gen.go
									
									
									
									
									
								
							
							
						
						
									
										71
									
								
								gen.go
									
									
									
									
									
								
							@@ -22,44 +22,45 @@ package main
 | 
			
		||||
import (
 | 
			
		||||
	"os"
 | 
			
		||||
 | 
			
		||||
	"github.com/leonelquinteros/gotext"
 | 
			
		||||
	"github.com/urfave/cli/v2"
 | 
			
		||||
 | 
			
		||||
	"gitea.plemya-x.ru/Plemya-x/ALR/pkg/gen"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var genCmd = &cli.Command{
 | 
			
		||||
	Name:    "generate",
 | 
			
		||||
	Usage:   "Generate a ALR script from a template",
 | 
			
		||||
	Aliases: []string{"gen"},
 | 
			
		||||
	Subcommands: []*cli.Command{
 | 
			
		||||
		genPipCmd,
 | 
			
		||||
	},
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var genPipCmd = &cli.Command{
 | 
			
		||||
	Name:  "pip",
 | 
			
		||||
	Usage: "Generate a ALR script for a pip module",
 | 
			
		||||
	Flags: []cli.Flag{
 | 
			
		||||
		&cli.StringFlag{
 | 
			
		||||
			Name:     "name",
 | 
			
		||||
			Aliases:  []string{"n"},
 | 
			
		||||
			Required: true,
 | 
			
		||||
		},
 | 
			
		||||
		&cli.StringFlag{
 | 
			
		||||
			Name:     "version",
 | 
			
		||||
			Aliases:  []string{"v"},
 | 
			
		||||
			Required: true,
 | 
			
		||||
		},
 | 
			
		||||
		&cli.StringFlag{
 | 
			
		||||
			Name:    "description",
 | 
			
		||||
			Aliases: []string{"d"},
 | 
			
		||||
		},
 | 
			
		||||
	},
 | 
			
		||||
	Action: func(c *cli.Context) error {
 | 
			
		||||
		return gen.Pip(os.Stdout, gen.PipOptions{
 | 
			
		||||
			Name:        c.String("name"),
 | 
			
		||||
			Version:     c.String("version"),
 | 
			
		||||
			Description: c.String("description"),
 | 
			
		||||
		})
 | 
			
		||||
	},
 | 
			
		||||
func GenCmd() *cli.Command {
 | 
			
		||||
	return &cli.Command{
 | 
			
		||||
		Name:    "generate",
 | 
			
		||||
		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{
 | 
			
		||||
					&cli.StringFlag{
 | 
			
		||||
						Name:     "name",
 | 
			
		||||
						Aliases:  []string{"n"},
 | 
			
		||||
						Required: true,
 | 
			
		||||
					},
 | 
			
		||||
					&cli.StringFlag{
 | 
			
		||||
						Name:     "version",
 | 
			
		||||
						Aliases:  []string{"v"},
 | 
			
		||||
						Required: true,
 | 
			
		||||
					},
 | 
			
		||||
					&cli.StringFlag{
 | 
			
		||||
						Name:    "description",
 | 
			
		||||
						Aliases: []string{"d"},
 | 
			
		||||
					},
 | 
			
		||||
				},
 | 
			
		||||
				Action: func(c *cli.Context) error {
 | 
			
		||||
					return gen.Pip(os.Stdout, gen.PipOptions{
 | 
			
		||||
						Name:        c.String("name"),
 | 
			
		||||
						Version:     c.String("version"),
 | 
			
		||||
						Description: c.String("description"),
 | 
			
		||||
					})
 | 
			
		||||
				},
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										130
									
								
								helper.go
									
									
									
									
									
								
							
							
						
						
									
										130
									
								
								helper.go
									
									
									
									
									
								
							@@ -35,75 +35,77 @@ import (
 | 
			
		||||
	"gitea.plemya-x.ru/Plemya-x/ALR/pkg/distro"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var helperCmd = &cli.Command{
 | 
			
		||||
	Name:        "helper",
 | 
			
		||||
	Usage:       "Run a ALR helper command",
 | 
			
		||||
	ArgsUsage:   `<helper_name|"list">`,
 | 
			
		||||
	Subcommands: []*cli.Command{helperListCmd},
 | 
			
		||||
	Flags: []cli.Flag{
 | 
			
		||||
		&cli.StringFlag{
 | 
			
		||||
			Name:    "dest-dir",
 | 
			
		||||
			Aliases: []string{"d"},
 | 
			
		||||
			Usage:   "The directory that the install commands will install to",
 | 
			
		||||
			Value:   "dest",
 | 
			
		||||
func HelperCmd() *cli.Command {
 | 
			
		||||
	var helperListCmd = &cli.Command{
 | 
			
		||||
		Name:    "list",
 | 
			
		||||
		Usage:   gotext.Get("List all the available helper commands"),
 | 
			
		||||
		Aliases: []string{"ls"},
 | 
			
		||||
		Action: func(ctx *cli.Context) error {
 | 
			
		||||
			for name := range helpers.Helpers {
 | 
			
		||||
				fmt.Println(name)
 | 
			
		||||
			}
 | 
			
		||||
			return nil
 | 
			
		||||
		},
 | 
			
		||||
	},
 | 
			
		||||
	Action: func(c *cli.Context) error {
 | 
			
		||||
		ctx := c.Context
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
		if c.Args().Len() < 1 {
 | 
			
		||||
			cli.ShowSubcommandHelpAndExit(c, 1)
 | 
			
		||||
		}
 | 
			
		||||
	return &cli.Command{
 | 
			
		||||
		Name:        "helper",
 | 
			
		||||
		Usage:       gotext.Get("Run a ALR helper command"),
 | 
			
		||||
		ArgsUsage:   `<helper_name|"list">`,
 | 
			
		||||
		Subcommands: []*cli.Command{helperListCmd},
 | 
			
		||||
		Flags: []cli.Flag{
 | 
			
		||||
			&cli.StringFlag{
 | 
			
		||||
				Name:    "dest-dir",
 | 
			
		||||
				Aliases: []string{"d"},
 | 
			
		||||
				Usage:   gotext.Get("The directory that the install commands will install to"),
 | 
			
		||||
				Value:   "dest",
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		Action: func(c *cli.Context) error {
 | 
			
		||||
			ctx := c.Context
 | 
			
		||||
 | 
			
		||||
		helper, ok := helpers.Helpers[c.Args().First()]
 | 
			
		||||
		if !ok {
 | 
			
		||||
			slog.Error(gotext.Get("No such helper command"), "name", c.Args().First())
 | 
			
		||||
			os.Exit(1)
 | 
			
		||||
		}
 | 
			
		||||
			if c.Args().Len() < 1 {
 | 
			
		||||
				cli.ShowSubcommandHelpAndExit(c, 1)
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
		wd, err := os.Getwd()
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			slog.Error(gotext.Get("Error getting working directory"), "err", err)
 | 
			
		||||
			os.Exit(1)
 | 
			
		||||
		}
 | 
			
		||||
			helper, ok := helpers.Helpers[c.Args().First()]
 | 
			
		||||
			if !ok {
 | 
			
		||||
				slog.Error(gotext.Get("No such helper command"), "name", c.Args().First())
 | 
			
		||||
				os.Exit(1)
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
		info, err := distro.ParseOSRelease(ctx)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			slog.Error(gotext.Get("Error getting working directory"), "err", err)
 | 
			
		||||
			os.Exit(1)
 | 
			
		||||
		}
 | 
			
		||||
			wd, err := os.Getwd()
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				slog.Error(gotext.Get("Error getting working directory"), "err", err)
 | 
			
		||||
				os.Exit(1)
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
		hc := interp.HandlerContext{
 | 
			
		||||
			Env: expand.ListEnviron(
 | 
			
		||||
				"pkgdir="+c.String("dest-dir"),
 | 
			
		||||
				"DISTRO_ID="+info.ID,
 | 
			
		||||
				"DISTRO_ID_LIKE="+strings.Join(info.Like, " "),
 | 
			
		||||
				"ARCH="+cpu.Arch(),
 | 
			
		||||
			),
 | 
			
		||||
			Dir:    wd,
 | 
			
		||||
			Stdin:  os.Stdin,
 | 
			
		||||
			Stdout: os.Stdout,
 | 
			
		||||
			Stderr: os.Stderr,
 | 
			
		||||
		}
 | 
			
		||||
			info, err := distro.ParseOSRelease(ctx)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				slog.Error(gotext.Get("Error getting working directory"), "err", err)
 | 
			
		||||
				os.Exit(1)
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
		return helper(hc, c.Args().First(), c.Args().Slice()[1:])
 | 
			
		||||
	},
 | 
			
		||||
	CustomHelpTemplate: cli.CommandHelpTemplate,
 | 
			
		||||
	BashComplete: func(ctx *cli.Context) {
 | 
			
		||||
		for name := range helpers.Helpers {
 | 
			
		||||
			fmt.Println(name)
 | 
			
		||||
		}
 | 
			
		||||
	},
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var helperListCmd = &cli.Command{
 | 
			
		||||
	Name:    "list",
 | 
			
		||||
	Usage:   "List all the available helper commands",
 | 
			
		||||
	Aliases: []string{"ls"},
 | 
			
		||||
	Action: func(ctx *cli.Context) error {
 | 
			
		||||
		for name := range helpers.Helpers {
 | 
			
		||||
			fmt.Println(name)
 | 
			
		||||
		}
 | 
			
		||||
		return nil
 | 
			
		||||
	},
 | 
			
		||||
			hc := interp.HandlerContext{
 | 
			
		||||
				Env: expand.ListEnviron(
 | 
			
		||||
					"pkgdir="+c.String("dest-dir"),
 | 
			
		||||
					"DISTRO_ID="+info.ID,
 | 
			
		||||
					"DISTRO_ID_LIKE="+strings.Join(info.Like, " "),
 | 
			
		||||
					"ARCH="+cpu.Arch(),
 | 
			
		||||
				),
 | 
			
		||||
				Dir:    wd,
 | 
			
		||||
				Stdin:  os.Stdin,
 | 
			
		||||
				Stdout: os.Stdout,
 | 
			
		||||
				Stderr: os.Stderr,
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			return helper(hc, c.Args().First(), c.Args().Slice()[1:])
 | 
			
		||||
		},
 | 
			
		||||
		CustomHelpTemplate: cli.CommandHelpTemplate,
 | 
			
		||||
		BashComplete: func(ctx *cli.Context) {
 | 
			
		||||
			for name := range helpers.Helpers {
 | 
			
		||||
				fmt.Println(name)
 | 
			
		||||
			}
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2
									
								
								info.go
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								info.go
									
									
									
									
									
								
							@@ -36,7 +36,7 @@ import (
 | 
			
		||||
	"gitea.plemya-x.ru/Plemya-x/ALR/pkg/repos"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func GetInfoCmd() *cli.Command {
 | 
			
		||||
func InfoCmd() *cli.Command {
 | 
			
		||||
	return &cli.Command{
 | 
			
		||||
		Name:  "info",
 | 
			
		||||
		Usage: gotext.Get("Print information about a package"),
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										169
									
								
								install.go
									
									
									
									
									
								
							
							
						
						
									
										169
									
								
								install.go
									
									
									
									
									
								
							@@ -36,96 +36,101 @@ import (
 | 
			
		||||
	"gitea.plemya-x.ru/Plemya-x/ALR/pkg/repos"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var installCmd = &cli.Command{
 | 
			
		||||
	Name:    "install",
 | 
			
		||||
	Usage:   "Install a new package",
 | 
			
		||||
	Aliases: []string{"in"},
 | 
			
		||||
	Flags: []cli.Flag{
 | 
			
		||||
		&cli.BoolFlag{
 | 
			
		||||
			Name:    "clean",
 | 
			
		||||
			Aliases: []string{"c"},
 | 
			
		||||
			Usage:   "Build package from scratch even if there's an already built package available",
 | 
			
		||||
func InstallCmd() *cli.Command {
 | 
			
		||||
 | 
			
		||||
	return &cli.Command{
 | 
			
		||||
		Name:    "install",
 | 
			
		||||
		Usage:   gotext.Get("Install a new package"),
 | 
			
		||||
		Aliases: []string{"in"},
 | 
			
		||||
		Flags: []cli.Flag{
 | 
			
		||||
			&cli.BoolFlag{
 | 
			
		||||
				Name:    "clean",
 | 
			
		||||
				Aliases: []string{"c"},
 | 
			
		||||
				Usage:   "Build package from scratch even if there's an already built package available",
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
	},
 | 
			
		||||
	Action: func(c *cli.Context) error {
 | 
			
		||||
		ctx := c.Context
 | 
			
		||||
		Action: func(c *cli.Context) error {
 | 
			
		||||
			ctx := c.Context
 | 
			
		||||
 | 
			
		||||
		args := c.Args()
 | 
			
		||||
		if args.Len() < 1 {
 | 
			
		||||
			slog.Error(gotext.Get("Command install expected at least 1 argument, got %d", args.Len()))
 | 
			
		||||
			os.Exit(1)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		mgr := manager.Detect()
 | 
			
		||||
		if mgr == nil {
 | 
			
		||||
			slog.Error(gotext.Get("Unable to detect a supported package manager on the system"))
 | 
			
		||||
			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)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		found, notFound, err := repos.FindPkgs(ctx, args.Slice())
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			slog.Error(gotext.Get("Error finding packages"), "err", err)
 | 
			
		||||
			os.Exit(1)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		pkgs := cliutils.FlattenPkgs(ctx, found, "install", c.Bool("interactive"))
 | 
			
		||||
		build.InstallPkgs(ctx, pkgs, notFound, types.BuildOpts{
 | 
			
		||||
			Manager:     mgr,
 | 
			
		||||
			Clean:       c.Bool("clean"),
 | 
			
		||||
			Interactive: c.Bool("interactive"),
 | 
			
		||||
		})
 | 
			
		||||
		return nil
 | 
			
		||||
	},
 | 
			
		||||
	BashComplete: func(c *cli.Context) {
 | 
			
		||||
		result, err := db.GetPkgs(c.Context, "true")
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			slog.Error(gotext.Get("Error getting packages"), "err", err)
 | 
			
		||||
			os.Exit(1)
 | 
			
		||||
		}
 | 
			
		||||
		defer result.Close()
 | 
			
		||||
 | 
			
		||||
		for result.Next() {
 | 
			
		||||
			var pkg db.Package
 | 
			
		||||
			err = result.StructScan(&pkg)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				slog.Error(gotext.Get("Error iterating over packages"), "err", err)
 | 
			
		||||
			args := c.Args()
 | 
			
		||||
			if args.Len() < 1 {
 | 
			
		||||
				slog.Error(gotext.Get("Command install expected at least 1 argument, got %d", args.Len()))
 | 
			
		||||
				os.Exit(1)
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			fmt.Println(pkg.Name)
 | 
			
		||||
		}
 | 
			
		||||
	},
 | 
			
		||||
			mgr := manager.Detect()
 | 
			
		||||
			if mgr == nil {
 | 
			
		||||
				slog.Error(gotext.Get("Unable to detect a supported package manager on the system"))
 | 
			
		||||
				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)
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			found, notFound, err := repos.FindPkgs(ctx, args.Slice())
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				slog.Error(gotext.Get("Error finding packages"), "err", err)
 | 
			
		||||
				os.Exit(1)
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			pkgs := cliutils.FlattenPkgs(ctx, found, "install", c.Bool("interactive"))
 | 
			
		||||
			build.InstallPkgs(ctx, pkgs, notFound, types.BuildOpts{
 | 
			
		||||
				Manager:     mgr,
 | 
			
		||||
				Clean:       c.Bool("clean"),
 | 
			
		||||
				Interactive: c.Bool("interactive"),
 | 
			
		||||
			})
 | 
			
		||||
			return nil
 | 
			
		||||
		},
 | 
			
		||||
		BashComplete: func(c *cli.Context) {
 | 
			
		||||
			result, err := db.GetPkgs(c.Context, "true")
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				slog.Error(gotext.Get("Error getting packages"), "err", err)
 | 
			
		||||
				os.Exit(1)
 | 
			
		||||
			}
 | 
			
		||||
			defer result.Close()
 | 
			
		||||
 | 
			
		||||
			for result.Next() {
 | 
			
		||||
				var pkg db.Package
 | 
			
		||||
				err = result.StructScan(&pkg)
 | 
			
		||||
				if err != nil {
 | 
			
		||||
					slog.Error(gotext.Get("Error iterating over packages"), "err", err)
 | 
			
		||||
					os.Exit(1)
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				fmt.Println(pkg.Name)
 | 
			
		||||
			}
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var removeCmd = &cli.Command{
 | 
			
		||||
	Name:    "remove",
 | 
			
		||||
	Usage:   "Remove an installed package",
 | 
			
		||||
	Aliases: []string{"rm"},
 | 
			
		||||
	Action: func(c *cli.Context) error {
 | 
			
		||||
		args := c.Args()
 | 
			
		||||
		if args.Len() < 1 {
 | 
			
		||||
			slog.Error(gotext.Get("Command remove expected at least 1 argument, got %d", args.Len()))
 | 
			
		||||
			os.Exit(1)
 | 
			
		||||
		}
 | 
			
		||||
func RemoveCmd() *cli.Command {
 | 
			
		||||
	return &cli.Command{
 | 
			
		||||
		Name:    "remove",
 | 
			
		||||
		Usage:   gotext.Get("Remove an installed package"),
 | 
			
		||||
		Aliases: []string{"rm"},
 | 
			
		||||
		Action: func(c *cli.Context) error {
 | 
			
		||||
			args := c.Args()
 | 
			
		||||
			if args.Len() < 1 {
 | 
			
		||||
				slog.Error(gotext.Get("Command remove expected at least 1 argument, got %d", args.Len()))
 | 
			
		||||
				os.Exit(1)
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
		mgr := manager.Detect()
 | 
			
		||||
		if mgr == nil {
 | 
			
		||||
			slog.Error(gotext.Get("Unable to detect a supported package manager on the system"))
 | 
			
		||||
			os.Exit(1)
 | 
			
		||||
		}
 | 
			
		||||
			mgr := manager.Detect()
 | 
			
		||||
			if mgr == nil {
 | 
			
		||||
				slog.Error(gotext.Get("Unable to detect a supported package manager on the system"))
 | 
			
		||||
				os.Exit(1)
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
		err := mgr.Remove(nil, c.Args().Slice()...)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			slog.Error(gotext.Get("Error removing packages"), "err", err)
 | 
			
		||||
			os.Exit(1)
 | 
			
		||||
		}
 | 
			
		||||
			err := mgr.Remove(nil, c.Args().Slice()...)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				slog.Error(gotext.Get("Error removing packages"), "err", err)
 | 
			
		||||
				os.Exit(1)
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
		return nil
 | 
			
		||||
	},
 | 
			
		||||
			return nil
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -9,51 +9,92 @@ msgstr ""
 | 
			
		||||
"Content-Transfer-Encoding: 8bit\n"
 | 
			
		||||
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
 | 
			
		||||
 | 
			
		||||
#: build.go:69
 | 
			
		||||
#: build.go:41
 | 
			
		||||
msgid "Build a local package"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: build.go:47
 | 
			
		||||
msgid "Path to the build script"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: build.go:52
 | 
			
		||||
msgid "Name of the package to build and its repo (example: default/go-bin)"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: build.go:57
 | 
			
		||||
msgid ""
 | 
			
		||||
"Build package from scratch even if there's an already built package available"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: build.go:70
 | 
			
		||||
msgid "Error pulling repositories"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: build.go:75
 | 
			
		||||
#: build.go:76
 | 
			
		||||
msgid "Unable to detect a supported package manager on the system"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: build.go:86
 | 
			
		||||
#: build.go:87
 | 
			
		||||
msgid "Error building package"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: build.go:92
 | 
			
		||||
#: build.go:93
 | 
			
		||||
msgid "Error getting working directory"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: build.go:100
 | 
			
		||||
#: build.go:101
 | 
			
		||||
msgid "Error moving the package"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: fix.go:43
 | 
			
		||||
#: fix.go:37
 | 
			
		||||
msgid "Attempt to fix problems with ALR"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: fix.go:44
 | 
			
		||||
msgid "Removing cache directory"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: fix.go:47
 | 
			
		||||
#: fix.go:48
 | 
			
		||||
msgid "Unable to remove cache directory"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: fix.go:51
 | 
			
		||||
#: fix.go:52
 | 
			
		||||
msgid "Rebuilding cache"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: fix.go:55
 | 
			
		||||
#: fix.go:56
 | 
			
		||||
msgid "Unable to create new cache directory"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: fix.go:61
 | 
			
		||||
#: fix.go:62
 | 
			
		||||
msgid "Error pulling repos"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: fix.go:65
 | 
			
		||||
#: fix.go:66
 | 
			
		||||
msgid "Done"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: gen.go:34
 | 
			
		||||
msgid "Generate a ALR script from a template"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: gen.go:39
 | 
			
		||||
msgid "Generate a ALR script for a pip module"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: helper.go:41
 | 
			
		||||
msgid "List all the available helper commands"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: helper.go:53
 | 
			
		||||
msgid "Run a ALR helper command"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: helper.go:60
 | 
			
		||||
msgid "The directory that the install commands will install to"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: helper.go:73
 | 
			
		||||
msgid "No such helper command"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
@@ -85,23 +126,27 @@ msgstr ""
 | 
			
		||||
msgid "Error encoding script variables"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: install.go:55
 | 
			
		||||
#: install.go:57
 | 
			
		||||
msgid "Command install expected at least 1 argument, got %d"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: install.go:88
 | 
			
		||||
#: install.go:90
 | 
			
		||||
msgid "Error getting packages"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: install.go:97
 | 
			
		||||
#: install.go:99
 | 
			
		||||
msgid "Error iterating over packages"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: install.go:113
 | 
			
		||||
#: install.go:112
 | 
			
		||||
msgid "Remove an installed package"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: install.go:117
 | 
			
		||||
msgid "Command remove expected at least 1 argument, got %d"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: install.go:125
 | 
			
		||||
#: install.go:129
 | 
			
		||||
msgid "Error removing packages"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
@@ -202,21 +247,37 @@ msgstr ""
 | 
			
		||||
msgid "ERROR"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: list.go:53
 | 
			
		||||
#: list.go:40
 | 
			
		||||
msgid "List ALR repo packages"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: list.go:54
 | 
			
		||||
msgid "Error initialization database"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: list.go:87
 | 
			
		||||
#: list.go:88
 | 
			
		||||
msgid "Error listing installed packages"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: main.go:88
 | 
			
		||||
#: main.go:45
 | 
			
		||||
msgid "Print the current ALR version and exit"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: main.go:61
 | 
			
		||||
msgid "Arguments to be passed on to the package manager"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: main.go:67
 | 
			
		||||
msgid "Enable interactive questions and prompts"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: main.go:90
 | 
			
		||||
msgid ""
 | 
			
		||||
"Running ALR as root is forbidden as it may cause catastrophic damage to your "
 | 
			
		||||
"system"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: main.go:122
 | 
			
		||||
#: main.go:124
 | 
			
		||||
msgid "Error while running app"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
@@ -328,26 +389,54 @@ msgid ""
 | 
			
		||||
"updating ALR if something doesn't work."
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: repo.go:78 repo.go:133
 | 
			
		||||
#: repo.go:41
 | 
			
		||||
msgid "Add a new repository"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: repo.go:48
 | 
			
		||||
msgid "Name of the new repo"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: repo.go:54
 | 
			
		||||
msgid "URL of the new repo"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: repo.go:79 repo.go:136
 | 
			
		||||
msgid "Error opening config file"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: repo.go:84 repo.go:139
 | 
			
		||||
#: repo.go:85 repo.go:142
 | 
			
		||||
msgid "Error encoding config"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: repo.go:125
 | 
			
		||||
#: repo.go:103
 | 
			
		||||
msgid "Remove an existing repository"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: repo.go:110
 | 
			
		||||
msgid "Name of the repo to be deleted"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: repo.go:128
 | 
			
		||||
msgid "Repo does not exist"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: repo.go:145
 | 
			
		||||
#: repo.go:148
 | 
			
		||||
msgid "Error removing repo directory"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: repo.go:151
 | 
			
		||||
#: repo.go:154
 | 
			
		||||
msgid "Error removing packages from database"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: upgrade.go:78
 | 
			
		||||
#: repo.go:166
 | 
			
		||||
msgid "Pull all repositories that have changed"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: upgrade.go:47
 | 
			
		||||
msgid "Upgrade all installed packages"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: upgrade.go:79
 | 
			
		||||
msgid "Error checking for updates"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 
 | 
			
		||||
@@ -11,55 +11,98 @@ msgstr ""
 | 
			
		||||
"MIME-Version: 1.0\n"
 | 
			
		||||
"Content-Type: text/plain; charset=UTF-8\n"
 | 
			
		||||
"Content-Transfer-Encoding: 8bit\n"
 | 
			
		||||
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && "
 | 
			
		||||
"n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
 | 
			
		||||
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n"
 | 
			
		||||
"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
 | 
			
		||||
"X-Generator: Gtranslator 47.1\n"
 | 
			
		||||
 | 
			
		||||
#: build.go:69
 | 
			
		||||
#: build.go:41
 | 
			
		||||
#, fuzzy
 | 
			
		||||
msgid "Build a local package"
 | 
			
		||||
msgstr "Сборка пакета"
 | 
			
		||||
 | 
			
		||||
#: build.go:47
 | 
			
		||||
#, fuzzy
 | 
			
		||||
msgid "Path to the build script"
 | 
			
		||||
msgstr "Не удалось предложить просмотреть скрипт"
 | 
			
		||||
 | 
			
		||||
#: build.go:52
 | 
			
		||||
msgid "Name of the package to build and its repo (example: default/go-bin)"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: build.go:57
 | 
			
		||||
msgid ""
 | 
			
		||||
"Build package from scratch even if there's an already built package available"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: build.go:70
 | 
			
		||||
msgid "Error pulling repositories"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: build.go:75
 | 
			
		||||
#: build.go:76
 | 
			
		||||
msgid "Unable to detect a supported package manager on the system"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: build.go:86
 | 
			
		||||
#: build.go:87
 | 
			
		||||
msgid "Error building package"
 | 
			
		||||
msgstr "Ошибка при сборке пакета"
 | 
			
		||||
 | 
			
		||||
#: build.go:92
 | 
			
		||||
#: build.go:93
 | 
			
		||||
msgid "Error getting working directory"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: build.go:100
 | 
			
		||||
#: build.go:101
 | 
			
		||||
msgid "Error moving the package"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: fix.go:43
 | 
			
		||||
#: fix.go:37
 | 
			
		||||
msgid "Attempt to fix problems with ALR"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: fix.go:44
 | 
			
		||||
msgid "Removing cache directory"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: fix.go:47
 | 
			
		||||
#: fix.go:48
 | 
			
		||||
msgid "Unable to remove cache directory"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: fix.go:51
 | 
			
		||||
#: fix.go:52
 | 
			
		||||
msgid "Rebuilding cache"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: fix.go:55
 | 
			
		||||
#: fix.go:56
 | 
			
		||||
msgid "Unable to create new cache directory"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: fix.go:61
 | 
			
		||||
#: fix.go:62
 | 
			
		||||
msgid "Error pulling repos"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: fix.go:65
 | 
			
		||||
#: fix.go:66
 | 
			
		||||
msgid "Done"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: gen.go:34
 | 
			
		||||
msgid "Generate a ALR script from a template"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: gen.go:39
 | 
			
		||||
msgid "Generate a ALR script for a pip module"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: helper.go:41
 | 
			
		||||
msgid "List all the available helper commands"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: helper.go:53
 | 
			
		||||
msgid "Run a ALR helper command"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: helper.go:60
 | 
			
		||||
msgid "The directory that the install commands will install to"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: helper.go:73
 | 
			
		||||
msgid "No such helper command"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
@@ -91,23 +134,27 @@ msgstr ""
 | 
			
		||||
msgid "Error encoding script variables"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: install.go:55
 | 
			
		||||
#: install.go:57
 | 
			
		||||
msgid "Command install expected at least 1 argument, got %d"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: install.go:88
 | 
			
		||||
#: install.go:90
 | 
			
		||||
msgid "Error getting packages"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: install.go:97
 | 
			
		||||
#: install.go:99
 | 
			
		||||
msgid "Error iterating over packages"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: install.go:113
 | 
			
		||||
#: install.go:112
 | 
			
		||||
msgid "Remove an installed package"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: install.go:117
 | 
			
		||||
msgid "Command remove expected at least 1 argument, got %d"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: install.go:125
 | 
			
		||||
#: install.go:129
 | 
			
		||||
msgid "Error removing packages"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
@@ -208,21 +255,37 @@ msgstr "Скачивание источника"
 | 
			
		||||
msgid "ERROR"
 | 
			
		||||
msgstr "ОШИБКА"
 | 
			
		||||
 | 
			
		||||
#: list.go:53
 | 
			
		||||
#: list.go:40
 | 
			
		||||
msgid "List ALR repo packages"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: list.go:54
 | 
			
		||||
msgid "Error initialization database"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: list.go:87
 | 
			
		||||
#: list.go:88
 | 
			
		||||
msgid "Error listing installed packages"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: main.go:88
 | 
			
		||||
#: main.go:45
 | 
			
		||||
msgid "Print the current ALR version and exit"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: main.go:61
 | 
			
		||||
msgid "Arguments to be passed on to the package manager"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: main.go:67
 | 
			
		||||
msgid "Enable interactive questions and prompts"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: main.go:90
 | 
			
		||||
msgid ""
 | 
			
		||||
"Running ALR as root is forbidden as it may cause catastrophic damage to your "
 | 
			
		||||
"system"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: main.go:122
 | 
			
		||||
#: main.go:124
 | 
			
		||||
msgid "Error while running app"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
@@ -334,26 +397,55 @@ msgid ""
 | 
			
		||||
"updating ALR if something doesn't work."
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: repo.go:78 repo.go:133
 | 
			
		||||
#: repo.go:41
 | 
			
		||||
#, fuzzy
 | 
			
		||||
msgid "Add a new repository"
 | 
			
		||||
msgstr "Скачивание репозитория"
 | 
			
		||||
 | 
			
		||||
#: repo.go:48
 | 
			
		||||
msgid "Name of the new repo"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: repo.go:54
 | 
			
		||||
msgid "URL of the new repo"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: repo.go:79 repo.go:136
 | 
			
		||||
msgid "Error opening config file"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: repo.go:84 repo.go:139
 | 
			
		||||
#: repo.go:85 repo.go:142
 | 
			
		||||
msgid "Error encoding config"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: repo.go:125
 | 
			
		||||
#: repo.go:103
 | 
			
		||||
msgid "Remove an existing repository"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: repo.go:110
 | 
			
		||||
msgid "Name of the repo to be deleted"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: repo.go:128
 | 
			
		||||
msgid "Repo does not exist"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: repo.go:145
 | 
			
		||||
#: repo.go:148
 | 
			
		||||
msgid "Error removing repo directory"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: repo.go:151
 | 
			
		||||
#: repo.go:154
 | 
			
		||||
msgid "Error removing packages from database"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: upgrade.go:78
 | 
			
		||||
#: repo.go:166
 | 
			
		||||
msgid "Pull all repositories that have changed"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: upgrade.go:47
 | 
			
		||||
msgid "Upgrade all installed packages"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: upgrade.go:79
 | 
			
		||||
msgid "Error checking for updates"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										146
									
								
								list.go
									
									
									
									
									
								
							
							
						
						
									
										146
									
								
								list.go
									
									
									
									
									
								
							@@ -34,90 +34,92 @@ import (
 | 
			
		||||
	"gitea.plemya-x.ru/Plemya-x/ALR/pkg/repos"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var listCmd = &cli.Command{
 | 
			
		||||
	Name:    "list",
 | 
			
		||||
	Usage:   "List ALR repo packages",
 | 
			
		||||
	Aliases: []string{"ls"},
 | 
			
		||||
	Flags: []cli.Flag{
 | 
			
		||||
		&cli.BoolFlag{
 | 
			
		||||
			Name:    "installed",
 | 
			
		||||
			Aliases: []string{"I"},
 | 
			
		||||
func ListCmd() *cli.Command {
 | 
			
		||||
	return &cli.Command{
 | 
			
		||||
		Name:    "list",
 | 
			
		||||
		Usage:   gotext.Get("List ALR repo packages"),
 | 
			
		||||
		Aliases: []string{"ls"},
 | 
			
		||||
		Flags: []cli.Flag{
 | 
			
		||||
			&cli.BoolFlag{
 | 
			
		||||
				Name:    "installed",
 | 
			
		||||
				Aliases: []string{"I"},
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
	},
 | 
			
		||||
	Action: func(c *cli.Context) error {
 | 
			
		||||
		ctx := c.Context
 | 
			
		||||
		cfg := config.New()
 | 
			
		||||
		db := database.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)
 | 
			
		||||
		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)
 | 
			
		||||
		if c.NArg() > 0 {
 | 
			
		||||
			where = "name LIKE ? OR json_array_contains(provides, ?)"
 | 
			
		||||
			args = []any{c.Args().First(), c.Args().First()}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		result, err := db.GetPkgs(ctx, where, args...)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			slog.Error(gotext.Get("Error getting packages"), "err", err)
 | 
			
		||||
			os.Exit(1)
 | 
			
		||||
		}
 | 
			
		||||
		defer result.Close()
 | 
			
		||||
 | 
			
		||||
		var installed map[string]string
 | 
			
		||||
		if c.Bool("installed") {
 | 
			
		||||
			mgr := manager.Detect()
 | 
			
		||||
			if mgr == nil {
 | 
			
		||||
				slog.Error(gotext.Get("Unable to detect a supported package manager on the system"))
 | 
			
		||||
		Action: func(c *cli.Context) error {
 | 
			
		||||
			ctx := c.Context
 | 
			
		||||
			cfg := config.New()
 | 
			
		||||
			db := database.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)
 | 
			
		||||
			err = rs.Pull(ctx, cfg.Repos(ctx))
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				slog.Error(gotext.Get("Error pulling repositories"), "err", err)
 | 
			
		||||
				os.Exit(1)
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			installed, err = mgr.ListInstalled(&manager.Opts{AsRoot: false})
 | 
			
		||||
			where := "true"
 | 
			
		||||
			args := []any(nil)
 | 
			
		||||
			if c.NArg() > 0 {
 | 
			
		||||
				where = "name LIKE ? OR json_array_contains(provides, ?)"
 | 
			
		||||
				args = []any{c.Args().First(), c.Args().First()}
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			result, err := db.GetPkgs(ctx, where, args...)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				slog.Error(gotext.Get("Error listing installed packages"), "err", err)
 | 
			
		||||
				slog.Error(gotext.Get("Error getting packages"), "err", err)
 | 
			
		||||
				os.Exit(1)
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
			defer result.Close()
 | 
			
		||||
 | 
			
		||||
		for result.Next() {
 | 
			
		||||
			var pkg database.Package
 | 
			
		||||
			err := result.StructScan(&pkg)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				return err
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			if slices.Contains(cfg.IgnorePkgUpdates(ctx), pkg.Name) {
 | 
			
		||||
				continue
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			version := pkg.Version
 | 
			
		||||
			var installed map[string]string
 | 
			
		||||
			if c.Bool("installed") {
 | 
			
		||||
				instVersion, ok := installed[pkg.Name]
 | 
			
		||||
				if !ok {
 | 
			
		||||
					continue
 | 
			
		||||
				} else {
 | 
			
		||||
					version = instVersion
 | 
			
		||||
				mgr := manager.Detect()
 | 
			
		||||
				if mgr == nil {
 | 
			
		||||
					slog.Error(gotext.Get("Unable to detect a supported package manager on the system"))
 | 
			
		||||
					os.Exit(1)
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				installed, err = mgr.ListInstalled(&manager.Opts{AsRoot: false})
 | 
			
		||||
				if err != nil {
 | 
			
		||||
					slog.Error(gotext.Get("Error listing installed packages"), "err", err)
 | 
			
		||||
					os.Exit(1)
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			fmt.Printf("%s/%s %s\n", pkg.Repository, pkg.Name, version)
 | 
			
		||||
		}
 | 
			
		||||
			for result.Next() {
 | 
			
		||||
				var pkg database.Package
 | 
			
		||||
				err := result.StructScan(&pkg)
 | 
			
		||||
				if err != nil {
 | 
			
		||||
					return err
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			slog.Error(gotext.Get("Error iterating over packages"), "err", err)
 | 
			
		||||
			os.Exit(1)
 | 
			
		||||
		}
 | 
			
		||||
				if slices.Contains(cfg.IgnorePkgUpdates(ctx), pkg.Name) {
 | 
			
		||||
					continue
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
		return nil
 | 
			
		||||
	},
 | 
			
		||||
				version := pkg.Version
 | 
			
		||||
				if c.Bool("installed") {
 | 
			
		||||
					instVersion, ok := installed[pkg.Name]
 | 
			
		||||
					if !ok {
 | 
			
		||||
						continue
 | 
			
		||||
					} else {
 | 
			
		||||
						version = instVersion
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				fmt.Printf("%s/%s %s\n", pkg.Repository, pkg.Name, version)
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				slog.Error(gotext.Get("Error iterating over packages"), "err", err)
 | 
			
		||||
				os.Exit(1)
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			return nil
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										46
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										46
									
								
								main.go
									
									
									
									
									
								
							@@ -39,13 +39,15 @@ import (
 | 
			
		||||
	"gitea.plemya-x.ru/Plemya-x/ALR/internal/logger"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var versionCmd = &cli.Command{
 | 
			
		||||
	Name:  "version",
 | 
			
		||||
	Usage: "Print the current ALR version and exit",
 | 
			
		||||
	Action: func(ctx *cli.Context) error {
 | 
			
		||||
		println(config.Version)
 | 
			
		||||
		return nil
 | 
			
		||||
	},
 | 
			
		||||
func VersionCmd() *cli.Command {
 | 
			
		||||
	return &cli.Command{
 | 
			
		||||
		Name:  "version",
 | 
			
		||||
		Usage: gotext.Get("Print the current ALR version and exit"),
 | 
			
		||||
		Action: func(ctx *cli.Context) error {
 | 
			
		||||
			println(config.Version)
 | 
			
		||||
			return nil
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetApp() *cli.App {
 | 
			
		||||
@@ -56,29 +58,29 @@ func GetApp() *cli.App {
 | 
			
		||||
			&cli.StringFlag{
 | 
			
		||||
				Name:    "pm-args",
 | 
			
		||||
				Aliases: []string{"P"},
 | 
			
		||||
				Usage:   "Arguments to be passed on to the package manager",
 | 
			
		||||
				Usage:   gotext.Get("Arguments to be passed on to the package manager"),
 | 
			
		||||
			},
 | 
			
		||||
			&cli.BoolFlag{
 | 
			
		||||
				Name:    "interactive",
 | 
			
		||||
				Aliases: []string{"i"},
 | 
			
		||||
				Value:   isatty.IsTerminal(os.Stdin.Fd()),
 | 
			
		||||
				Usage:   "Enable interactive questions and prompts",
 | 
			
		||||
				Usage:   gotext.Get("Enable interactive questions and prompts"),
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		Commands: []*cli.Command{
 | 
			
		||||
			installCmd,
 | 
			
		||||
			removeCmd,
 | 
			
		||||
			upgradeCmd,
 | 
			
		||||
			GetInfoCmd(),
 | 
			
		||||
			listCmd,
 | 
			
		||||
			buildCmd,
 | 
			
		||||
			addrepoCmd,
 | 
			
		||||
			removerepoCmd,
 | 
			
		||||
			refreshCmd,
 | 
			
		||||
			fixCmd,
 | 
			
		||||
			genCmd,
 | 
			
		||||
			helperCmd,
 | 
			
		||||
			versionCmd,
 | 
			
		||||
			InstallCmd(),
 | 
			
		||||
			RemoveCmd(),
 | 
			
		||||
			UpgradeCmd(),
 | 
			
		||||
			InfoCmd(),
 | 
			
		||||
			ListCmd(),
 | 
			
		||||
			BuildCmd(),
 | 
			
		||||
			AddRepoCmd(),
 | 
			
		||||
			RemoveRepoCmd(),
 | 
			
		||||
			RefreshCmd(),
 | 
			
		||||
			FixCmd(),
 | 
			
		||||
			GenCmd(),
 | 
			
		||||
			HelperCmd(),
 | 
			
		||||
			VersionCmd(),
 | 
			
		||||
		},
 | 
			
		||||
		Before: func(c *cli.Context) error {
 | 
			
		||||
			ctx := c.Context
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										250
									
								
								repo.go
									
									
									
									
									
								
							
							
						
						
									
										250
									
								
								repo.go
									
									
									
									
									
								
							@@ -35,138 +35,144 @@ import (
 | 
			
		||||
	"gitea.plemya-x.ru/Plemya-x/ALR/pkg/repos"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var addrepoCmd = &cli.Command{
 | 
			
		||||
	Name:    "addrepo",
 | 
			
		||||
	Usage:   "Add a new repository",
 | 
			
		||||
	Aliases: []string{"ar"},
 | 
			
		||||
	Flags: []cli.Flag{
 | 
			
		||||
		&cli.StringFlag{
 | 
			
		||||
			Name:     "name",
 | 
			
		||||
			Aliases:  []string{"n"},
 | 
			
		||||
			Required: true,
 | 
			
		||||
			Usage:    "Name of the new repo",
 | 
			
		||||
func AddRepoCmd() *cli.Command {
 | 
			
		||||
	return &cli.Command{
 | 
			
		||||
		Name:    "addrepo",
 | 
			
		||||
		Usage:   gotext.Get("Add a new repository"),
 | 
			
		||||
		Aliases: []string{"ar"},
 | 
			
		||||
		Flags: []cli.Flag{
 | 
			
		||||
			&cli.StringFlag{
 | 
			
		||||
				Name:     "name",
 | 
			
		||||
				Aliases:  []string{"n"},
 | 
			
		||||
				Required: true,
 | 
			
		||||
				Usage:    gotext.Get("Name of the new repo"),
 | 
			
		||||
			},
 | 
			
		||||
			&cli.StringFlag{
 | 
			
		||||
				Name:     "url",
 | 
			
		||||
				Aliases:  []string{"u"},
 | 
			
		||||
				Required: true,
 | 
			
		||||
				Usage:    gotext.Get("URL of the new repo"),
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		&cli.StringFlag{
 | 
			
		||||
			Name:     "url",
 | 
			
		||||
			Aliases:  []string{"u"},
 | 
			
		||||
			Required: true,
 | 
			
		||||
			Usage:    "URL of the new repo",
 | 
			
		||||
		},
 | 
			
		||||
	},
 | 
			
		||||
	Action: func(c *cli.Context) error {
 | 
			
		||||
		ctx := c.Context
 | 
			
		||||
		Action: func(c *cli.Context) error {
 | 
			
		||||
			ctx := c.Context
 | 
			
		||||
 | 
			
		||||
		name := c.String("name")
 | 
			
		||||
		repoURL := c.String("url")
 | 
			
		||||
			name := c.String("name")
 | 
			
		||||
			repoURL := c.String("url")
 | 
			
		||||
 | 
			
		||||
		cfg := config.Config(ctx)
 | 
			
		||||
			cfg := config.Config(ctx)
 | 
			
		||||
 | 
			
		||||
		for _, repo := range cfg.Repos {
 | 
			
		||||
			if repo.URL == repoURL {
 | 
			
		||||
				slog.Error("Repo already exists", "name", repo.Name)
 | 
			
		||||
			for _, repo := range cfg.Repos {
 | 
			
		||||
				if repo.URL == repoURL {
 | 
			
		||||
					slog.Error("Repo already exists", "name", repo.Name)
 | 
			
		||||
					os.Exit(1)
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			cfg.Repos = append(cfg.Repos, types.Repo{
 | 
			
		||||
				Name: name,
 | 
			
		||||
				URL:  repoURL,
 | 
			
		||||
			})
 | 
			
		||||
 | 
			
		||||
			cfgFl, err := os.Create(config.GetPaths(ctx).ConfigPath)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				slog.Error(gotext.Get("Error opening config file"), "err", err)
 | 
			
		||||
				os.Exit(1)
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		cfg.Repos = append(cfg.Repos, types.Repo{
 | 
			
		||||
			Name: name,
 | 
			
		||||
			URL:  repoURL,
 | 
			
		||||
		})
 | 
			
		||||
 | 
			
		||||
		cfgFl, err := os.Create(config.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 = repos.Pull(ctx, cfg.Repos)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			slog.Error(gotext.Get("Error pulling repos"), "err", err)
 | 
			
		||||
			os.Exit(1)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return nil
 | 
			
		||||
	},
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var removerepoCmd = &cli.Command{
 | 
			
		||||
	Name:    "removerepo",
 | 
			
		||||
	Usage:   "Remove an existing repository",
 | 
			
		||||
	Aliases: []string{"rr"},
 | 
			
		||||
	Flags: []cli.Flag{
 | 
			
		||||
		&cli.StringFlag{
 | 
			
		||||
			Name:     "name",
 | 
			
		||||
			Aliases:  []string{"n"},
 | 
			
		||||
			Required: true,
 | 
			
		||||
			Usage:    "Name of the repo to be deleted",
 | 
			
		||||
		},
 | 
			
		||||
	},
 | 
			
		||||
	Action: func(c *cli.Context) error {
 | 
			
		||||
		ctx := c.Context
 | 
			
		||||
 | 
			
		||||
		name := c.String("name")
 | 
			
		||||
		cfg := config.Config(ctx)
 | 
			
		||||
 | 
			
		||||
		found := false
 | 
			
		||||
		index := 0
 | 
			
		||||
		for i, repo := range cfg.Repos {
 | 
			
		||||
			if repo.Name == name {
 | 
			
		||||
				index = i
 | 
			
		||||
				found = true
 | 
			
		||||
			err = toml.NewEncoder(cfgFl).Encode(cfg)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				slog.Error(gotext.Get("Error encoding config"), "err", err)
 | 
			
		||||
				os.Exit(1)
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		if !found {
 | 
			
		||||
			slog.Error(gotext.Get("Repo does not exist"), "name", name)
 | 
			
		||||
			os.Exit(1)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		cfg.Repos = slices.Delete(cfg.Repos, index, index+1)
 | 
			
		||||
			err = repos.Pull(ctx, cfg.Repos)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				slog.Error(gotext.Get("Error pulling repos"), "err", err)
 | 
			
		||||
				os.Exit(1)
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
		cfgFl, err := os.Create(config.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(config.GetPaths(ctx).RepoDir, name))
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			slog.Error(gotext.Get("Error removing repo directory"), "err", err)
 | 
			
		||||
			os.Exit(1)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		err = db.DeletePkgs(ctx, "repository = ?", name)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			slog.Error(gotext.Get("Error removing packages from database"), "err", err)
 | 
			
		||||
			os.Exit(1)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return nil
 | 
			
		||||
	},
 | 
			
		||||
			return nil
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var refreshCmd = &cli.Command{
 | 
			
		||||
	Name:    "refresh",
 | 
			
		||||
	Usage:   "Pull all repositories that have changed",
 | 
			
		||||
	Aliases: []string{"ref"},
 | 
			
		||||
	Action: func(c *cli.Context) error {
 | 
			
		||||
		ctx := c.Context
 | 
			
		||||
		err := repos.Pull(ctx, config.Config(ctx).Repos)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			slog.Error(gotext.Get("Error pulling repos"), "err", err)
 | 
			
		||||
			os.Exit(1)
 | 
			
		||||
		}
 | 
			
		||||
		return nil
 | 
			
		||||
	},
 | 
			
		||||
func RemoveRepoCmd() *cli.Command {
 | 
			
		||||
	return &cli.Command{
 | 
			
		||||
		Name:    "removerepo",
 | 
			
		||||
		Usage:   gotext.Get("Remove an existing repository"),
 | 
			
		||||
		Aliases: []string{"rr"},
 | 
			
		||||
		Flags: []cli.Flag{
 | 
			
		||||
			&cli.StringFlag{
 | 
			
		||||
				Name:     "name",
 | 
			
		||||
				Aliases:  []string{"n"},
 | 
			
		||||
				Required: true,
 | 
			
		||||
				Usage:    gotext.Get("Name of the repo to be deleted"),
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		Action: func(c *cli.Context) error {
 | 
			
		||||
			ctx := c.Context
 | 
			
		||||
 | 
			
		||||
			name := c.String("name")
 | 
			
		||||
			cfg := config.Config(ctx)
 | 
			
		||||
 | 
			
		||||
			found := false
 | 
			
		||||
			index := 0
 | 
			
		||||
			for i, repo := range cfg.Repos {
 | 
			
		||||
				if repo.Name == name {
 | 
			
		||||
					index = i
 | 
			
		||||
					found = true
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
			if !found {
 | 
			
		||||
				slog.Error(gotext.Get("Repo does not exist"), "name", name)
 | 
			
		||||
				os.Exit(1)
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			cfg.Repos = slices.Delete(cfg.Repos, index, index+1)
 | 
			
		||||
 | 
			
		||||
			cfgFl, err := os.Create(config.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(config.GetPaths(ctx).RepoDir, name))
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				slog.Error(gotext.Get("Error removing repo directory"), "err", err)
 | 
			
		||||
				os.Exit(1)
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			err = db.DeletePkgs(ctx, "repository = ?", name)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				slog.Error(gotext.Get("Error removing packages from database"), "err", err)
 | 
			
		||||
				os.Exit(1)
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			return nil
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func RefreshCmd() *cli.Command {
 | 
			
		||||
	return &cli.Command{
 | 
			
		||||
		Name:    "refresh",
 | 
			
		||||
		Usage:   gotext.Get("Pull all repositories that have changed"),
 | 
			
		||||
		Aliases: []string{"ref"},
 | 
			
		||||
		Action: func(c *cli.Context) error {
 | 
			
		||||
			ctx := c.Context
 | 
			
		||||
			err := repos.Pull(ctx, config.Config(ctx).Repos)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				slog.Error(gotext.Get("Error pulling repos"), "err", err)
 | 
			
		||||
				os.Exit(1)
 | 
			
		||||
			}
 | 
			
		||||
			return nil
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										88
									
								
								upgrade.go
									
									
									
									
									
								
							
							
						
						
									
										88
									
								
								upgrade.go
									
									
									
									
									
								
							@@ -41,56 +41,58 @@ import (
 | 
			
		||||
	"gitea.plemya-x.ru/Plemya-x/ALR/pkg/repos"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var upgradeCmd = &cli.Command{
 | 
			
		||||
	Name:    "upgrade",
 | 
			
		||||
	Usage:   "Upgrade all installed packages",
 | 
			
		||||
	Aliases: []string{"up"},
 | 
			
		||||
	Flags: []cli.Flag{
 | 
			
		||||
		&cli.BoolFlag{
 | 
			
		||||
			Name:    "clean",
 | 
			
		||||
			Aliases: []string{"c"},
 | 
			
		||||
			Usage:   "Build package from scratch even if there's an already built package available",
 | 
			
		||||
func UpgradeCmd() *cli.Command {
 | 
			
		||||
	return &cli.Command{
 | 
			
		||||
		Name:    "upgrade",
 | 
			
		||||
		Usage:   gotext.Get("Upgrade all installed packages"),
 | 
			
		||||
		Aliases: []string{"up"},
 | 
			
		||||
		Flags: []cli.Flag{
 | 
			
		||||
			&cli.BoolFlag{
 | 
			
		||||
				Name:    "clean",
 | 
			
		||||
				Aliases: []string{"c"},
 | 
			
		||||
				Usage:   gotext.Get("Build package from scratch even if there's an already built package available"),
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
	},
 | 
			
		||||
	Action: func(c *cli.Context) error {
 | 
			
		||||
		ctx := c.Context
 | 
			
		||||
		Action: func(c *cli.Context) error {
 | 
			
		||||
			ctx := c.Context
 | 
			
		||||
 | 
			
		||||
		info, err := distro.ParseOSRelease(ctx)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			slog.Error(gotext.Get("Error parsing os-release file"), "err", err)
 | 
			
		||||
			os.Exit(1)
 | 
			
		||||
		}
 | 
			
		||||
			info, err := distro.ParseOSRelease(ctx)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				slog.Error(gotext.Get("Error parsing os-release file"), "err", err)
 | 
			
		||||
				os.Exit(1)
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
		mgr := manager.Detect()
 | 
			
		||||
		if mgr == nil {
 | 
			
		||||
			slog.Error(gotext.Get("Unable to detect a supported package manager on the system"))
 | 
			
		||||
			os.Exit(1)
 | 
			
		||||
		}
 | 
			
		||||
			mgr := manager.Detect()
 | 
			
		||||
			if mgr == nil {
 | 
			
		||||
				slog.Error(gotext.Get("Unable to detect a supported package manager on the system"))
 | 
			
		||||
				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)
 | 
			
		||||
		}
 | 
			
		||||
			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 {
 | 
			
		||||
			slog.Error(gotext.Get("Error checking for updates"), "err", err)
 | 
			
		||||
			os.Exit(1)
 | 
			
		||||
		}
 | 
			
		||||
			updates, err := checkForUpdates(ctx, mgr, info)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				slog.Error(gotext.Get("Error checking for updates"), "err", err)
 | 
			
		||||
				os.Exit(1)
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
		if len(updates) > 0 {
 | 
			
		||||
			build.InstallPkgs(ctx, updates, nil, types.BuildOpts{
 | 
			
		||||
				Manager:     mgr,
 | 
			
		||||
				Clean:       c.Bool("clean"),
 | 
			
		||||
				Interactive: c.Bool("interactive"),
 | 
			
		||||
			})
 | 
			
		||||
		} else {
 | 
			
		||||
			log.Info("There is nothing to do.").Send()
 | 
			
		||||
		}
 | 
			
		||||
			if len(updates) > 0 {
 | 
			
		||||
				build.InstallPkgs(ctx, updates, nil, types.BuildOpts{
 | 
			
		||||
					Manager:     mgr,
 | 
			
		||||
					Clean:       c.Bool("clean"),
 | 
			
		||||
					Interactive: c.Bool("interactive"),
 | 
			
		||||
				})
 | 
			
		||||
			} else {
 | 
			
		||||
				log.Info("There is nothing to do.").Send()
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
		return nil
 | 
			
		||||
	},
 | 
			
		||||
			return nil
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func checkForUpdates(ctx context.Context, mgr manager.Manager, info *distro.OSRelease) ([]db.Package, error) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user