🎨 Introduce contextualized logging

This commit is multi-fold as it also refactors internally context and logger
as interfaces so it is easier to plug luet as a library externally.

Introduces a garbage collector (related to #227) but doesn't handle yet
parallelism.

Closes #265
This commit is contained in:
Ettore Di Giacinto
2021-12-17 15:21:03 +01:00
parent fd90e0d627
commit c98f427156
105 changed files with 2672 additions and 1271 deletions

View File

@@ -32,7 +32,7 @@ type LuetFinalizer struct {
Uninstall []string `json:"uninstall"` // TODO: Where to store?
}
func (f *LuetFinalizer) RunInstall(ctx *types.Context, s *System) error {
func (f *LuetFinalizer) RunInstall(ctx types.Context, s *System) error {
var cmd string
var args []string
if len(f.Shell) == 0 {
@@ -51,14 +51,14 @@ func (f *LuetFinalizer) RunInstall(ctx *types.Context, s *System) error {
ctx.Info(":shell: Executing finalizer on ", s.Target, cmd, toRun)
if s.Target == string(os.PathSeparator) {
cmd := exec.Command(cmd, toRun...)
cmd.Env = ctx.Config.GetFinalizerEnvs()
cmd.Env = ctx.GetConfig().FinalizerEnvs.Slice()
stdoutStderr, err := cmd.CombinedOutput()
if err != nil {
return errors.Wrap(err, "Failed running command: "+string(stdoutStderr))
}
ctx.Info(string(stdoutStderr))
} else {
b := box.NewBox(cmd, toRun, []string{}, ctx.Config.GetFinalizerEnvs(), s.Target, false, true, true)
b := box.NewBox(cmd, toRun, []string{}, ctx.GetConfig().FinalizerEnvs.Slice(), s.Target, false, true, true)
err := b.Run()
if err != nil {
return errors.Wrap(err, "Failed running command ")
@@ -69,7 +69,7 @@ func (f *LuetFinalizer) RunInstall(ctx *types.Context, s *System) error {
}
// TODO: We don't store uninstall finalizers ?!
func (f *LuetFinalizer) RunUnInstall(ctx *types.Context) error {
func (f *LuetFinalizer) RunUnInstall(ctx types.Context) error {
for _, c := range f.Uninstall {
ctx.Debug("finalizer:", "sh", "-c", c)
cmd := exec.Command("sh", "-c", c)