diff --git a/cmd/check.go b/cmd/check.go index 9e28766..7d1cf56 100644 --- a/cmd/check.go +++ b/cmd/check.go @@ -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.") }, } diff --git a/cmd/forget.go b/cmd/forget.go index 8528d7c..32e18fd 100644 --- a/cmd/forget.go +++ b/cmd/forget.go @@ -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") } diff --git a/internal/config.go b/internal/config.go index 485cee4..7045144 100644 --- a/internal/config.go +++ b/internal/config.go @@ -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 } } diff --git a/internal/location.go b/internal/location.go index d256572..181e12b 100644 --- a/internal/location.go +++ b/internal/location.go @@ -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)