11import flag
22
3- const args_bool_short = ['some.exe' , '-h' ]
4- const args_bool_long = ['some.exe' , '-help' ]
3+ const args_bool_short_tail = ['some.exe' , '-h' ]
4+ const args_bool_long_tail = ['some.exe' , '-help' ]
5+
6+ const args_bool_short_mixed = ['some.exe' , '-h' , '-long' , 'val' ]
7+ const args_bool_long_mixed = ['some.exe' , '-help' , '-long' , 'val' ]
58
69struct CliOptions {
710 show_help bool @[long: 'help' ; short: h]
811}
912
10- fn test_short_tail_bool () {
11- cli_options , unmatched := flag.to_struct[CliOptions](args_bool_short,
13+ struct CliOptions2 {
14+ show_help bool @[long: 'help' ; short: h]
15+ long string
16+ }
17+
18+ fn test_v_style_short_tail_bool () {
19+ cli_options , unmatched := flag.to_struct[CliOptions](args_bool_short_tail,
20+ skip: 1
21+ style: .v
22+ mode: .relaxed
23+ )!
24+
25+ if unmatched.len > 0 {
26+ assert false
27+ }
28+ if cli_options.show_help {
29+ assert true
30+ } else {
31+ assert false
32+ }
33+ }
34+
35+ fn test_v_style_long_tail_bool () {
36+ cli_options , unmatched := flag.to_struct[CliOptions](args_bool_long_tail,
37+ skip: 1
38+ style: .v
39+ mode: .relaxed
40+ )!
41+
42+ if unmatched.len > 0 {
43+ assert false
44+ }
45+ if cli_options.show_help {
46+ assert true
47+ } else {
48+ assert false
49+ }
50+ }
51+
52+ fn test_v_style_short_bool () {
53+ cli_options , unmatched := flag.to_struct[CliOptions2 ](args_bool_short_mixed,
1254 skip: 1
1355 style: .v
1456 mode: .relaxed
@@ -22,10 +64,11 @@ fn test_short_tail_bool() {
2264 } else {
2365 assert false
2466 }
67+ assert cli_options.long == 'val'
2568}
2669
27- fn test_long_tail_bool () {
28- cli_options , unmatched := flag.to_struct[CliOptions](args_bool_long ,
70+ fn test_v_style_long_bool () {
71+ cli_options , unmatched := flag.to_struct[CliOptions 2 ](args_bool_long_mixed ,
2972 skip: 1
3073 style: .v
3174 mode: .relaxed
@@ -39,4 +82,5 @@ fn test_long_tail_bool() {
3982 } else {
4083 assert false
4184 }
85+ assert cli_options.long == 'val'
4286}
0 commit comments