Skip to content

Commit

Permalink
feat: add validate-config command (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
freak12techno authored May 15, 2024
1 parent 8960bf6 commit 3ee0c34
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ linters:
- depguard
- interfacebloat
- perfsprint
- mnd
39 changes: 36 additions & 3 deletions cmd/cosmos-transactions-bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (fs *OsFS) Create(path string) (fs.File, error) {
return os.Create(path)
}

func Execute(configPath string) {
func ExecuteMain(configPath string) {
filesystem := &OsFS{}
config, err := configPkg.GetConfig(configPath, filesystem)
if err != nil {
Expand All @@ -41,15 +41,41 @@ func Execute(configPath string) {
app.Start()
}

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

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

if warnings := config.DisplayWarnings(); len(warnings) > 0 {
for _, warning := range warnings {
warning.Log(loggerPkg.GetDefaultLogger())
}
}

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

func main() {
var ConfigPath string

rootCmd := &cobra.Command{
Use: "cosmos-transactions-bot",
Use: "cosmos-transactions-bot --config [config path]",
Long: "Get notified on new transactions on different cosmos-sdk 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 @@ -58,6 +84,13 @@ func main() {
loggerPkg.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 {
loggerPkg.GetDefaultLogger().Fatal().Err(err).Msg("Could not set flag as required")
}

rootCmd.AddCommand(validateConfigCmd)

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

0 comments on commit 3ee0c34

Please sign in to comment.