CliParser.Init() accepts optional flags. Currently una flag is available: ResetOnEqualSign
This commit is contained in:
+12
-4
@@ -49,12 +49,12 @@ func addBoxOption(cli *CliParser, boxPtr *[]int) {
|
||||
})
|
||||
}
|
||||
|
||||
func testIntArrayOptOk(t *testing.T, n int, args []string) {
|
||||
func testIntArrayOptOk(t *testing.T, n int, args []string, flags ...int16) {
|
||||
var box []int
|
||||
var cli CliParser
|
||||
t.Logf("Arg set n. %d", n)
|
||||
addBoxOption(&cli, &box)
|
||||
cli.Init(args, "1.0.0", "TestIntArrayOpt description")
|
||||
cli.Init(args, "1.0.0", "TestIntArrayOpt description", flags...)
|
||||
if err := cli.Parse(); err != nil {
|
||||
t.Error(err)
|
||||
} else if len(box) != 4 {
|
||||
@@ -62,12 +62,12 @@ func testIntArrayOptOk(t *testing.T, n int, args []string) {
|
||||
}
|
||||
}
|
||||
|
||||
func testIntArrayOptKo(t *testing.T, n int, args []string, msg string) {
|
||||
func testIntArrayOptKo(t *testing.T, n int, args []string, msg string, flags ...int16) {
|
||||
var box []int
|
||||
var cli CliParser
|
||||
t.Logf("Arg set n. %d", n)
|
||||
addBoxOption(&cli, &box)
|
||||
cli.Init(args, "1.0.0", "TestIntArrayOpt description")
|
||||
cli.Init(args, "1.0.0", "TestIntArrayOpt description", flags...)
|
||||
if err := cli.Parse(); err == nil {
|
||||
t.Errorf("Expected error, got nil")
|
||||
} else if err.Error() != msg {
|
||||
@@ -132,4 +132,12 @@ func TestIntArrayOpt(t *testing.T) {
|
||||
"--box", "450,12",
|
||||
}
|
||||
testIntArrayOptKo(t, n, args, "--box option requires exactly 4 items, 5 provided")
|
||||
|
||||
n++
|
||||
args = []string{
|
||||
"TestIntArrayOpt",
|
||||
"--box", "100,200,150",
|
||||
"--box=100,200,150,450",
|
||||
}
|
||||
testIntArrayOptOk(t, n, args, ResetOnEqualSign)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user