mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
[PLT-4843] Add CLI tool for deleting channels (#6430)
* rename delete channel to archive channel * add Permanently delete the channels * fix typo
This commit is contained in:
committed by
Corey Hulen
parent
9a5f16924c
commit
cd23b8139a
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user