diff options
author | Chris <ccbrown112@gmail.com> | 2017-11-17 08:27:26 -0600 |
---|---|---|
committer | enahum <nahumhbl@gmail.com> | 2017-11-17 11:27:26 -0300 |
commit | 065d8e97313b9c8ffad37862665186668c88499f (patch) | |
tree | e59810898b9bfab1e5591a72373330b0a4454dc3 /cmd/platform/config.go | |
parent | eb1a00ef5f93b19c2d49b26de057ee2c51c09e45 (diff) | |
download | chat-065d8e97313b9c8ffad37862665186668c88499f.tar.gz chat-065d8e97313b9c8ffad37862665186668c88499f.tar.bz2 chat-065d8e97313b9c8ffad37862665186668c88499f.zip |
make `config validate` exit with non-zero code on failure (#7855)
Diffstat (limited to 'cmd/platform/config.go')
-rw-r--r-- | cmd/platform/config.go | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/cmd/platform/config.go b/cmd/platform/config.go index 6a3df0ade..0b3f26ee0 100644 --- a/cmd/platform/config.go +++ b/cmd/platform/config.go @@ -20,7 +20,8 @@ var configCmd = &cobra.Command{ var validateConfigCmd = &cobra.Command{ Use: "validate", Short: "Validate config file", - Run: configValidateCmdF, + Long: "If the config file is valid, this command will output a success message and have a zero exit code. If it is invalid, this command will output an error and have a non-zero exit code.", + RunE: configValidateCmdF, } func init() { @@ -29,39 +30,35 @@ func init() { ) } -func configValidateCmdF(cmd *cobra.Command, args []string) { +func configValidateCmdF(cmd *cobra.Command, args []string) error { utils.TranslationsPreInit() filePath, err := cmd.Flags().GetString("config") if err != nil { - CommandPrintErrorln(err) - return + return err } filePath = utils.FindConfigFile(filePath) file, err := os.Open(filePath) if err != nil { - CommandPrintErrorln(err) - return + return err } decoder := json.NewDecoder(file) config := model.Config{} err = decoder.Decode(&config) if err != nil { - CommandPrintErrorln(err) - return + return err } if _, err := file.Stat(); err != nil { - CommandPrintErrorln(err) - return + return err } if err := config.IsValid(); err != nil { - CommandPrintErrorln(errors.New(utils.T(err.Id))) - return + return errors.New(utils.T(err.Id)) } CommandPrettyPrintln("The document is valid") + return nil } |