github.com/psyb0t/mattermost-server@v4.6.1-0.20180125161845-5503a1351abf+incompatible/cmd/platform/mattermost.go (about)

     1  // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package main
     5  
     6  import (
     7  	"errors"
     8  	"fmt"
     9  	"os"
    10  
    11  	"github.com/spf13/cobra"
    12  
    13  	// Plugins
    14  	_ "github.com/mattermost/mattermost-server/model/gitlab"
    15  
    16  	// Enterprise Imports
    17  	_ "github.com/mattermost/mattermost-server/imports"
    18  
    19  	// Enterprise Deps
    20  	_ "github.com/dgryski/dgoogauth"
    21  	_ "github.com/go-ldap/ldap"
    22  	_ "github.com/hashicorp/memberlist"
    23  	_ "github.com/mattermost/rsc/qr"
    24  	_ "gopkg.in/olivere/elastic.v5"
    25  )
    26  
    27  func main() {
    28  	if err := rootCmd.Execute(); err != nil {
    29  		os.Exit(1)
    30  	}
    31  }
    32  
    33  func init() {
    34  	rootCmd.PersistentFlags().StringP("config", "c", "config.json", "Configuration file to use.")
    35  	rootCmd.PersistentFlags().Bool("disableconfigwatch", false, "When set config.json will not be loaded from disk when the file is changed.")
    36  
    37  	resetCmd.Flags().Bool("confirm", false, "Confirm you really want to delete everything and a DB backup has been performed.")
    38  
    39  	rootCmd.AddCommand(serverCmd, versionCmd, userCmd, teamCmd, licenseCmd, importCmd, resetCmd, channelCmd, rolesCmd, testCmd, ldapCmd, configCmd, jobserverCmd, commandCmd, messageExportCmd, sampleDataCmd)
    40  }
    41  
    42  var rootCmd = &cobra.Command{
    43  	Use:   "platform",
    44  	Short: "Open source, self-hosted Slack-alternative",
    45  	Long:  `Mattermost offers workplace messaging across web, PC and phones with archiving, search and integration with your existing systems. Documentation available at https://docs.mattermost.com`,
    46  	RunE:  runServerCmd,
    47  }
    48  
    49  var resetCmd = &cobra.Command{
    50  	Use:   "reset",
    51  	Short: "Reset the database to initial state",
    52  	Long:  "Completely erases the database causing the loss of all data. This will reset Mattermost to its initial state.",
    53  	RunE:  resetCmdF,
    54  }
    55  
    56  func resetCmdF(cmd *cobra.Command, args []string) error {
    57  	a, err := initDBCommandContextCobra(cmd)
    58  	if err != nil {
    59  		return err
    60  	}
    61  
    62  	confirmFlag, _ := cmd.Flags().GetBool("confirm")
    63  	if !confirmFlag {
    64  		var confirm string
    65  		CommandPrettyPrintln("Have you performed a database backup? (YES/NO): ")
    66  		fmt.Scanln(&confirm)
    67  
    68  		if confirm != "YES" {
    69  			return errors.New("ABORTED: You did not answer YES exactly, in all capitals.")
    70  		}
    71  		CommandPrettyPrintln("Are you sure you want to delete everything? All data will be permanently deleted? (YES/NO): ")
    72  		fmt.Scanln(&confirm)
    73  		if confirm != "YES" {
    74  			return errors.New("ABORTED: You did not answer YES exactly, in all capitals.")
    75  		}
    76  	}
    77  
    78  	a.Srv.Store.DropAllTables()
    79  	CommandPrettyPrintln("Database sucessfully reset")
    80  
    81  	return nil
    82  }