diff options
author | Shobhit Gupta <smartyshobhit@gmail.com> | 2018-10-23 04:19:10 -0700 |
---|---|---|
committer | George Goldberg <george@gberg.me> | 2018-10-23 12:19:10 +0100 |
commit | c317d6f2656d864a2031d0ac8898a3c46d2c93cc (patch) | |
tree | ff58ed977a0d38d3a7918f8b056f33feea9fe0c4 /cmd/mattermost/commands/command.go | |
parent | 6232ff3738a2e5e52469dc23840bb96385b5d8ea (diff) | |
download | chat-c317d6f2656d864a2031d0ac8898a3c46d2c93cc.tar.gz chat-c317d6f2656d864a2031d0ac8898a3c46d2c93cc.tar.bz2 chat-c317d6f2656d864a2031d0ac8898a3c46d2c93cc.zip |
MM-12356 Add cli command "command delete" (#9553)
* Add cli command for deleting commands
* Add code/test for delete command
* Fix test
* Add confirm flag
* Update as per comments
* Uncomment test
* Fix test
Diffstat (limited to 'cmd/mattermost/commands/command.go')
-rw-r--r-- | cmd/mattermost/commands/command.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/cmd/mattermost/commands/command.go b/cmd/mattermost/commands/command.go index 63f18bed6..bd0bed1fd 100644 --- a/cmd/mattermost/commands/command.go +++ b/cmd/mattermost/commands/command.go @@ -44,6 +44,15 @@ var CommandListCmd = &cobra.Command{ RunE: listCommandCmdF, } +var CommandDeleteCmd = &cobra.Command{ + Use: "delete", + Short: "Delete a slash command", + Long: `Delete a slash command. Commands can be specified by command ID.`, + Example: ` command delete commandID`, + Args: cobra.MinimumNArgs(1), + RunE: deleteCommandCmdF, +} + func init() { CommandCreateCmd.Flags().String("title", "", "Command Title") CommandCreateCmd.Flags().String("description", "", "Command Description") @@ -64,6 +73,7 @@ func init() { CommandCreateCmd, CommandMoveCmd, CommandListCmd, + CommandDeleteCmd, ) RootCmd.AddCommand(CommandCmd) } @@ -204,3 +214,21 @@ func listCommandCmdF(command *cobra.Command, args []string) error { } return nil } + +func deleteCommandCmdF(command *cobra.Command, args []string) error { + a, err := InitDBCommandContextCobra(command) + if err != nil { + return err + } + defer a.Shutdown() + + commandID := args[0] + + deleteErr := a.DeleteCommand(commandID) + if deleteErr != nil { + CommandPrintErrorln("Unable to delete command '" + commandID + "' error: " + deleteErr.Error()) + return deleteErr + } + CommandPrettyPrintln("Deleted command '" + commandID + "'") + return nil +} |