* init commit * remove viper from tm cmds * updates * Undo x/bank/client/cli/tx.go * Fix unit tests * lint++ * rename var * Fix genutil test * fix test * prefer cmd.Flags() over direct viper usage * update * fix ABCI error tests * fix integration tests * Add viper to context * fix build * fix unit test * Implement and use AppOptions * Revert Redact godoc Co-authored-by: Alessio Treglia <alessio@tendermint.com>
40 lines
1.2 KiB
Go
40 lines
1.2 KiB
Go
package server
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/spf13/cast"
|
|
|
|
"github.com/cosmos/cosmos-sdk/store"
|
|
"github.com/cosmos/cosmos-sdk/store/types"
|
|
)
|
|
|
|
// GetPruningOptionsFromFlags parses command flags and returns the correct
|
|
// PruningOptions. If a pruning strategy is provided, that will be parsed and
|
|
// returned, otherwise, it is assumed custom pruning options are provided.
|
|
func GetPruningOptionsFromFlags(appOpts AppOptions) (types.PruningOptions, error) {
|
|
strategy := strings.ToLower(cast.ToString(appOpts.Get(FlagPruning)))
|
|
|
|
switch strategy {
|
|
case types.PruningOptionDefault, types.PruningOptionNothing, types.PruningOptionEverything:
|
|
return types.NewPruningOptionsFromString(strategy), nil
|
|
|
|
case types.PruningOptionCustom:
|
|
opts := types.NewPruningOptions(
|
|
cast.ToUint64(appOpts.Get(FlagPruningKeepRecent)),
|
|
cast.ToUint64(appOpts.Get(FlagPruningKeepEvery)),
|
|
cast.ToUint64(appOpts.Get(FlagPruningInterval)),
|
|
)
|
|
|
|
if err := opts.Validate(); err != nil {
|
|
return opts, fmt.Errorf("invalid custom pruning options: %w", err)
|
|
}
|
|
|
|
return opts, nil
|
|
|
|
default:
|
|
return store.PruningOptions{}, fmt.Errorf("unknown pruning strategy %s", strategy)
|
|
}
|
|
}
|