2017-04-12 08:27:57 -04:00
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
2016-12-06 10:49:34 -05:00
// See License.txt for license information.
package main
import (
"errors"
"fmt"
"os"
2017-01-13 13:53:37 -05:00
"github.com/mattermost/platform/app"
2016-12-06 10:49:34 -05:00
"github.com/spf13/cobra"
// Plugins
_ "github.com/mattermost/platform/model/gitlab"
2017-05-18 15:05:57 -04:00
// Enterprise Imports
_ "github.com/mattermost/platform/imports"
2016-12-06 10:49:34 -05:00
// Enterprise Deps
_ "github.com/dgryski/dgoogauth"
_ "github.com/go-ldap/ldap"
_ "github.com/mattermost/rsc/qr"
2017-05-17 16:51:25 -04:00
// Tmp deps for adding
_ "github.com/dimchansky/utfbom"
_ "github.com/hashicorp/memberlist"
_ "gopkg.in/gomail.v2"
_ "gopkg.in/olivere/elastic.v5"
2016-12-06 10:49:34 -05:00
)
func main ( ) {
2017-04-15 13:45:22 -04:00
if err := rootCmd . Execute ( ) ; err != nil {
os . Exit ( 1 )
2016-12-06 10:49:34 -05:00
}
2017-04-15 13:45:22 -04:00
}
func init ( ) {
2016-12-06 10:49:34 -05:00
rootCmd . PersistentFlags ( ) . StringP ( "config" , "c" , "config.json" , "Configuration file to use." )
2017-04-17 07:55:03 -07:00
rootCmd . PersistentFlags ( ) . Bool ( "disableconfigwatch" , false , "When set config.json will not be loaded from disk when the file is changed." )
2016-12-06 10:49:34 -05:00
resetCmd . Flags ( ) . Bool ( "confirm" , false , "Confirm you really want to delete everything and a DB backup has been performed." )
2017-04-17 09:44:10 -05:00
rootCmd . AddCommand ( serverCmd , versionCmd , userCmd , teamCmd , licenseCmd , importCmd , resetCmd , channelCmd , rolesCmd , testCmd , ldapCmd , configCmd )
2017-04-15 13:45:22 -04:00
}
2016-12-06 10:49:34 -05:00
2017-04-15 13:45:22 -04:00
var rootCmd = & cobra . Command {
Use : "platform" ,
Short : "Open source, self-hosted Slack-alternative" ,
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 ` ,
RunE : runServerCmd ,
2016-12-06 10:49:34 -05:00
}
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 resetCmdF ( cmd * cobra . Command , args [ ] string ) error {
2017-05-23 11:06:25 -04:00
if err := initDBCommandContextCobra ( cmd ) ; err != nil {
return err
}
2016-12-07 10:24:28 -05:00
2016-12-06 10:49:34 -05:00
confirmFlag , _ := cmd . Flags ( ) . GetBool ( "confirm" )
if ! confirmFlag {
var confirm string
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." )
}
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." )
}
}
2017-01-13 13:53:37 -05:00
app . Srv . Store . DropAllTables ( )
2016-12-06 10:49:34 -05:00
CommandPrettyPrintln ( "Database sucessfully reset" )
return nil
}