chore(cmd): Remove UintVar and move to Uint64Var
This commit is contained in:
1 parent
abb2d50494
commit
3195dcba4e
9 files changed
+10
-74
No files matched your search
@@ -116,7 +116,7 @@ type Command struct {
|
||||
FlagSkipCacheDaemon bool
|
||||
FlagSkipClientAgent bool
|
||||
|
||||
FlagClientAgentPort uint
|
||||
FlagClientAgentPort uint64
|
||||
|
||||
FlagScopeId string
|
||||
FlagScopeName string
|
||||
@@ -500,7 +500,7 @@ func (c *Command) FlagSet(bit FlagSetBit) *FlagSets {
|
||||
Hidden: true,
|
||||
})
|
||||
|
||||
f.UintVar(&UintVar{
|
||||
f.Uint64Var(&Uint64Var{
|
||||
Name: "client-agent-port",
|
||||
Target: &c.FlagClientAgentPort,
|
||||
Default: 9300,
|
||||
|
||||
@@ -226,70 +226,6 @@ func (i *int64Value) String() string { return strconv.FormatInt(int64(*i.target
|
||||
func (i *int64Value) Example() string { return "int" }
|
||||
func (i *int64Value) Hidden() bool { return i.hidden }
|
||||
|
||||
// -- UintVar && uintValue
|
||||
type UintVar struct {
|
||||
Name string
|
||||
Aliases []string
|
||||
Usage string
|
||||
Default uint
|
||||
Hidden bool
|
||||
EnvVar string
|
||||
Target *uint
|
||||
Completion complete.Predictor
|
||||
}
|
||||
|
||||
func (f *FlagSet) UintVar(i *UintVar) {
|
||||
initial := i.Default
|
||||
if v, exist := os.LookupEnv(i.EnvVar); exist {
|
||||
if i, err := strconv.ParseUint(v, 0, 64); err == nil {
|
||||
initial = uint(i)
|
||||
}
|
||||
}
|
||||
|
||||
def := ""
|
||||
if i.Default != 0 {
|
||||
def = strconv.FormatUint(uint64(i.Default), 10)
|
||||
}
|
||||
|
||||
f.VarFlag(&VarFlag{
|
||||
Name: i.Name,
|
||||
Aliases: i.Aliases,
|
||||
Usage: i.Usage,
|
||||
Default: def,
|
||||
EnvVar: i.EnvVar,
|
||||
Value: newUintValue(initial, i.Target, i.Hidden),
|
||||
Completion: i.Completion,
|
||||
})
|
||||
}
|
||||
|
||||
type uintValue struct {
|
||||
hidden bool
|
||||
target *uint
|
||||
}
|
||||
|
||||
func newUintValue(def uint, target *uint, hidden bool) *uintValue {
|
||||
*target = def
|
||||
return &uintValue{
|
||||
hidden: hidden,
|
||||
target: target,
|
||||
}
|
||||
}
|
||||
|
||||
func (i *uintValue) Set(s string) error {
|
||||
v, err := strconv.ParseUint(s, 0, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*i.target = uint(v)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *uintValue) Get() any { return uint(*i.target) }
|
||||
func (i *uintValue) String() string { return strconv.FormatUint(uint64(*i.target), 10) }
|
||||
func (i *uintValue) Example() string { return "uint" }
|
||||
func (i *uintValue) Hidden() bool { return i.hidden }
|
||||
|
||||
// -- Uint64Var and uint64Value
|
||||
type Uint64Var struct {
|
||||
Name string
|
||||
|
||||
@@ -45,7 +45,7 @@ type extraLdapCmdVars struct {
|
||||
flagBindPassword string
|
||||
flagUseTokenGroups bool
|
||||
flagAccountAttributeMaps []string
|
||||
flagMaxPageSize uint
|
||||
flagMaxPageSize uint64
|
||||
flagDerefAliases string
|
||||
}
|
||||
|
||||
@@ -232,7 +232,7 @@ func extraLdapFlagsFuncImpl(c *LdapCommand, set *base.FlagSets, _ *base.FlagSet)
|
||||
Usage: "The desired operational state of the auth method.",
|
||||
})
|
||||
case maxPageSizeFlagName:
|
||||
f.UintVar(&base.UintVar{
|
||||
f.Uint64Var(&base.Uint64Var{
|
||||
Name: maxPageSizeFlagName,
|
||||
Target: &c.flagMaxPageSize,
|
||||
Usage: "MaximumPageSize specifies a maximum search result size to use when retrieving the authenticated user's groups (optional).",
|
||||
|
||||
@@ -30,7 +30,7 @@ type UpsertTokenRequest struct {
|
||||
// The passed in cli.Ui is used to print out any errors when looking up the
|
||||
// auth token from the keyring. This allows background operations calling this
|
||||
// method to pass in a silent UI to suppress any output.
|
||||
func addToken(ctx context.Context, apiClient *api.Client, port uint) (*api.Response, *api.Error, error) {
|
||||
func addToken(ctx context.Context, apiClient *api.Client, port uint64) (*api.Response, *api.Error, error) {
|
||||
pa := UpsertTokenRequest{
|
||||
BoundaryAddr: apiClient.Addr(),
|
||||
}
|
||||
|
||||
@@ -67,6 +67,6 @@ func (c *ClientAgentCommand) Run(args []string) int {
|
||||
}
|
||||
|
||||
// clientAgentUrl constructs the full URL for a client agent request given a port and path.
|
||||
func clientAgentUrl(port uint, path string) string {
|
||||
func clientAgentUrl(port uint64, path string) string {
|
||||
return fmt.Sprintf("http://localhost:%d/%s", port, path)
|
||||
}
|
||||
@@ -53,7 +53,7 @@ func (c *PauseCommand) Flags() *base.FlagSets {
|
||||
Usage: "Instead of executing the request, print an equivalent cURL command string and exit.",
|
||||
})
|
||||
|
||||
f.UintVar(&base.UintVar{
|
||||
f.Uint64Var(&base.Uint64Var{
|
||||
Name: "client-agent--port",
|
||||
Target: &c.FlagClientAgentPort,
|
||||
Default: 9300,
|
||||
|
||||
@@ -53,7 +53,7 @@ func (c *ResumeCommand) Flags() *base.FlagSets {
|
||||
Usage: "Instead of executing the request, print an equivalent cURL command string and exit.",
|
||||
})
|
||||
|
||||
f.UintVar(&base.UintVar{
|
||||
f.Uint64Var(&base.Uint64Var{
|
||||
Name: "client-agent-port",
|
||||
Target: &c.FlagClientAgentPort,
|
||||
Default: 9300,
|
||||
|
||||
@@ -58,7 +58,7 @@ func (c *SessionsCommand) Flags() *base.FlagSets {
|
||||
Usage: "Instead of executing the request, print an equivalent cURL command string and exit.",
|
||||
})
|
||||
|
||||
f.UintVar(&base.UintVar{
|
||||
f.Uint64Var(&base.Uint64Var{
|
||||
Name: "client-agent-port",
|
||||
Target: &c.FlagClientAgentPort,
|
||||
Default: 9300,
|
||||
|
||||
@@ -54,7 +54,7 @@ func (c *StatusCommand) Flags() *base.FlagSets {
|
||||
Usage: "Instead of executing the request, print an equivalent cURL command string and exit.",
|
||||
})
|
||||
|
||||
f.UintVar(&base.UintVar{
|
||||
f.Uint64Var(&base.Uint64Var{
|
||||
Name: "client-agent-port",
|
||||
Target: &c.FlagClientAgentPort,
|
||||
Default: 9300,
|
||||
|
||||
Reference in new issue
Block a user