summaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorCarlos Tadeu Panato Junior <ctadeu@gmail.com>2017-05-17 20:12:37 +0200
committerCorey Hulen <corey@hulen.com>2017-05-17 11:12:37 -0700
commitcd23b8139a9463b67e3096744321f6f4eb0ca40a (patch)
treea7abffd57c2e8cefca50dadbbe2a1171ec39d82c /cmd
parent9a5f16924c16afb018098d389236c693faa4eba9 (diff)
downloadchat-cd23b8139a9463b67e3096744321f6f4eb0ca40a.tar.gz
chat-cd23b8139a9463b67e3096744321f6f4eb0ca40a.tar.bz2
chat-cd23b8139a9463b67e3096744321f6f4eb0ca40a.zip
[PLT-4843] Add CLI tool for deleting channels (#6430)
* rename delete channel to archive channel * add Permanently delete the channels * fix typo
Diffstat (limited to 'cmd')
-rw-r--r--cmd/platform/channel.go53
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)