diff options
author | Kalin Staykov <k.t.staykov@gmail.com> | 2022-11-26 15:49:59 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2023-01-11 14:58:58 +0100 |
commit | fc266b733cf0ea794209031e3500ab3f86db6cee (patch) | |
tree | bae1996ec19fb74446429200e52cdb942f60ac54 /commands/wipe.go | |
parent | 9c50a359704f4edd2f33df6d256e032feae3a576 (diff) | |
download | git-bug-fc266b733cf0ea794209031e3500ab3f86db6cee.tar.gz |
add wipe sub-command that remove local bugs and identities
Diffstat (limited to 'commands/wipe.go')
-rw-r--r-- | commands/wipe.go | 58 |
1 files changed, 58 insertions, 0 deletions
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 +} |