2021-04-09 01:55:10 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2022-08-26 17:09:26 +02:00
|
|
|
"fmt"
|
|
|
|
|
2021-04-09 01:55:10 +02:00
|
|
|
"github.com/cupcakearmy/autorestic/internal"
|
2021-04-12 16:15:17 +02:00
|
|
|
"github.com/cupcakearmy/autorestic/internal/colors"
|
2021-04-11 17:02:34 +02:00
|
|
|
"github.com/cupcakearmy/autorestic/internal/lock"
|
2021-04-09 01:55:10 +02:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var execCmd = &cobra.Command{
|
|
|
|
Use: "exec",
|
2021-04-11 13:08:50 +02:00
|
|
|
Short: "Execute arbitrary native restic commands for given backends",
|
2021-04-09 01:55:10 +02:00
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
2021-08-05 21:48:02 +02:00
|
|
|
internal.GetConfig()
|
2021-04-11 17:02:34 +02:00
|
|
|
err := lock.Lock()
|
|
|
|
CheckErr(err)
|
|
|
|
defer lock.Unlock()
|
|
|
|
|
2021-04-11 18:17:21 +02:00
|
|
|
selected, err := internal.GetAllOrSelected(cmd, true)
|
|
|
|
CheckErr(err)
|
2022-08-26 17:09:26 +02:00
|
|
|
|
|
|
|
var errors []error
|
2021-04-11 18:17:21 +02:00
|
|
|
for _, name := range selected {
|
2021-04-12 16:15:17 +02:00
|
|
|
colors.PrimaryPrint(" Executing on \"%s\" ", name)
|
2021-04-11 18:17:21 +02:00
|
|
|
backend, _ := internal.GetBackend(name)
|
2022-08-26 17:09:26 +02:00
|
|
|
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)))
|
2021-04-11 13:04:11 +02:00
|
|
|
}
|
2021-04-09 01:55:10 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
rootCmd.AddCommand(execCmd)
|
2021-04-11 13:04:11 +02:00
|
|
|
internal.AddFlagsToCommand(execCmd, true)
|
2021-04-09 01:55:10 +02:00
|
|
|
}
|