Write forget and copy options with correct name

This commit is contained in:
Quentin Duchemin 2022-05-16 12:30:22 +02:00
parent 3bc091f826
commit b29a7472e0
No known key found for this signature in database
GPG Key ID: 0547178FEEDE7D6B
2 changed files with 18 additions and 18 deletions

View File

@ -21,7 +21,7 @@ var forgetCmd = &cobra.Command{
dry, _ := cmd.Flags().GetBool("dry-run") dry, _ := cmd.Flags().GetBool("dry-run")
for _, name := range selected { for _, name := range selected {
location, _ := internal.GetLocation(name) location, _ := internal.GetLocation(name)
err := location.Forget(prune, dry) err := location.DoForget(prune, dry)
CheckErr(err) CheckErr(err)
} }
}, },

View File

@ -43,15 +43,15 @@ type Hooks struct {
type LocationCopy = map[string][]string type LocationCopy = map[string][]string
type Location struct { type Location struct {
name string `mapstructure:",omitempty"` name string `mapstructure:",omitempty"`
From []string `mapstructure:"from,omitempty"` From []string `mapstructure:"from,omitempty"`
Type string `mapstructure:"type,omitempty"` Type string `mapstructure:"type,omitempty"`
To []string `mapstructure:"to,omitempty"` To []string `mapstructure:"to,omitempty"`
Hooks Hooks `mapstructure:"hooks,omitempty"` Hooks Hooks `mapstructure:"hooks,omitempty"`
Cron string `mapstructure:"cron,omitempty"` Cron string `mapstructure:"cron,omitempty"`
Options Options `mapstructure:"options,omitempty"` Options Options `mapstructure:"options,omitempty"`
ForgetOption LocationForgetOption `mapstructure:"forget,omitempty"` Forget LocationForgetOption `mapstructure:"forget,omitempty"`
CopyOption LocationCopy `mapstructure:"copy,omitempty"` Copy LocationCopy `mapstructure:"copy,omitempty"`
} }
func GetLocation(name string) (Location, bool) { func GetLocation(name string) (Location, bool) {
@ -101,7 +101,7 @@ func (l Location) validate() error {
} }
// Check copy option // Check copy option
for copyFrom, copyTo := range l.CopyOption { for copyFrom, copyTo := range l.Copy {
if _, ok := GetBackend(copyFrom); !ok { if _, ok := GetBackend(copyFrom); !ok {
return fmt.Errorf(`location "%s" has an invalid backend "%s" in copy option`, l.name, copyFrom) return fmt.Errorf(`location "%s" has an invalid backend "%s" in copy option`, l.name, copyFrom)
} }
@ -119,9 +119,9 @@ func (l Location) validate() error {
} }
// Check if forget type is correct // Check if forget type is correct
if l.ForgetOption != "" { if l.Forget != "" {
if l.ForgetOption != LocationForgetYes && l.ForgetOption != LocationForgetNo && l.ForgetOption != LocationForgetPrune { if l.Forget != LocationForgetYes && l.Forget != LocationForgetNo && l.Forget != LocationForgetPrune {
return fmt.Errorf("invalid value for forget option: %s", l.ForgetOption) return fmt.Errorf("invalid value for forget option: %s", l.Forget)
} }
} }
return nil return nil
@ -270,7 +270,7 @@ func (l Location) Backup(cron bool, specificBackend string) []error {
// Copy // Copy
if md.SnapshotID != "" { if md.SnapshotID != "" {
for copyFrom, copyTo := range l.CopyOption { for copyFrom, copyTo := range l.Copy {
b1, _ := GetBackend(copyFrom) b1, _ := GetBackend(copyFrom)
for _, copyToTarget := range copyTo { for _, copyToTarget := range copyTo {
b2, _ := GetBackend(copyToTarget) b2, _ := GetBackend(copyToTarget)
@ -311,8 +311,8 @@ after:
} }
// Forget and optionally prune // Forget and optionally prune
if isSuccess && l.ForgetOption != "" && l.ForgetOption != LocationForgetNo { if isSuccess && l.Forget != "" && l.Forget != LocationForgetNo {
l.Forget(l.ForgetOption == LocationForgetPrune, false) l.DoForget(l.Forget == LocationForgetPrune, false)
} }
if len(errors) == 0 { if len(errors) == 0 {
@ -321,7 +321,7 @@ after:
return errors return errors
} }
func (l Location) Forget(prune bool, dry bool) error { func (l Location) DoForget(prune bool, dry bool) error {
colors.PrimaryPrint("Forgetting for location \"%s\"", l.name) colors.PrimaryPrint("Forgetting for location \"%s\"", l.name)
for _, to := range l.To { for _, to := range l.To {