aboutsummaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorKalin Staykov <k.t.staykov@gmail.com>2022-11-26 15:49:59 +0200
committerMichael Muré <batolettre@gmail.com>2023-01-11 14:58:58 +0100
commitfc266b733cf0ea794209031e3500ab3f86db6cee (patch)
treebae1996ec19fb74446429200e52cdb942f60ac54 /commands
parent9c50a359704f4edd2f33df6d256e032feae3a576 (diff)
downloadgit-bug-fc266b733cf0ea794209031e3500ab3f86db6cee.tar.gz
add wipe sub-command that remove local bugs and identities
Diffstat (limited to 'commands')
-rw-r--r--commands/root.go1
-rw-r--r--commands/wipe.go58
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
+}