mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-10-29 17:52:32 +00:00
VAULT-24050 Fix erroneous warning showing when -address is provided (#27265)
* VAULT-24050 Fix erroneous warning showing when -address is provided * VAULT-24050 changelog
This commit is contained in:
@@ -705,7 +705,7 @@ func (c *Client) SetAddress(addr string) error {
|
||||
|
||||
parsedAddr, err := c.config.ParseAddress(addr)
|
||||
if err != nil {
|
||||
return errwrap.Wrapf("failed to set address: {{err}}", err)
|
||||
return fmt.Errorf("failed to set address: %w", err)
|
||||
}
|
||||
|
||||
c.addr = parsedAddr
|
||||
|
||||
3
changelog/27265.txt
Normal file
3
changelog/27265.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
```release-note:bug
|
||||
cli: Fixed an erroneous warning appearing about `-address` not being set when it is.
|
||||
```
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"regexp"
|
||||
@@ -212,7 +211,7 @@ func (c *BaseCommand) Client() (*api.Client, error) {
|
||||
}
|
||||
|
||||
if c.addrWarning != "" && c.UI != nil {
|
||||
if os.Getenv("VAULT_ADDR") == "" {
|
||||
if os.Getenv("VAULT_ADDR") == "" && !c.flags.hadAddressFlag {
|
||||
if !c.flagNonInteractive && isatty.IsTerminal(os.Stdin.Fd()) {
|
||||
c.UI.Warn(wrapAtLength(c.addrWarning))
|
||||
}
|
||||
@@ -627,6 +626,10 @@ type FlagSets struct {
|
||||
hiddens map[string]struct{}
|
||||
completions complete.Flags
|
||||
ui cli.Ui
|
||||
// hadAddressFlag signals if the FlagSet had an -address
|
||||
// flag set, for the purposes of warning (see also:
|
||||
// BaseCommand::addrWarning).
|
||||
hadAddressFlag bool
|
||||
}
|
||||
|
||||
// NewFlagSets creates a new flag sets.
|
||||
@@ -635,7 +638,7 @@ func NewFlagSets(ui cli.Ui) *FlagSets {
|
||||
|
||||
// Errors and usage are controlled by the CLI.
|
||||
mainSet.Usage = func() {}
|
||||
mainSet.SetOutput(ioutil.Discard)
|
||||
mainSet.SetOutput(io.Discard)
|
||||
|
||||
return &FlagSets{
|
||||
flagSets: make([]*FlagSet, 0, 6),
|
||||
@@ -669,6 +672,15 @@ type (
|
||||
// Parse parses the given flags, returning any errors.
|
||||
// Warnings, if any, regarding the arguments format are sent to stdout
|
||||
func (f *FlagSets) Parse(args []string, opts ...ParseOptions) error {
|
||||
// Before parsing, check to see if we have an address flag, for the
|
||||
// purposes of warning later. This must be done now, as the argument
|
||||
// will be removed during parsing.
|
||||
for _, arg := range args {
|
||||
if strings.HasPrefix(arg, "-address") {
|
||||
f.hadAddressFlag = true
|
||||
}
|
||||
}
|
||||
|
||||
err := f.mainSet.Parse(args)
|
||||
|
||||
displayFlagWarningsDisabled := false
|
||||
|
||||
Reference in New Issue
Block a user