prysm-pulse/cmd/flags/enum.go
Nishant Das 76ed634f73
Capella E2E (#11951)
* save changes

* fix build

* fix build

* fix signatures

* fix

* fix

* finally fix it

* mainnet

* deps

* make it 10

* back to phase0

* fix build

* gofmt

* etherbase

* rm logs

* build

* james review

* fix yaml

* Update testing/endtoend/evaluators/fork.go

Co-authored-by: Radosław Kapka <rkapka@wp.pl>

* radek's review

---------

Co-authored-by: Radosław Kapka <rkapka@wp.pl>
2023-02-10 14:19:15 +08:00

48 lines
977 B
Go

package flags
// via https://github.com/urfave/cli/issues/602
import (
"fmt"
"strings"
"github.com/urfave/cli/v2"
)
// EnumValue allows the cli to present a fixed set of string values.
type EnumValue struct {
Name string
Usage string
Destination *string
Enum []string
Value string
}
func (e *EnumValue) Set(value string) error {
for _, enum := range e.Enum {
if enum == value {
*e.Destination = value
return nil
}
}
return fmt.Errorf("allowed values are %s", strings.Join(e.Enum, ", "))
}
func (e *EnumValue) String() string {
if e.Destination == nil {
return e.Value
}
if *e.Destination == "" {
return e.Value
}
return *e.Destination
}
// Wraps the EnumValue in a GenericFlag value so that it satisfies the cli.Flag interface.
func (e EnumValue) GenericFlag() *cli.GenericFlag {
*e.Destination = e.Value
var i cli.Generic = &e
return &cli.GenericFlag{Name: e.Name, Usage: e.Usage, Destination: i, Value: i}
}