mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
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:
9
cmd/flags/BUILD.bazel
Normal file
9
cmd/flags/BUILD.bazel
Normal 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
47
cmd/flags/enum.go
Normal 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}
|
||||
}
|
||||
Reference in New Issue
Block a user