-
Notifications
You must be signed in to change notification settings - Fork 87
/
get-backups.go
44 lines (36 loc) · 1022 Bytes
/
get-backups.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package cli
import (
"github.com/pkg/errors"
"github.com/replicatedhq/kots/pkg/print"
"github.com/replicatedhq/kots/pkg/snapshot"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
func GetBackupsCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "backups",
Aliases: []string{"backup"},
Short: "Get backups",
Long: "",
SilenceUsage: false,
SilenceErrors: false,
PreRun: func(cmd *cobra.Command, args []string) {
viper.BindPFlags(cmd.Flags())
},
RunE: getBackupsCmd,
}
cmd.Flags().StringP("output", "o", "", "output format. supported values: json")
return cmd
}
func getBackupsCmd(cmd *cobra.Command, args []string) error {
v := viper.GetViper()
options := snapshot.ListInstanceBackupsOptions{
Namespace: v.GetString("namespace"),
}
backups, err := snapshot.ListInstanceBackups(cmd.Context(), options)
if err != nil {
return errors.Wrap(err, "failed to list instance backups")
}
print.Backups(backups, v.GetString("output"))
return nil
}