diff options
author | Simon Soriano <simon0191@gmail.com> | 2017-04-17 09:44:10 -0500 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2017-04-17 10:44:10 -0400 |
commit | f9ac95c920174728f9f28d273d6ffcd5493faafb (patch) | |
tree | 476b2c1ce621db0902ded0575d17265fab6890b3 /cmd/platform/config.go | |
parent | 80684ad69f641bb759095beff0e1a15db0aa33b1 (diff) | |
download | chat-f9ac95c920174728f9f28d273d6ffcd5493faafb.tar.gz chat-f9ac95c920174728f9f28d273d6ffcd5493faafb.tar.bz2 chat-f9ac95c920174728f9f28d273d6ffcd5493faafb.zip |
Add CLI tool for validating the config.json file (#6041)
Diffstat (limited to 'cmd/platform/config.go')
-rw-r--r-- | cmd/platform/config.go | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/cmd/platform/config.go b/cmd/platform/config.go new file mode 100644 index 000000000..d66129de4 --- /dev/null +++ b/cmd/platform/config.go @@ -0,0 +1,66 @@ +// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. +package main + +import ( + "encoding/json" + "errors" + "github.com/mattermost/platform/model" + "github.com/mattermost/platform/utils" + "github.com/spf13/cobra" + "os" +) + +var configCmd = &cobra.Command{ + Use: "config", + Short: "Configuration", +} + +var validateConfigCmd = &cobra.Command{ + Use: "validate", + Short: "Validate config file", + Run: configValidateCmdF, +} + +func init() { + configCmd.AddCommand( + validateConfigCmd, + ) +} + +func configValidateCmdF(cmd *cobra.Command, args []string) { + utils.TranslationsPreInit() + filePath, err := cmd.Flags().GetString("config") + if err != nil { + CommandPrintErrorln(err) + return + } + + filePath = utils.FindConfigFile(filePath) + + file, err := os.Open(filePath) + if err != nil { + CommandPrintErrorln(err) + return + } + + decoder := json.NewDecoder(file) + config := model.Config{} + err = decoder.Decode(&config) + if err != nil { + CommandPrintErrorln(err) + return + } + + if _, err := file.Stat(); err != nil { + CommandPrintErrorln(err) + return + } + + if err := config.IsValid(); err != nil { + CommandPrintErrorln(errors.New(utils.T(err.Id))) + return + } + + CommandPrettyPrintln("The document is valid") +} |