-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]> Co-authored-by: prestonvanloon <[email protected]>
- Loading branch information
1 parent
ee099d3
commit 395e499
Showing
7 changed files
with
143 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters