Skip to content

Commit

Permalink
Implements CheckExclusive for flags
Browse files Browse the repository at this point in the history
  • Loading branch information
robschleusner committed Jan 5, 2024
1 parent 10f8f64 commit 473a14b
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -1300,14 +1300,46 @@ func setWhitelist(cfg *quaiconfig.Config) {
// set by the user. Each flag might optionally be followed by a string type to
// specialize it further.
func CheckExclusive(args ...interface{}) {
// TODO: need a way in viper to check if a flag is exclusive
set := make([]string, 0, 1)
for i := 0; i < len(args); i++ {
// Ensure the argument is a string (flag name)
flag, ok := args[i].(Flag)
if !ok {
panic(fmt.Sprintf("invalid argument, not string type: %T", args[i]))
}

// Check if the next arg extends the current flag
if i+1 < len(args) {
switch extension := args[i+1].(type) {
case string:
// Extended flag check
if viper.GetString(flag.Name) == extension {
set = append(set, "--"+flag.Name+"="+extension)
}
i++ // skip the next argument as it's processed
continue
case Flag:
default:
panic(fmt.Sprintf("invalid argument, not string extension: %T", args[i+1]))
}
}

// Check if the flag is set
if viper.IsSet(flag.Name) {
set = append(set, "--"+flag.Name)
}
}

if len(set) > 1 {
Fatalf("Flags %v can't be used at the same time", strings.Join(set, ", "))
}
}

// SetQuaiConfig applies eth-related command line flags to the config.
func SetQuaiConfig(stack *node.Node, cfg *quaiconfig.Config, nodeLocation common.Location) {
// Avoid conflicting network flags
// CheckExclusive(ColosseumFlag, DeveloperFlag, GardenFlag, OrchardFlag, LocalFlag, LighthouseFlag)
// CheckExclusive(DeveloperFlag, ExternalSignerFlag) // Can't use both ephemeral unlocked and external signer
CheckExclusive(ColosseumFlag, DeveloperFlag, GardenFlag, OrchardFlag, LocalFlag, LighthouseFlag)
CheckExclusive(DeveloperFlag, ExternalSignerFlag) // Can't use both ephemeral unlocked and external signer

if viper.GetString(GCModeFlag.Name) == "archive" && viper.GetUint64(TxLookupLimitFlag.Name) != 0 {
// TODO: see what this is supposed to do
Expand Down

0 comments on commit 473a14b

Please sign in to comment.