You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
autorestic/cmd/exec.go

48 lines
1.0 KiB

4 years ago
package cmd
import (
"fmt"
4 years ago
"github.com/cupcakearmy/autorestic/internal"
"github.com/cupcakearmy/autorestic/internal/colors"
"github.com/cupcakearmy/autorestic/internal/lock"
4 years ago
"github.com/spf13/cobra"
)
var execCmd = &cobra.Command{
Use: "exec",
4 years ago
Short: "Execute arbitrary native restic commands for given backends",
4 years ago
Run: func(cmd *cobra.Command, args []string) {
internal.GetConfig()
err := lock.Lock()
CheckErr(err)
defer lock.Unlock()
4 years ago
selected, err := internal.GetAllOrSelected(cmd, true)
CheckErr(err)
var errors []error
4 years ago
for _, name := range selected {
colors.PrimaryPrint(" Executing on \"%s\" ", name)
4 years ago
backend, _ := internal.GetBackend(name)
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)))
4 years ago
}
4 years ago
},
}
func init() {
rootCmd.AddCommand(execCmd)
4 years ago
internal.AddFlagsToCommand(execCmd, true)
4 years ago
}