diff options
Diffstat (limited to 'cmd/platform/channel.go')
-rw-r--r-- | cmd/platform/channel.go | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/cmd/platform/channel.go b/cmd/platform/channel.go index 7419a0492..218cef1d5 100644 --- a/cmd/platform/channel.go +++ b/cmd/platform/channel.go @@ -4,6 +4,7 @@ package main import ( "errors" + "fmt" "github.com/mattermost/platform/app" "github.com/mattermost/platform/model" @@ -41,6 +42,16 @@ var addChannelUsersCmd = &cobra.Command{ RunE: addChannelUsersCmdF, } +var archiveChannelsCmd = &cobra.Command{ + Use: "archive [channels]", + Short: "Archive channels", + Long: `Archive some channels. +Archive a channel along with all related information including posts from the database. +Channels can be specified by [team]:[channel]. ie. myteam:mychannel or by channel ID.`, + Example: " channel archive myteam:mychannel", + RunE: archiveChannelsCmdF, +} + var deleteChannelsCmd = &cobra.Command{ Use: "delete [channels]", Short: "Delete channels", @@ -77,10 +88,13 @@ func init() { channelCreateCmd.Flags().String("purpose", "", "Channel purpose") channelCreateCmd.Flags().Bool("private", false, "Create a private channel.") + deleteChannelsCmd.Flags().Bool("confirm", false, "Confirm you really want to delete the channels.") + channelCmd.AddCommand( channelCreateCmd, removeChannelUsersCmd, addChannelUsersCmd, + archiveChannelsCmd, deleteChannelsCmd, listChannelsCmd, restoreChannelsCmd, @@ -205,7 +219,7 @@ func addUserToChannel(channel *model.Channel, user *model.User, userArg string) } } -func deleteChannelsCmdF(cmd *cobra.Command, args []string) error { +func archiveChannelsCmdF(cmd *cobra.Command, args []string) error { initDBCommandContextCobra(cmd) if len(args) < 1 { @@ -226,6 +240,43 @@ func deleteChannelsCmdF(cmd *cobra.Command, args []string) error { return nil } +func deleteChannelsCmdF(cmd *cobra.Command, args []string) error { + initDBCommandContextCobra(cmd) + + if len(args) < 1 { + return errors.New("Enter at least one channel to delete.") + } + + confirmFlag, _ := cmd.Flags().GetBool("confirm") + if !confirmFlag { + var confirm string + CommandPrettyPrintln("Are you sure you want to delete the channels specified? 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.") + } + } + + channels := getChannelsFromChannelArgs(args) + for i, channel := range channels { + if channel == nil { + CommandPrintErrorln("Unable to find channel '" + args[i] + "'") + continue + } + if err := deleteChannel(channel); err != nil { + CommandPrintErrorln("Unable to delete channel '" + channel.Name + "' error: " + err.Error()) + } else { + CommandPrettyPrintln("Deleted channel '" + channel.Name + "'") + } + } + + return nil +} + +func deleteChannel(channel *model.Channel) *model.AppError { + return app.PermanentDeleteChannel(channel) +} + func listChannelsCmdF(cmd *cobra.Command, args []string) error { initDBCommandContextCobra(cmd) |