1
1
import flag
2
2
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' ]
5
8
6
9
struct CliOptions {
7
10
show_help bool @[long: 'help' ; short: h]
8
11
}
9
12
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,
12
54
skip: 1
13
55
style: .v
14
56
mode: .relaxed
@@ -22,10 +64,11 @@ fn test_short_tail_bool() {
22
64
} else {
23
65
assert false
24
66
}
67
+ assert cli_options.long == 'val'
25
68
}
26
69
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 ,
29
72
skip: 1
30
73
style: .v
31
74
mode: .relaxed
@@ -39,4 +82,5 @@ fn test_long_tail_bool() {
39
82
} else {
40
83
assert false
41
84
}
85
+ assert cli_options.long == 'val'
42
86
}
0 commit comments