[cmd] added all flags

pull/3278/head
Jacky Wang 4 years ago
parent 94b2d75923
commit 9dabfd24ad
No known key found for this signature in database
GPG Key ID: 1085CE5F4FF5842C
  1. 17
      cmd/harmony/config.go
  2. 87
      cmd/harmony/general_flag.go

@ -93,8 +93,9 @@ type devnetConfig struct {
HmyNodeSize int HmyNodeSize int
} }
// TODO: make this revert a seperate command // TODO: make this revert to a seperate command
type revertConfig struct { type revertConfig struct {
RevertBeacon bool
RevertTo int RevertTo int
RevertBefore int RevertBefore int
} }
@ -155,6 +156,20 @@ var defaultDevnetConfig = devnetConfig{
HmyNodeSize: -1, HmyNodeSize: -1,
} }
var defaultRevertConfig = revertConfig{
RevertBeacon: false,
RevertBefore: -1,
RevertTo: -1,
}
func getDefaultDevnetConfigCopy() devnetConfig {
return defaultDevnetConfig
}
func getDefaultRevertConfigCopy() revertConfig {
return defaultRevertConfig
}
const ( const (
blsPassTypeAuto = "auto" blsPassTypeAuto = "auto"
blsPassTypeFile = "file" blsPassTypeFile = "file"

@ -342,7 +342,8 @@ var (
func applyDevnetFlags(cmd *cobra.Command, config *hmyConfig) { func applyDevnetFlags(cmd *cobra.Command, config *hmyConfig) {
if cli.HasFlagsChanged(cmd, devnetFlags) && config.Devnet != nil { if cli.HasFlagsChanged(cmd, devnetFlags) && config.Devnet != nil {
config.Devnet = &defaultDevnetConfig devnet := getDefaultDevnetConfigCopy()
config.Devnet = &devnet
} }
if cli.HasFlagsChanged(cmd, newDevnetFlags) { if cli.HasFlagsChanged(cmd, newDevnetFlags) {
@ -369,6 +370,90 @@ func applyDevnetFlags(cmd *cobra.Command, config *hmyConfig) {
} }
} }
var revertFlags = append(newRevertFlags, legacyRevertFlags...)
var newRevertFlags = []cli.Flag{
revertBeaconFlag,
revertToFlag,
revertBeforeFlag,
}
var legacyRevertFlags = []cli.Flag{
legacyRevertBeaconFlag,
legacyRevertBeforeFlag,
legacyRevertToFlag,
}
var (
revertBeaconFlag = cli.BoolFlag{
Name: "revert.beacon",
Usage: "revert the beacon chain",
DefValue: defaultRevertConfig.RevertBeacon,
Hidden: true,
}
revertToFlag = cli.IntFlag{
Name: "revert.to",
Usage: "rollback all blocks until and including block number revert_to",
DefValue: defaultRevertConfig.RevertTo,
Hidden: true,
}
revertBeforeFlag = cli.IntFlag{
Name: "revert.do-before",
Usage: "if the current block is less than do_revert_before, revert all blocks until (including) revert_to block",
DefValue: defaultRevertConfig.RevertBefore,
Hidden: true,
}
legacyRevertBeaconFlag = cli.BoolFlag{
Name: "revert_beacon",
Usage: "whether to revert beacon chain or the chain this node is assigned to",
DefValue: defaultRevertConfig.RevertBeacon,
Deprecated: "use --revert.beacon",
}
legacyRevertBeforeFlag = cli.IntFlag{
Name: "do_revert_before",
Usage: "If the current block is less than do_revert_before, revert all blocks until (including) revert_to block",
DefValue: defaultRevertConfig.RevertBefore,
Deprecated: "use --revert.do-before",
}
legacyRevertToFlag = cli.IntFlag{
Name: "revert_to",
Usage: "The revert will rollback all blocks until and including block number revert_to",
DefValue: defaultRevertConfig.RevertTo,
Deprecated: "use --revert.to",
}
)
func applyRevertFlags(cmd *cobra.Command, config *hmyConfig) {
if cli.HasFlagsChanged(cmd, revertFlags) {
revert := getDefaultRevertConfigCopy()
config.Revert = &revert
}
if cli.HasFlagsChanged(cmd, newRevertFlags) {
if cli.IsFlagChanged(cmd, revertBeaconFlag) {
config.Revert.RevertBeacon = cli.GetBoolFlagValue(cmd, revertBeaconFlag)
}
if cli.IsFlagChanged(cmd, revertBeforeFlag) {
config.Revert.RevertBefore = cli.GetIntFlagValue(cmd, revertBeforeFlag)
}
if cli.IsFlagChanged(cmd, revertToFlag) {
config.Revert.RevertTo = cli.GetIntFlagValue(cmd, revertToFlag)
}
}
if cli.HasFlagsChanged(cmd, legacyRevertFlags) {
if cli.IsFlagChanged(cmd, legacyRevertBeaconFlag) {
config.Revert.RevertBeacon = cli.GetBoolFlagValue(cmd, legacyRevertBeaconFlag)
}
if cli.IsFlagChanged(cmd, legacyRevertBeforeFlag) {
config.Revert.RevertBefore = cli.GetIntFlagValue(cmd, legacyRevertBeforeFlag)
}
if cli.IsFlagChanged(cmd, legacyRevertToFlag) {
config.Revert.RevertTo = cli.GetIntFlagValue(cmd, legacyRevertToFlag)
}
}
}
// legacyMiscFlags are legacy flags that cannot be categorized to a single category. // legacyMiscFlags are legacy flags that cannot be categorized to a single category.
var legacyMiscFlags = []cli.Flag{ var legacyMiscFlags = []cli.Flag{
legacyPortFlag, legacyPortFlag,

Loading…
Cancel
Save