diff options
Diffstat (limited to 'commands')
-rw-r--r-- | commands/root.go | 1 | ||||
-rw-r--r-- | commands/wipe.go | 58 |
2 files changed, 59 insertions, 0 deletions
diff --git a/commands/root.go b/commands/root.go index cb4fd686..0c854739 100644 --- a/commands/root.go +++ b/commands/root.go @@ -81,6 +81,7 @@ the same git remote you are already using to collaborate with other people. cmd.AddCommand(newCommandsCommand()) cmd.AddCommand(newVersionCommand()) + cmd.AddCommand(newWipeCommand()) return cmd } diff --git a/commands/wipe.go b/commands/wipe.go new file mode 100644 index 00000000..0ec53f49 --- /dev/null +++ b/commands/wipe.go @@ -0,0 +1,58 @@ +package commands + +import ( + "github.com/spf13/cobra" + + "github.com/MichaelMure/git-bug/commands/execenv" +) + +func newWipeCommand() *cobra.Command { + env := execenv.NewEnv() + + cmd := &cobra.Command{ + Use: "wipe", + Short: "Wipe git-bug from the git repository", + PreRunE: execenv.LoadBackend(env), + RunE: func(cmd *cobra.Command, args []string) error { + return runWipe(env) + }, + } + + return cmd +} + +func runWipe(env *execenv.Env) error { + env.Out.Println("cleaning entities...") + err := env.Backend.RemoveAll() + if err != nil { + _ = env.Backend.Close() + return err + } + + env.Out.Println("cleaning git config ...") + err = env.Backend.ClearUserIdentity() + if err != nil { + _ = env.Backend.Close() + return err + } + err = env.Backend.LocalConfig().RemoveAll("git-bug") + if err != nil { + _ = env.Backend.Close() + return err + } + + storage := env.Backend.LocalStorage() + + err = env.Backend.Close() + if err != nil { + return err + } + + env.Out.Println("cleaning caches ...") + err = storage.RemoveAll(".") + if err != nil { + return err + } + + return nil +} |