Skip to content

Commit

Permalink
feat: add validate-config command (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
freak12techno committed May 15, 2024
1 parent c1aded7 commit ae32786
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions cmd/missed-blocks-checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"main/pkg"
configPkg "main/pkg/config"
"main/pkg/fs"
"main/pkg/logger"
"os"
Expand All @@ -24,21 +25,45 @@ func (fs *OsFS) Create(path string) (fs.File, error) {
return os.Create(path)
}

func Execute(configPath string) {
func ExecuteMain(configPath string) {
filesystem := &OsFS{}
app := pkg.NewApp(configPath, filesystem, version)
app.Start()
}

func ExecuteValidateConfig(configPath string) {
filesystem := &OsFS{}

config, err := configPkg.GetConfig(configPath, filesystem)
if err != nil {
logger.GetDefaultLogger().Fatal().Err(err).Msg("Could not load config!")
}

if err := config.Validate(); err != nil {
logger.GetDefaultLogger().Fatal().Err(err).Msg("Config is invalid!")
}

logger.GetDefaultLogger().Info().Msg("Provided config is valid.")
}

func main() {
var ConfigPath string

rootCmd := &cobra.Command{
Use: "missed-blocks-checker",
Use: "missed-blocks-checker --config [config path]",
Long: "Monitors validators' missed blocks on Cosmos chains.",
Version: version,
Run: func(cmd *cobra.Command, args []string) {
Execute(ConfigPath)
ExecuteMain(ConfigPath)
},
}

validateConfigCmd := &cobra.Command{
Use: "validate-config --config [config path]",
Long: "Validate config.",
Version: version,
Run: func(cmd *cobra.Command, args []string) {
ExecuteValidateConfig(ConfigPath)
},
}

Expand All @@ -47,6 +72,13 @@ func main() {
logger.GetDefaultLogger().Fatal().Err(err).Msg("Could not set flag as required")
}

validateConfigCmd.PersistentFlags().StringVar(&ConfigPath, "config", "", "Config file path")
if err := validateConfigCmd.MarkPersistentFlagRequired("config"); err != nil {
logger.GetDefaultLogger().Fatal().Err(err).Msg("Could not set flag as required")
}

rootCmd.AddCommand(validateConfigCmd)

if err := rootCmd.Execute(); err != nil {
logger.GetDefaultLogger().Fatal().Err(err).Msg("Could not start application")
}
Expand Down

0 comments on commit ae32786

Please sign in to comment.