github.com/Finschia/finschia-sdk@v0.48.1/server/pruning.go (about) 1 package server 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/spf13/cast" 8 9 "github.com/Finschia/finschia-sdk/server/types" 10 "github.com/Finschia/finschia-sdk/store" 11 storetypes "github.com/Finschia/finschia-sdk/store/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) (storetypes.PruningOptions, error) { 18 strategy := strings.ToLower(cast.ToString(appOpts.Get(FlagPruning))) 19 20 switch strategy { 21 case storetypes.PruningOptionDefault, storetypes.PruningOptionNothing, storetypes.PruningOptionEverything: 22 return storetypes.NewPruningOptionsFromString(strategy), nil 23 24 case storetypes.PruningOptionCustom: 25 opts := storetypes.NewPruningOptions( 26 cast.ToUint64(appOpts.Get(FlagPruningKeepRecent)), 27 cast.ToUint64(appOpts.Get(FlagPruningKeepEvery)), 28 cast.ToUint64(appOpts.Get(FlagPruningInterval)), 29 ) 30 31 if err := opts.Validate(); err != nil { 32 return opts, fmt.Errorf("invalid custom pruning options: %w", err) 33 } 34 35 return opts, nil 36 37 default: 38 return store.PruningOptions{}, fmt.Errorf("unknown pruning strategy %s", strategy) 39 } 40 }