From a6cd6554ecb4966eafdf77654b4899a0e773a914 Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Thu, 27 Feb 2020 12:30:24 +0100 Subject: [PATCH] extract to function logic to check pruning params --- server/start.go | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/server/start.go b/server/start.go index f3e8253e7b..4749edf633 100644 --- a/server/start.go +++ b/server/start.go @@ -63,23 +63,7 @@ For profiling and benchmarking purposes, CPU profiling can be enabled via the '- which accepts a path for the resulting pprof file. `, PreRunE: func(cmd *cobra.Command, args []string) error { - if !viper.IsSet(flagPruning) && !viper.IsSet(flagPruningKeepEvery) && !viper.IsSet(flagPruningSnapshotEvery) { - return errPruningOptionsRequired - } - - if viper.IsSet(flagPruning) { - if viper.IsSet(flagPruningKeepEvery) || viper.IsSet(flagPruningSnapshotEvery) { - return errPruningWithGranularOptions - } - - return nil - } - - if !(viper.IsSet(flagPruningKeepEvery) && viper.IsSet(flagPruningSnapshotEvery)) { - return errPruningGranularOptions - } - - return nil + return checkPruningParams() }, RunE: func(cmd *cobra.Command, args []string) error { if !viper.GetBool(flagWithTendermint) { @@ -114,6 +98,27 @@ which accepts a path for the resulting pprof file. return cmd } +// checkPruningParams checks that the provided pruning params are correct +func checkPruningParams() error { + if !viper.IsSet(flagPruning) && !viper.IsSet(flagPruningKeepEvery) && !viper.IsSet(flagPruningSnapshotEvery) { + return errPruningOptionsRequired + } + + if viper.IsSet(flagPruning) { + if viper.IsSet(flagPruningKeepEvery) || viper.IsSet(flagPruningSnapshotEvery) { + return errPruningWithGranularOptions + } + + return nil + } + + if !(viper.IsSet(flagPruningKeepEvery) && viper.IsSet(flagPruningSnapshotEvery)) { + return errPruningGranularOptions + } + + return nil +} + func startStandAlone(ctx *Context, appCreator AppCreator) error { addr := viper.GetString(flagAddress) home := viper.GetString("home")