Check for errors and forward on exec command (#227)

fix #226
This commit is contained in:
Romain de Laage 2022-08-26 17:09:26 +02:00 committed by GitHub
parent 2f407cf211
commit 6990bf6adc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)))
}
},
}