summaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorJesús Espino <jespinog@gmail.com>2018-07-24 16:11:47 +0200
committerHarrison Healey <harrisonmhealey@gmail.com>2018-07-24 10:11:47 -0400
commitbfb2640451c95b242ae7b8bb8528538b706412ef (patch)
tree0287dc30c4fa70a3c457371dfd5cfd1a7d91376f /cmd
parentda124f018dbb10a41f4d4b5ecb4818baf628e940 (diff)
downloadchat-bfb2640451c95b242ae7b8bb8528538b706412ef.tar.gz
chat-bfb2640451c95b242ae7b8bb8528538b706412ef.tar.bz2
chat-bfb2640451c95b242ae7b8bb8528538b706412ef.zip
Add idiomatic error handling in mattermost commands (#9147)
Diffstat (limited to 'cmd')
-rw-r--r--cmd/mattermost/commands/config.go8
-rw-r--r--cmd/mattermost/commands/import.go14
-rw-r--r--cmd/mattermost/commands/message_export.go15
3 files changed, 24 insertions, 13 deletions
diff --git a/cmd/mattermost/commands/config.go b/cmd/mattermost/commands/config.go
index d9881b050..b8630b82f 100644
--- a/cmd/mattermost/commands/config.go
+++ b/cmd/mattermost/commands/config.go
@@ -90,9 +90,13 @@ func configSubpathCmdF(command *cobra.Command, args []string) error {
path, err := command.Flags().GetString("path")
if err != nil {
return errors.Wrap(err, "failed reading path")
- } else if path == "" {
+ }
+
+ if path == "" {
return utils.UpdateAssetsSubpathFromConfig(a.Config())
- } else if err := utils.UpdateAssetsSubpath(path); err != nil {
+ }
+
+ if err := utils.UpdateAssetsSubpath(path); err != nil {
return errors.Wrap(err, "failed to update assets subpath")
}
diff --git a/cmd/mattermost/commands/import.go b/cmd/mattermost/commands/import.go
index 8526ba6f8..d376fd61e 100644
--- a/cmd/mattermost/commands/import.go
+++ b/cmd/mattermost/commands/import.go
@@ -125,7 +125,9 @@ func bulkImportCmdF(command *cobra.Command, args []string) error {
if apply && validate {
CommandPrettyPrintln("Use only one of --apply or --validate.")
return nil
- } else if apply && !validate {
+ }
+
+ if apply && !validate {
CommandPrettyPrintln("Running Bulk Import. This may take a long time.")
} else {
CommandPrettyPrintln("Running Bulk Import Data Validation.")
@@ -141,12 +143,12 @@ func bulkImportCmdF(command *cobra.Command, args []string) error {
CommandPrettyPrintln(fmt.Sprintf("Error occurred on data file line %v", lineNumber))
}
return err
+ }
+
+ if apply {
+ CommandPrettyPrintln("Finished Bulk Import.")
} else {
- if apply {
- CommandPrettyPrintln("Finished Bulk Import.")
- } else {
- CommandPrettyPrintln("Validation complete. You can now perform the import by rerunning this command with the --apply flag.")
- }
+ CommandPrettyPrintln("Validation complete. You can now perform the import by rerunning this command with the --apply flag.")
}
return nil
diff --git a/cmd/mattermost/commands/message_export.go b/cmd/mattermost/commands/message_export.go
index ae97eacfb..e7d82a8c1 100644
--- a/cmd/mattermost/commands/message_export.go
+++ b/cmd/mattermost/commands/message_export.go
@@ -78,23 +78,27 @@ func scheduleExportCmdF(command *cobra.Command, args []string) error {
}
// for now, format is hard-coded to actiance. In time, we'll have to support other formats and inject them into job data
- if format, err := command.Flags().GetString("format"); err != nil {
+ format, err := command.Flags().GetString("format")
+ if err != nil {
return errors.New("format flag error")
- } else if format != "actiance" {
+ }
+ if format != "actiance" {
return errors.New("unsupported export format")
}
startTime, err := command.Flags().GetInt64("exportFrom")
if err != nil {
return errors.New("exportFrom flag error")
- } else if startTime < 0 {
+ }
+ if startTime < 0 {
return errors.New("exportFrom must be a positive integer")
}
timeoutSeconds, err := command.Flags().GetInt("timeoutSeconds")
if err != nil {
return errors.New("timeoutSeconds error")
- } else if timeoutSeconds < 0 {
+ }
+ if timeoutSeconds < 0 {
return errors.New("timeoutSeconds must be a positive integer")
}
@@ -128,7 +132,8 @@ func buildExportCmdF(format string) func(command *cobra.Command, args []string)
startTime, err := command.Flags().GetInt64("exportFrom")
if err != nil {
return errors.New("exportFrom flag error")
- } else if startTime < 0 {
+ }
+ if startTime < 0 {
return errors.New("exportFrom must be a positive integer")
}