From 1b2f73d1d44de2379b55d1122d86f6838f81023a Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Mon, 14 Sep 2020 12:45:56 -0400 Subject: [PATCH] Fix some old logic in some CLI commands (#357) --- internal/cmd/commands/groups/group.go | 11 +++++------ internal/cmd/commands/hostsets/hostset.go | 16 +++++++--------- internal/cmd/commands/roles/role.go | 20 ++++++++------------ internal/cmd/commands/targets/target.go | 16 +++++++--------- 4 files changed, 27 insertions(+), 36 deletions(-) diff --git a/internal/cmd/commands/groups/group.go b/internal/cmd/commands/groups/group.go index d25f85ac0..1fbd36b75 100644 --- a/internal/cmd/commands/groups/group.go +++ b/internal/cmd/commands/groups/group.go @@ -135,15 +135,14 @@ func (c *Command) Run(args []string) int { case "set-members": switch len(c.flagMembers) { case 0: - case 1: - if c.flagMembers[0] == "null" { - members = []string{} - } - } - if members == nil { c.UI.Error("No members supplied via -member") return 1 + case 1: + if c.flagMembers[0] == "null" { + members = nil + } } + } groupClient := groups.NewClient(client) diff --git a/internal/cmd/commands/hostsets/hostset.go b/internal/cmd/commands/hostsets/hostset.go index 078a90c4f..35ceb8757 100644 --- a/internal/cmd/commands/hostsets/hostset.go +++ b/internal/cmd/commands/hostsets/hostset.go @@ -218,14 +218,12 @@ func (c *Command) Run(args []string) int { case "set-hosts": switch len(c.flagHosts) { case 0: - case 1: - if c.flagHosts[0] == "null" { - hosts = []string{} - } - } - if hosts == nil { c.UI.Error("No hosts supplied via -host") return 1 + case 1: + if c.flagHosts[0] == "null" { + hosts = nil + } } } @@ -259,11 +257,11 @@ func (c *Command) Run(args []string) int { case "list": listedSets, apiErr, err = hostsetClient.List(c.Context, c.flagHostCatalogId, opts...) case "add-hosts": - set, apiErr, err = hostsetClient.AddHosts(c.Context, c.FlagId, version, c.flagHosts, opts...) + set, apiErr, err = hostsetClient.AddHosts(c.Context, c.FlagId, version, hosts, opts...) case "remove-hosts": - set, apiErr, err = hostsetClient.RemoveHosts(c.Context, c.FlagId, version, c.flagHosts, opts...) + set, apiErr, err = hostsetClient.RemoveHosts(c.Context, c.FlagId, version, hosts, opts...) case "set-hosts": - set, apiErr, err = hostsetClient.SetHosts(c.Context, c.FlagId, version, c.flagHosts, opts...) + set, apiErr, err = hostsetClient.SetHosts(c.Context, c.FlagId, version, hosts, opts...) } plural := "host set" diff --git a/internal/cmd/commands/roles/role.go b/internal/cmd/commands/roles/role.go index c775fd9a4..f1a02e0bb 100644 --- a/internal/cmd/commands/roles/role.go +++ b/internal/cmd/commands/roles/role.go @@ -160,27 +160,23 @@ func (c *Command) Run(args []string) int { case "set-principals": switch len(c.flagPrincipals) { case 0: - case 1: - if c.flagPrincipals[0] == "null" { - principals = []string{} - } - } - if principals == nil { c.UI.Error("No principals supplied via -principal") return 1 + case 1: + if c.flagPrincipals[0] == "null" { + principals = nil + } } case "set-grants": switch len(c.flagGrants) { case 0: - case 1: - if c.flagGrants[0] == "null" { - grants = []string{} - } - } - if grants == nil { c.UI.Error("No grants supplied via -grant") return 1 + case 1: + if c.flagGrants[0] == "null" { + grants = nil + } } } diff --git a/internal/cmd/commands/targets/target.go b/internal/cmd/commands/targets/target.go index 559dab31c..2a94f182c 100644 --- a/internal/cmd/commands/targets/target.go +++ b/internal/cmd/commands/targets/target.go @@ -212,14 +212,12 @@ func (c *Command) Run(args []string) int { case "set-host-sets": switch len(c.flagHostSets) { case 0: - case 1: - if c.flagHostSets[0] == "null" { - hostSets = []string{} - } - } - if hostSets == nil { c.UI.Error("No host-sets supplied via -host-set") return 1 + case 1: + if c.flagHostSets[0] == "null" { + hostSets = nil + } } } @@ -253,11 +251,11 @@ func (c *Command) Run(args []string) int { case "list": listedCatalogs, apiErr, err = targetClient.List(c.Context, c.FlagScopeId, opts...) case "add-host-sets": - target, apiErr, err = targetClient.AddHostSets(c.Context, c.FlagId, version, c.flagHostSets, opts...) + target, apiErr, err = targetClient.AddHostSets(c.Context, c.FlagId, version, hostSets, opts...) case "remove-host-sets": - target, apiErr, err = targetClient.RemoveHostSets(c.Context, c.FlagId, version, c.flagHostSets, opts...) + target, apiErr, err = targetClient.RemoveHostSets(c.Context, c.FlagId, version, hostSets, opts...) case "set-host-sets": - target, apiErr, err = targetClient.SetHostSets(c.Context, c.FlagId, version, c.flagHostSets, opts...) + target, apiErr, err = targetClient.SetHostSets(c.Context, c.FlagId, version, hostSets, opts...) } plural := "target"