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