Изменение работы логики аргумента -p

This commit is contained in:
2025-01-26 11:36:03 +03:00
parent 99857efb01
commit dc1fac29d5
2 changed files with 57 additions and 57 deletions

View File

@ -57,55 +57,64 @@ func BuildCmd() *cli.Command {
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
script := c.String("script")
if c.String("package") != "" {
script = filepath.Join(config.GetPaths(ctx).RepoDir, c.String("package"), "alr.sh")
}
var script string
packageInput := c.String("package")
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)
}
}
if packageInput != "" {
// If the package input contains a '/', use it as the full path.
if filepath.Dir(packageInput) == "." {
// No directory specified, use 'default' as a prefix.
script = filepath.Join(config.GetPaths(ctx).RepoDir, "default", packageInput, "alr.sh")
} else {
// Use the full path specified by the user.
script = filepath.Join(config.GetPaths(ctx).RepoDir, packageInput, "alr.sh")
}
}
mgr := manager.Detect()
if mgr == nil {
slog.Error(gotext.Get("Unable to detect a supported package manager on the system"))
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)
}
}
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)
}
mgr := manager.Detect()
if mgr == nil {
slog.Error(gotext.Get("Unable to detect a supported package manager on the system"))
os.Exit(1)
}
wd, err := os.Getwd()
if err != nil {
slog.Error(gotext.Get("Error getting working directory"), "err", err)
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)
}
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)
}
}
wd, err := os.Getwd()
if err != nil {
slog.Error(gotext.Get("Error getting working directory"), "err", err)
os.Exit(1)
}
return nil
},
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
},
}
}