Add CLI tool for validating the config.json file (#6041)
Этот коммит содержится в:
коммит произвёл
Christopher Speller
родитель
80684ad69f
Коммит
f9ac95c920
66
cmd/platform/config.go
Обычный файл
66
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")
|
||||||
|
}
|
||||||
@@ -33,7 +33,7 @@ func init() {
|
|||||||
|
|
||||||
resetCmd.Flags().Bool("confirm", false, "Confirm you really want to delete everything and a DB backup has been performed.")
|
resetCmd.Flags().Bool("confirm", false, "Confirm you really want to delete everything and a DB backup has been performed.")
|
||||||
|
|
||||||
rootCmd.AddCommand(serverCmd, versionCmd, userCmd, teamCmd, licenseCmd, importCmd, resetCmd, channelCmd, rolesCmd, testCmd, ldapCmd)
|
rootCmd.AddCommand(serverCmd, versionCmd, userCmd, teamCmd, licenseCmd, importCmd, resetCmd, channelCmd, rolesCmd, testCmd, ldapCmd, configCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user