From 6990bf6adc200e7e5a38e76e8f07c4060d3650f1 Mon Sep 17 00:00:00 2001 From: Romain de Laage Date: Fri, 26 Aug 2022 17:09:26 +0200 Subject: [PATCH] Check for errors and forward on exec command (#227) fix #226 --- cmd/exec.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/cmd/exec.go b/cmd/exec.go index 1614fda..107b0e1 100644 --- a/cmd/exec.go +++ b/cmd/exec.go @@ -1,6 +1,8 @@ package cmd import ( + "fmt" + "github.com/cupcakearmy/autorestic/internal" "github.com/cupcakearmy/autorestic/internal/colors" "github.com/cupcakearmy/autorestic/internal/lock" @@ -18,10 +20,23 @@ var execCmd = &cobra.Command{ selected, err := internal.GetAllOrSelected(cmd, true) CheckErr(err) + + var errors []error for _, name := range selected { colors.PrimaryPrint(" Executing on \"%s\" ", name) backend, _ := internal.GetBackend(name) - backend.Exec(args) + err := backend.Exec(args) + if err != nil { + errors = append(errors, err) + } + } + + if len(errors) > 0 { + for _, err := range errors { + colors.Error.Printf("%s\n\n", err) + } + + CheckErr(fmt.Errorf("%d errors were found", len(errors))) } }, }