github.com/cosmos/cosmos-sdk@v0.50.10/server/pruning.go (about) 1 package server 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/spf13/cast" 8 9 pruningtypes "cosmossdk.io/store/pruning/types" 10 11 "github.com/cosmos/cosmos-sdk/server/types" 12 ) 13 14 // GetPruningOptionsFromFlags parses command flags and returns the correct 15 // PruningOptions. If a pruning strategy is provided, that will be parsed and 16 // returned, otherwise, it is assumed custom pruning options are provided. 17 func GetPruningOptionsFromFlags(appOpts types.AppOptions) (pruningtypes.PruningOptions, error) { 18 strategy := strings.ToLower(cast.ToString(appOpts.Get(FlagPruning))) 19 20 switch strategy { 21 case pruningtypes.PruningOptionDefault, pruningtypes.PruningOptionNothing, pruningtypes.PruningOptionEverything: 22 return pruningtypes.NewPruningOptionsFromString(strategy), nil 23 24 case pruningtypes.PruningOptionCustom: 25 opts := pruningtypes.NewCustomPruningOptions( 26 cast.ToUint64(appOpts.Get(FlagPruningKeepRecent)), 27 cast.ToUint64(appOpts.Get(FlagPruningInterval)), 28 ) 29 30 if err := opts.Validate(); err != nil { 31 return opts, fmt.Errorf("invalid custom pruning options: %w", err) 32 } 33 34 return opts, nil 35 36 default: 37 return pruningtypes.PruningOptions{}, fmt.Errorf("unknown pruning strategy %s", strategy) 38 } 39 }