From b2dd00dd5b83fc7e8b311a55f5a2536e4f3d45a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Espino?= Date: Wed, 7 Mar 2018 20:04:18 +0000 Subject: Adding enterprise commands support (#8327) --- cmd/commands/reset.go | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 cmd/commands/reset.go (limited to 'cmd/commands/reset.go') diff --git a/cmd/commands/reset.go b/cmd/commands/reset.go new file mode 100644 index 000000000..e479d0354 --- /dev/null +++ b/cmd/commands/reset.go @@ -0,0 +1,53 @@ +// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package commands + +import ( + "errors" + "fmt" + + "github.com/mattermost/mattermost-server/cmd" + "github.com/spf13/cobra" +) + +var ResetCmd = &cobra.Command{ + Use: "reset", + Short: "Reset the database to initial state", + Long: "Completely erases the database causing the loss of all data. This will reset Mattermost to its initial state.", + RunE: resetCmdF, +} + +func init() { + ResetCmd.Flags().Bool("confirm", false, "Confirm you really want to delete everything and a DB backup has been performed.") + + cmd.RootCmd.AddCommand(ResetCmd) +} + +func resetCmdF(command *cobra.Command, args []string) error { + a, err := cmd.InitDBCommandContextCobra(command) + if err != nil { + return err + } + + confirmFlag, _ := command.Flags().GetBool("confirm") + if !confirmFlag { + var confirm string + cmd.CommandPrettyPrintln("Have you performed a database backup? (YES/NO): ") + fmt.Scanln(&confirm) + + if confirm != "YES" { + return errors.New("ABORTED: You did not answer YES exactly, in all capitals.") + } + cmd.CommandPrettyPrintln("Are you sure you want to delete everything? All data will be permanently deleted? (YES/NO): ") + fmt.Scanln(&confirm) + if confirm != "YES" { + return errors.New("ABORTED: You did not answer YES exactly, in all capitals.") + } + } + + a.Srv.Store.DropAllTables() + cmd.CommandPrettyPrintln("Database sucessfully reset") + + return nil +} -- cgit v1.2.3-1-g7c22