Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(load-balancer): show message if none of --server, --label-selector or --ip is set #849

Merged
merged 2 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions internal/cmd/loadbalancer/add_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ var AddTargetCmd = base.Cmd{
labelSelector, _ := cmd.Flags().GetString("label-selector")
ipAddr, _ := cmd.Flags().GetString("ip")

if !util.AnySet(serverIDOrName, labelSelector, ipAddr) {
return fmt.Errorf("specify one of --server, --label-selector, or --ip")
}
if !util.ExactlyOneSet(serverIDOrName, labelSelector, ipAddr) {
return fmt.Errorf("--server, --label-selector, and --ip are mutually exclusive")
}
Expand Down
3 changes: 3 additions & 0 deletions internal/cmd/loadbalancer/remove_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ var RemoveTargetCmd = base.Cmd{
return fmt.Errorf("Load Balancer not found: %s", idOrName)
}

if !util.AnySet(serverIDOrName, labelSelector, ipAddr) {
return fmt.Errorf("specify one of --server, --label-selector, or --ip")
}
if !util.ExactlyOneSet(serverIDOrName, labelSelector, ipAddr) {
return fmt.Errorf("--server, --label-selector, and --ip are mutually exclusive")
}
Expand Down
9 changes: 9 additions & 0 deletions internal/cmd/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ func ChainRunE(fns ...func(cmd *cobra.Command, args []string) error) func(cmd *c
}
}

func AnySet(s string, ss ...string) bool {
for _, s := range append(ss, s) {
if s != "" {
return true
}
}
return false
}
jooola marked this conversation as resolved.
Show resolved Hide resolved

func ExactlyOneSet(s string, ss ...string) bool {
set := s != ""
for _, s := range ss {
Expand Down