diff options
author | Michael Muré <batolettre@gmail.com> | 2023-01-14 14:21:01 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-14 14:21:01 +0100 |
commit | 98eb1c111efb22ddb02ab71779f1862abab4baa5 (patch) | |
tree | bb4d8bc2c1fd5614d274dab272e7dae03da5496b /commands/wipe.go | |
parent | 9c50a359704f4edd2f33df6d256e032feae3a576 (diff) | |
parent | 5bf274e64a3486bba21edd9bf455089839219f25 (diff) | |
download | git-bug-98eb1c111efb22ddb02ab71779f1862abab4baa5.tar.gz git-bug-98eb1c111efb22ddb02ab71779f1862abab4baa5.zip |
Merge pull request #933 from zinderic/feat-cleanup-subcommand
add cleanup 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 000000000..0ec53f495 --- /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 +} |