Skip to content

Commit e3d0a94

Browse files
committed
fix: use switch for nodekey
1 parent 64112d3 commit e3d0a94

File tree

1 file changed

+10
-22
lines changed

1 file changed

+10
-22
lines changed

cmd/nodekey/nodekey.go

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -72,30 +72,16 @@ var NodekeyCmd = &cobra.Command{
7272
inputNodeKeyPrivateKey = *privateKey
7373
},
7474
PreRunE: func(cmd *cobra.Command, args []string) error {
75-
validProtocols := []string{"devp2p", "libp2p", "seed-libp2p"}
76-
ok := slices.Contains(validProtocols, inputNodeKeyProtocol)
77-
if !ok {
78-
return fmt.Errorf("the protocol %s is not implemented", inputNodeKeyProtocol)
79-
}
80-
81-
if inputNodeKeyProtocol == "devp2p" {
75+
switch inputNodeKeyProtocol {
76+
case "devp2p":
8277
invalidFlags := []string{"seed", "marshal-protobuf"}
83-
err := validateNodeKeyFlags(cmd, invalidFlags)
84-
if err != nil {
85-
return err
86-
}
87-
}
88-
if inputNodeKeyProtocol == "libp2p" {
78+
return validateNodeKeyFlags(cmd, invalidFlags)
79+
case "libp2p":
8980
invalidFlags := []string{"file", "ip", "tcp", "udp", "sign", "seed"}
90-
err := validateNodeKeyFlags(cmd, invalidFlags)
91-
if err != nil {
92-
return err
93-
}
94-
}
95-
if inputNodeKeyProtocol == "seed-libp2p" {
81+
return validateNodeKeyFlags(cmd, invalidFlags)
82+
case "seed-libp2p":
9683
invalidFlags := []string{"file", "ip", "tcp", "udp", "sign"}
97-
err := validateNodeKeyFlags(cmd, invalidFlags)
98-
if err != nil {
84+
if err := validateNodeKeyFlags(cmd, invalidFlags); err != nil {
9985
return err
10086
}
10187
if inputNodeKeyType == "rsa" {
@@ -104,8 +90,10 @@ var NodekeyCmd = &cobra.Command{
10490
if inputNodeKeyType == "secp256k1" {
10591
return fmt.Errorf("the secp256k1 key type doesn't support manual key seeding")
10692
}
93+
return nil
94+
default:
95+
return fmt.Errorf("the protocol %s is not implemented", inputNodeKeyProtocol)
10796
}
108-
return nil
10997
},
11098
RunE: func(cmd *cobra.Command, args []string) error {
11199
var nko nodeKeyOut

0 commit comments

Comments
 (0)