Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add validate-config command #61

Merged
merged 1 commit into from
May 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading