cosmos-sdk/server/pruning.go

41 lines
1.2 KiB
Go
Raw Normal View History

package server
import (
"fmt"
2020-06-22 13:31:33 -07:00
"strings"
"github.com/spf13/cast"
2020-03-20 10:14:14 -07:00
"github.com/cosmos/cosmos-sdk/server/types"
2020-03-20 10:14:14 -07:00
"github.com/cosmos/cosmos-sdk/store"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
)
2020-06-22 13:31:33 -07:00
// 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 types.AppOptions) (storetypes.PruningOptions, error) {
strategy := strings.ToLower(cast.ToString(appOpts.Get(FlagPruning)))
2020-06-22 13:31:33 -07:00
switch strategy {
case storetypes.PruningOptionDefault, storetypes.PruningOptionNothing, storetypes.PruningOptionEverything:
return storetypes.NewPruningOptionsFromString(strategy), nil
case storetypes.PruningOptionCustom:
opts := storetypes.NewPruningOptions(
cast.ToUint64(appOpts.Get(FlagPruningKeepRecent)),
cast.ToUint64(appOpts.Get(FlagPruningKeepEvery)),
cast.ToUint64(appOpts.Get(FlagPruningInterval)),
2020-06-22 13:31:33 -07:00
)
if err := opts.Validate(); err != nil {
return opts, fmt.Errorf("invalid custom pruning options: %w", err)
}
2020-06-22 13:31:33 -07:00
return opts, nil
default:
return store.PruningOptions{}, fmt.Errorf("unknown pruning strategy %s", strategy)
}
}