Added a small utility method to display warnings when parsing command arguments. (#16441)

* Added a small utility method to display warnings when parsing command arguments

Will print warning if flag is passed after arguments e.g.
vault <command> -a b -c
In this example -c will be interpreted as an argument which may be misleading
This commit is contained in:
Max Coulombe
2022-07-27 14:00:03 -04:00
committed by GitHub
parent a269ca6157
commit 2166d6ecf9
4 changed files with 78 additions and 3 deletions

View File

@@ -5,6 +5,7 @@ import (
"io"
"io/ioutil"
"os"
"strings"
"testing"
"time"
)
@@ -209,3 +210,48 @@ func TestParseFlagFile(t *testing.T) {
})
}
}
func TestArgWarnings(t *testing.T) {
t.Parallel()
cases := []struct {
args []string
expected string
}{
{
[]string{"a", "b", "c"},
"",
},
{
[]string{"a", "-b"},
"-b",
},
{
[]string{"a", "--b"},
"--b",
},
{
[]string{"a-b", "-c"},
"-c",
},
{
[]string{"a", "-b-c"},
"-b-c",
},
{
[]string{"-a", "b"},
"-a",
},
}
for _, tc := range cases {
tc := tc
t.Run(tc.expected, func(t *testing.T) {
warnings := generateFlagWarnings(tc.args)
if !strings.Contains(warnings, tc.expected) {
t.Fatalf("expected %s to contain %s", warnings, tc.expected)
}
})
}
}