prysmctl support generating non-phase0 genesis.ssz (#11677)

* support generating non-phase0 genesis.ssz

* make default (Value) work for EnumValue + lint

* remove messy punctuation

* Ran gazelle for @kasey

* Fix deps viz

Co-authored-by: Kasey Kirkham <kasey@users.noreply.github.com>
Co-authored-by: prestonvanloon <preston@prysmaticlabs.com>
This commit is contained in:
kasey
2022-11-23 08:22:24 -06:00
committed by GitHub
parent ee099d3f03
commit 395e49972e
7 changed files with 143 additions and 6 deletions

9
cmd/flags/BUILD.bazel Normal file
View File

@@ -0,0 +1,9 @@
load("@prysm//tools/go:def.bzl", "go_library")
go_library(
name = "go_default_library",
srcs = ["enum.go"],
importpath = "github.com/prysmaticlabs/prysm/v3/cmd/flags",
visibility = ["//visibility:public"],
deps = ["@com_github_urfave_cli_v2//:go_default_library"],
)

47
cmd/flags/enum.go Normal file
View File

@@ -0,0 +1,47 @@
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}
}