Skip to content

Commit

Permalink
misc!(flags): rename core.grpc.port to core.port (#4059)
Browse files Browse the repository at this point in the history
  • Loading branch information
vgonkivs authored Jan 22, 2025
1 parent 5707592 commit b373287
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
25 changes: 18 additions & 7 deletions nodebuilder/core/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
)

var (
coreFlag = "core.ip"
coreIPFlag = "core.ip"
corePortFlag = "core.port"
coreGRPCFlag = "core.grpc.port"
coreTLS = "core.tls"
coreXTokenPathFlag = "core.xtoken.path" //nolint:gosec
Expand All @@ -19,17 +20,23 @@ func Flags() *flag.FlagSet {
flags := &flag.FlagSet{}

flags.String(
coreFlag,
coreIPFlag,
"",
"Indicates node to connect to the given core node. "+
"Example: <ip>, 127.0.0.1. <dns>, subdomain.domain.tld "+
"Assumes gRPC port 9090 as default unless otherwise specified.",
)
flags.String(
coreGRPCFlag,
corePortFlag,
DefaultPort,
"Set a custom gRPC port for the core node connection. The --core.ip flag must also be provided.",
)
flags.String(
coreGRPCFlag,
"",
"Set a custom gRPC port for the core node connection.WARNING: --core.grpc.port is deprecated. "+
"Please use --core.port instead",
)
flags.Bool(
coreTLS,
false,
Expand All @@ -51,16 +58,20 @@ func ParseFlags(
cmd *cobra.Command,
cfg *Config,
) error {
coreIP := cmd.Flag(coreFlag).Value.String()
if cmd.Flag(coreGRPCFlag).Changed {
return fmt.Errorf("the flag is deprecated. Please use --core.port instead")
}

coreIP := cmd.Flag(coreIPFlag).Value.String()
if coreIP == "" {
if cmd.Flag(coreGRPCFlag).Changed {
if cmd.Flag(corePortFlag).Changed {
return fmt.Errorf("cannot specify gRPC port without specifying an IP address for --core.ip")
}
return nil
}

if cmd.Flag(coreGRPCFlag).Changed {
grpc := cmd.Flag(coreGRPCFlag).Value.String()
if cmd.Flag(corePortFlag).Changed {
grpc := cmd.Flag(corePortFlag).Value.String()
cfg.Port = grpc
}

Expand Down
8 changes: 4 additions & 4 deletions nodebuilder/core/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ func TestParseFlags(t *testing.T) {
expectError: false,
},
{
name: "core.ip and core.grpc.port",
args: []string{"--core.ip=127.0.0.1", "--core.grpc.port=54321"},
name: "core.ip and core.port",
args: []string{"--core.ip=127.0.0.1", "--core.port=54321"},
inputCfg: Config{
Port: DefaultPort,
},
Expand All @@ -85,8 +85,8 @@ func TestParseFlags(t *testing.T) {
expectError: false,
},
{
name: "core.grpc.port without core.ip",
args: []string{"--core.grpc.port=54321"},
name: "core.port without core.ip",
args: []string{"--core.port=54321"},
expectedCfg: Config{},
expectError: true,
},
Expand Down

0 comments on commit b373287

Please sign in to comment.