CliParser.Init() accepts optional flags. Currently una flag is available: ResetOnEqualSign

This commit is contained in:
2026-03-06 11:45:58 +01:00
parent 9e28ee6545
commit 00b84278d8
3 changed files with 26 additions and 6 deletions
+12 -4
View File
@@ -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)
}