From bf9dbd818eaf1b70757781becb575e21b15482e7 Mon Sep 17 00:00:00 2001 From: Hugo <10965479+hugoghx@users.noreply.github.com> Date: Fri, 16 Aug 2024 15:28:20 +0100 Subject: [PATCH] chore(cmd): Remove IntVar and move to Int64Var --- internal/cmd/base/base.go | 2 +- internal/cmd/base/flags.go | 64 ------------------------ internal/cmd/base/servers.go | 6 +-- internal/cmd/commands/connect/connect.go | 4 +- internal/cmd/commands/dev/dev.go | 12 ++--- internal/cmd/common/flags.go | 2 +- 6 files changed, 13 insertions(+), 77 deletions(-) diff --git a/internal/cmd/base/base.go b/internal/cmd/base/base.go index 880c100c8a..3380850fe6 100644 --- a/internal/cmd/base/base.go +++ b/internal/cmd/base/base.go @@ -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 diff --git a/internal/cmd/base/flags.go b/internal/cmd/base/flags.go index 0a6e717f33..b6080b0756 100644 --- a/internal/cmd/base/flags.go +++ b/internal/cmd/base/flags.go @@ -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 diff --git a/internal/cmd/base/servers.go b/internal/cmd/base/servers.go index 2d23dcf58a..6621c384bc 100644 --- a/internal/cmd/base/servers.go +++ b/internal/cmd/base/servers.go @@ -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 diff --git a/internal/cmd/commands/connect/connect.go b/internal/cmd/commands/connect/connect.go index a54d218ccf..dbed3345df 100644 --- a/internal/cmd/commands/connect/connect.go +++ b/internal/cmd/commands/connect/connect.go @@ -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", diff --git a/internal/cmd/commands/dev/dev.go b/internal/cmd/commands/dev/dev.go index 5503ad9004..e2a74511a2 100644 --- a/internal/cmd/commands/dev/dev.go +++ b/internal/cmd/commands/dev/dev.go @@ -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", diff --git a/internal/cmd/common/flags.go b/internal/cmd/common/flags.go index 387cb595cd..9cf79faaaf 100644 --- a/internal/cmd/common/flags.go +++ b/internal/cmd/common/flags.go @@ -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),