mirror of
https://github.com/cupcakearmy/autorestic.git
synced 2024-12-22 08:16:25 +00:00
dry run for forget cmd
This commit is contained in:
parent
05be58a3a7
commit
5d92b5bcc1
@ -17,6 +17,7 @@ package cmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/cupcakearmy/autorestic/internal"
|
||||
"github.com/spf13/cobra"
|
||||
@ -33,6 +34,7 @@ var checkCmd = &cobra.Command{
|
||||
config := internal.GetConfig()
|
||||
err := config.CheckConfig()
|
||||
cobra.CheckErr(err)
|
||||
fmt.Println("Everyting is fine.")
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -33,9 +33,10 @@ var forgetCmd = &cobra.Command{
|
||||
selected, err := internal.GetAllOrSelected(cmd, false)
|
||||
cobra.CheckErr(err)
|
||||
prune, _ := cmd.Flags().GetBool("prune")
|
||||
dry, _ := cmd.Flags().GetBool("dry-run")
|
||||
for _, name := range selected {
|
||||
location := config.Locations[name]
|
||||
err := location.Forget(prune)
|
||||
err := location.Forget(prune, dry)
|
||||
cobra.CheckErr(err)
|
||||
}
|
||||
}
|
||||
@ -46,4 +47,5 @@ func init() {
|
||||
rootCmd.AddCommand(forgetCmd)
|
||||
internal.AddFlagsToCommand(forgetCmd, false)
|
||||
forgetCmd.Flags().Bool("prune", false, "Also prune repository")
|
||||
forgetCmd.Flags().Bool("dry-run", false, "Do not write changes, show what would be affected")
|
||||
}
|
||||
|
@ -101,6 +101,9 @@ func GetAllOrSelected(cmd *cobra.Command, backends bool) ([]string, error) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(selected) == 0 {
|
||||
return selected, fmt.Errorf("nothing selected, aborting")
|
||||
}
|
||||
return selected, nil
|
||||
}
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ func (l Location) Backup() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l Location) Forget(prune bool) error {
|
||||
func (l Location) Forget(prune bool, dry bool) error {
|
||||
c := GetConfig()
|
||||
from := GetPathRelativeToConfig(l.From)
|
||||
for _, to := range l.To {
|
||||
@ -101,6 +101,9 @@ func (l Location) Forget(prune bool) error {
|
||||
if prune {
|
||||
cmd = append(cmd, "--prune")
|
||||
}
|
||||
if dry {
|
||||
cmd = append(cmd, "--dry-run")
|
||||
}
|
||||
cmd = append(cmd, flags...)
|
||||
out, err := ExecuteResticCommand(options, cmd...)
|
||||
fmt.Println(out)
|
||||
|
Loading…
Reference in New Issue
Block a user