Add missing default-port flag to targets command (#355)

This commit is contained in:
Jeff Mitchell authored and GitHub committed 2020-09-12 14:06:28 -04:00
1 parent 41ed95bdec
commit 1f80edbffc
5 files changed
+36 -24

No files matched your search

+2 -5
View File
@@ -92,10 +92,7 @@ func (c *Command) Flags() *base.FlagSets {
set := c.FlagSet(base.FlagSetHTTP | base.FlagSetClient | base.FlagSetOutputFormat)
f := set.NewFlagSet("Command Options")
if len(flagsMap[c.Func]) > 0 {
common.PopulateCommonFlags(c.Command, f, resource.Host.String(), flagsMap[c.Func])
}
common.PopulateCommonFlags(c.Command, f, resource.Host.String(), flagsMap[c.Func])
for _, name := range flagsMap[c.Func] {
switch name {
@@ -103,7 +100,7 @@ func (c *Command) Flags() *base.FlagSets {
f.StringVar(&base.StringVar{
Name: "host-catalog-id",
Target: &c.flagHostCatalogId,
Usage: "The host-catalog resource in which to create or update the host resource",
Usage: "The host-catalog resource in which to list host resources",
})
}
}
+2 -5
View File
@@ -132,10 +132,7 @@ func (c *Command) Flags() *base.FlagSets {
set := c.FlagSet(base.FlagSetHTTP | base.FlagSetClient | base.FlagSetOutputFormat)
f := set.NewFlagSet("Command Options")
if len(flagsMap[c.Func]) > 0 {
common.PopulateCommonFlags(c.Command, f, resource.HostSet.String(), flagsMap[c.Func])
}
common.PopulateCommonFlags(c.Command, f, resource.HostSet.String(), flagsMap[c.Func])
for _, name := range flagsMap[c.Func] {
switch name {
@@ -143,7 +140,7 @@ func (c *Command) Flags() *base.FlagSets {
f.StringVar(&base.StringVar{
Name: "host-catalog-id",
Target: &c.flagHostCatalogId,
Usage: "The host-catalog resource in which to create or update the host-set resource",
Usage: "The host-catalog resource in which to list host-set resources",
})
case "host":
f.StringSliceVar(&base.StringSliceVar{
+1 -4
View File
@@ -66,10 +66,7 @@ func (c *StaticCommand) Flags() *base.FlagSets {
set := c.FlagSet(base.FlagSetHTTP | base.FlagSetClient | base.FlagSetOutputFormat)
f := set.NewFlagSet("Command Options")
if len(staticFlagsMap[c.Func]) > 0 {
common.PopulateCommonFlags(c.Command, f, "static-type host-set", staticFlagsMap[c.Func])
}
common.PopulateCommonFlags(c.Command, f, "static-type host-set", staticFlagsMap[c.Func])
for _, name := range staticFlagsMap[c.Func] {
switch name {
+1 -4
View File
@@ -126,10 +126,7 @@ func (c *Command) Flags() *base.FlagSets {
set := c.FlagSet(base.FlagSetHTTP | base.FlagSetClient | base.FlagSetOutputFormat)
f := set.NewFlagSet("Command Options")
if len(flagsMap[c.Func]) > 0 {
common.PopulateCommonFlags(c.Command, f, resource.Target.String(), flagsMap[c.Func])
}
common.PopulateCommonFlags(c.Command, f, resource.Target.String(), flagsMap[c.Func])
for _, name := range flagsMap[c.Func] {
switch name {
+30 -6
View File
@@ -3,6 +3,7 @@ package targets
import (
"fmt"
"net/textproto"
"strconv"
"github.com/hashicorp/boundary/api"
"github.com/hashicorp/boundary/api/targets"
@@ -20,7 +21,8 @@ var _ cli.CommandAutocomplete = (*TcpCommand)(nil)
type TcpCommand struct {
*base.Command
Func string
Func string
flagDefaultPort string
}
func (c *TcpCommand) Synopsis() string {
@@ -28,8 +30,8 @@ func (c *TcpCommand) Synopsis() string {
}
var tcpFlagsMap = map[string][]string{
"create": {"scope-id", "name", "description"},
"update": {"id", "name", "description", "version"},
"create": {"scope-id", "name", "description", "default-port"},
"update": {"id", "name", "description", "version", "default-port"},
}
func (c *TcpCommand) Help() string {
@@ -63,9 +65,18 @@ func (c *TcpCommand) Help() string {
func (c *TcpCommand) Flags() *base.FlagSets {
set := c.FlagSet(base.FlagSetHTTP | base.FlagSetClient | base.FlagSetOutputFormat)
if len(tcpFlagsMap[c.Func]) > 0 {
f := set.NewFlagSet("Command Options")
common.PopulateCommonFlags(c.Command, f, "tcp-type target", tcpFlagsMap[c.Func])
f := set.NewFlagSet("Command Options")
common.PopulateCommonFlags(c.Command, f, "tcp-type target", tcpFlagsMap[c.Func])
for _, name := range flagsMap[c.Func] {
switch name {
case "default-port":
f.StringVar(&base.StringVar{
Name: "default-port",
Target: &c.flagDefaultPort,
Usage: "The default port to set on the target.",
})
}
}
return set
@@ -124,6 +135,19 @@ func (c *TcpCommand) Run(args []string) int {
opts = append(opts, targets.WithDescription(c.FlagDescription))
}
switch c.flagDefaultPort {
case "":
case "null":
opts = append(opts, targets.DefaultDefaultPort())
default:
length, err := strconv.ParseUint(c.flagDefaultPort, 10, 32)
if err != nil {
c.UI.Error(fmt.Sprintf("Error parsing %q: %s", c.flagDefaultPort, err))
return 1
}
opts = append(opts, targets.WithDefaultPort(uint32(length)))
}
targetClient := targets.NewClient(client)
// Perform check-and-set when needed