mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-10-30 18:17:55 +00:00
backport of commit c93f4aa6d0 (#20543)
Co-authored-by: Hamid Ghaf <83242695+hghaf099@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
6a1e24e124
commit
a6c5b15390
3
changelog/20502.txt
Normal file
3
changelog/20502.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
```release-note:bug
|
||||||
|
cli: disable printing flags warnings messages for the ssh command
|
||||||
|
```
|
||||||
@@ -585,6 +585,7 @@ func (f *FlagSets) Completions() complete.Flags {
|
|||||||
type (
|
type (
|
||||||
ParseOptions interface{}
|
ParseOptions interface{}
|
||||||
ParseOptionAllowRawFormat bool
|
ParseOptionAllowRawFormat bool
|
||||||
|
DisableDisplayFlagWarning bool
|
||||||
)
|
)
|
||||||
|
|
||||||
// Parse parses the given flags, returning any errors.
|
// Parse parses the given flags, returning any errors.
|
||||||
@@ -592,10 +593,18 @@ type (
|
|||||||
func (f *FlagSets) Parse(args []string, opts ...ParseOptions) error {
|
func (f *FlagSets) Parse(args []string, opts ...ParseOptions) error {
|
||||||
err := f.mainSet.Parse(args)
|
err := f.mainSet.Parse(args)
|
||||||
|
|
||||||
|
displayFlagWarningsDisabled := false
|
||||||
|
for _, opt := range opts {
|
||||||
|
if value, ok := opt.(DisableDisplayFlagWarning); ok {
|
||||||
|
displayFlagWarningsDisabled = bool(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !displayFlagWarningsDisabled {
|
||||||
warnings := generateFlagWarnings(f.Args())
|
warnings := generateFlagWarnings(f.Args())
|
||||||
if warnings != "" && Format(f.ui) == "table" {
|
if warnings != "" && Format(f.ui) == "table" {
|
||||||
f.ui.Warn(warnings)
|
f.ui.Warn(warnings)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -238,7 +238,7 @@ type SSHCredentialResp struct {
|
|||||||
func (c *SSHCommand) Run(args []string) int {
|
func (c *SSHCommand) Run(args []string) int {
|
||||||
f := c.Flags()
|
f := c.Flags()
|
||||||
|
|
||||||
if err := f.Parse(args); err != nil {
|
if err := f.Parse(args, DisableDisplayFlagWarning(true)); err != nil {
|
||||||
c.UI.Error(err.Error())
|
c.UI.Error(err.Error())
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package command
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/mitchellh/cli"
|
"github.com/mitchellh/cli"
|
||||||
@@ -214,3 +215,18 @@ func TestIsSingleSSHArg(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestSSHCommandOmitFlagWarning checks if flags warning messages are printed
|
||||||
|
// in the output of the CLI command or not. If so, it will fail.
|
||||||
|
func TestSSHCommandOmitFlagWarning(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
ui, cmd := testSSHCommand(t)
|
||||||
|
|
||||||
|
_ = cmd.Run([]string{"-mode", "ca", "-role", "otp_key_role", "user@1.2.3.4", "-extraFlag", "bug"})
|
||||||
|
|
||||||
|
combined := ui.OutputWriter.String() + ui.ErrorWriter.String()
|
||||||
|
if strings.Contains(combined, "Command flags must be provided before positional arguments. The following arguments will not be parsed as flags") {
|
||||||
|
t.Fatalf("ssh command displayed flag warnings")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user