chore(cmd): Remove IntVar and move to Int64Var
This commit is contained in:
1 parent
3195dcba4e
commit
bf9dbd818e
6 files changed
+13
-77
No files matched your search
@@ -128,7 +128,7 @@ type Command struct {
|
||||
FlagAuthMethodId string
|
||||
FlagHostCatalogId string
|
||||
FlagCredentialStoreId string
|
||||
FlagVersion int
|
||||
FlagVersion int64
|
||||
FlagRecursive bool
|
||||
FlagFilter string
|
||||
FlagTags map[string][]string
|
||||
|
||||
@@ -98,70 +98,6 @@ func (b *boolValue) Example() string { return "" }
|
||||
func (b *boolValue) Hidden() bool { return b.hidden }
|
||||
func (b *boolValue) IsBoolFlag() bool { return true }
|
||||
|
||||
// -- IntVar and intValue
|
||||
type IntVar struct {
|
||||
Name string
|
||||
Aliases []string
|
||||
Usage string
|
||||
Default int
|
||||
Hidden bool
|
||||
EnvVar string
|
||||
Target *int
|
||||
Completion complete.Predictor
|
||||
}
|
||||
|
||||
func (f *FlagSet) IntVar(i *IntVar) {
|
||||
initial := i.Default
|
||||
if v, exist := os.LookupEnv(i.EnvVar); exist {
|
||||
if i, err := strconv.ParseInt(v, 0, 64); err == nil {
|
||||
initial = int(i)
|
||||
}
|
||||
}
|
||||
|
||||
def := ""
|
||||
if i.Default != 0 {
|
||||
def = strconv.FormatInt(int64(i.Default), 10)
|
||||
}
|
||||
|
||||
f.VarFlag(&VarFlag{
|
||||
Name: i.Name,
|
||||
Aliases: i.Aliases,
|
||||
Usage: i.Usage,
|
||||
Default: def,
|
||||
EnvVar: i.EnvVar,
|
||||
Value: newIntValue(initial, i.Target, i.Hidden),
|
||||
Completion: i.Completion,
|
||||
})
|
||||
}
|
||||
|
||||
type intValue struct {
|
||||
hidden bool
|
||||
target *int
|
||||
}
|
||||
|
||||
func newIntValue(def int, target *int, hidden bool) *intValue {
|
||||
*target = def
|
||||
return &intValue{
|
||||
hidden: hidden,
|
||||
target: target,
|
||||
}
|
||||
}
|
||||
|
||||
func (i *intValue) Set(s string) error {
|
||||
v, err := strconv.ParseInt(s, 0, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*i.target = int(v)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *intValue) Get() any { return int(*i.target) }
|
||||
func (i *intValue) String() string { return strconv.Itoa(int(*i.target)) }
|
||||
func (i *intValue) Example() string { return "int" }
|
||||
func (i *intValue) Hidden() bool { return i.hidden }
|
||||
|
||||
// -- Int64Var and int64Value
|
||||
type Int64Var struct {
|
||||
Name string
|
||||
|
||||
@@ -122,9 +122,9 @@ type Server struct {
|
||||
DevSecondaryTargetId string // Target using host sources.
|
||||
DevHostAddress string // Host address for target using host sources.
|
||||
DevTargetAddress string // Network address for target with address.
|
||||
DevTargetDefaultPort int
|
||||
DevTargetSessionMaxSeconds int
|
||||
DevTargetSessionConnectionLimit int
|
||||
DevTargetDefaultPort int64
|
||||
DevTargetSessionMaxSeconds int64
|
||||
DevTargetSessionConnectionLimit int64
|
||||
DevLoopbackPluginId string
|
||||
|
||||
EnabledPlugins []EnabledPlugin
|
||||
|
||||
@@ -62,7 +62,7 @@ type Command struct {
|
||||
|
||||
flagAuthzToken string
|
||||
flagListenAddr string
|
||||
flagListenPort int
|
||||
flagListenPort int64
|
||||
flagTargetId string
|
||||
flagTargetName string
|
||||
flagHostId string
|
||||
@@ -210,7 +210,7 @@ func (c *Command) Flags() *base.FlagSets {
|
||||
Usage: `If set, the CLI will attempt to bind its listening address to the given value, which must be an IP address. If it cannot, the command will error. If not set, defaults to the most common IPv4 loopback address (127.0.0.1).`,
|
||||
})
|
||||
|
||||
f.IntVar(&base.IntVar{
|
||||
f.Int64Var(&base.Int64Var{
|
||||
Name: "listen-port",
|
||||
Target: &c.flagListenPort,
|
||||
EnvVar: "BOUNDARY_CONNECT_LISTEN_PORT",
|
||||
|
||||
@@ -76,9 +76,9 @@ type Command struct {
|
||||
flagIdSuffix string
|
||||
flagSecondaryIdSuffix string
|
||||
flagHostAddress string
|
||||
flagTargetDefaultPort int
|
||||
flagTargetSessionMaxSeconds int
|
||||
flagTargetSessionConnectionLimit int
|
||||
flagTargetDefaultPort int64
|
||||
flagTargetSessionMaxSeconds int64
|
||||
flagTargetSessionConnectionLimit int64
|
||||
flagControllerApiListenAddr string
|
||||
flagControllerClusterListenAddr string
|
||||
flagControllerPublicClusterAddr string
|
||||
@@ -219,7 +219,7 @@ func (c *Command) Flags() *base.FlagSets {
|
||||
Usage: "Address to use for the default host that is created. Must be a bare host or IP address, no port.",
|
||||
})
|
||||
|
||||
f.IntVar(&base.IntVar{
|
||||
f.Int64Var(&base.Int64Var{
|
||||
Name: "target-default-port",
|
||||
Default: 22,
|
||||
Target: &c.flagTargetDefaultPort,
|
||||
@@ -227,7 +227,7 @@ func (c *Command) Flags() *base.FlagSets {
|
||||
Usage: "Default port to use for the default target that is created.",
|
||||
})
|
||||
|
||||
f.IntVar(&base.IntVar{
|
||||
f.Int64Var(&base.Int64Var{
|
||||
Name: "target-session-connection-limit",
|
||||
Target: &c.flagTargetSessionConnectionLimit,
|
||||
Default: -1,
|
||||
@@ -235,7 +235,7 @@ func (c *Command) Flags() *base.FlagSets {
|
||||
Usage: "Maximum number of connections per session to set on the default target. -1 means unlimited.",
|
||||
})
|
||||
|
||||
f.IntVar(&base.IntVar{
|
||||
f.Int64Var(&base.Int64Var{
|
||||
Name: "target-session-max-seconds",
|
||||
Target: &c.flagTargetSessionMaxSeconds,
|
||||
EnvVar: "BOUNDARY_DEV_TARGET_SESSION_MAX_SECONDS",
|
||||
|
||||
@@ -72,7 +72,7 @@ func PopulateCommonFlags(c *base.Command, f *base.FlagSet, resourceType string,
|
||||
Usage: fmt.Sprintf("Description to set on the %s.", resourceType),
|
||||
})
|
||||
case "version":
|
||||
f.IntVar(&base.IntVar{
|
||||
f.Int64Var(&base.Int64Var{
|
||||
Name: "version",
|
||||
Target: &c.FlagVersion,
|
||||
Usage: fmt.Sprintf("The version of the %s against which to perform an update operation. If not specified, the command will perform a check-and-set automatically.", resourceType),
|
||||
|
||||
Reference in new issue
Block a user