This commit is contained in:
2025-04-13 19:39:01 +03:00
parent 587abf7aad
commit f26b72b2a2
10 changed files with 186 additions and 184 deletions

53
main.go
View File

@ -21,10 +21,10 @@ package main
import (
"context"
"fmt"
"log/slog"
"os"
"os/signal"
"strings"
"syscall"
"github.com/leonelquinteros/gotext"
@ -50,24 +50,6 @@ func VersionCmd() *cli.Command {
}
}
func HandleExitCoder(err error) {
if err == nil {
return
}
if exitErr, ok := err.(cli.ExitCoder); ok {
if err.Error() != "" {
if _, ok := exitErr.(cli.ErrorFormatter); ok {
slog.Error(fmt.Sprintf("%+v\n", err))
} else {
slog.Error(err.Error())
}
}
cli.OsExiter(exitErr.ExitCode())
return
}
}
func GetApp() *cli.App {
return &cli.App{
Name: "alr",
@ -100,41 +82,22 @@ func GetApp() *cli.App {
HelperCmd(),
VersionCmd(),
SearchCmd(),
// TEST
// Internal commands
InternalBuildCmd(),
InternalInstallCmd(),
InternalMountCmd(),
InternalUnmountCmd(),
// InternalBuild2Cmd(),
},
Before: func(c *cli.Context) error {
/*
cfg := config.New()
err := cfg.Load()
if err != nil {
slog.Error(gotext.Get("Error loading config"), "err", err)
os.Exit(1)
}
/*
cmd := c.Args().First()
if cmd != "helper" && !cfg.AllowRunAsRoot() && os.Geteuid() == 0 {
slog.Error(gotext.Get("Running ALR as root is forbidden as it may cause catastrophic damage to your system"))
os.Exit(1)
}
if trimmed := strings.TrimSpace(c.String("pm-args")); trimmed != "" {
args := strings.Split(trimmed, " ")
manager.Args = append(manager.Args, args...)
}
return nil
*/
if trimmed := strings.TrimSpace(c.String("pm-args")); trimmed != "" {
args := strings.Split(trimmed, " ")
manager.Args = append(manager.Args, args...)
}
return nil
},
EnableBashCompletion: true,
ExitErrHandler: func(c *cli.Context, err error) {
ExitErrHandler: func(cCtx *cli.Context, err error) {
cliutils.HandleExitCoder(err)
},
}
}