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

pull/355/merge
Jeff Mitchell 6 years ago committed by GitHub
parent 41ed95bdec
commit 1f80edbffc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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",
})
}
}

@ -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{

@ -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 {

@ -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 {

@ -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

Loading…
Cancel
Save