-
Notifications
You must be signed in to change notification settings - Fork 36
/
argparse_example8.jl
51 lines (43 loc) · 1.44 KB
/
argparse_example8.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# example 8: mutually exculsive and required groups
using ArgParse
function main(args)
s = ArgParseSettings("Example 8 for argparse.jl: " *
"mutually exclusive and requiredd groups.")
add_arg_group!(s, "Mutually exclusive options", exclusive=true)
@add_arg_table! s begin
"--maybe", "-M"
action = :store_true
help = "maybe..."
"--maybe-not", "-N"
action = :store_true
help = "maybe not..."
end
add_arg_group!(s, "Required mutually exclusive options", exclusive=true, required=true)
@add_arg_table! s begin
"--either", "-E"
action = :store_true
help = "choose the `either` option"
"--or", "-O"
action = :store_arg
arg_type = Int
help = "set the `or` option"
end
add_arg_group!(s, "Required arguments", required=true)
@add_arg_table! s begin
"--enhance", "-+"
action = :store_const
default = 0
constant = 42
help = "set the enhancement option"
"arg1"
nargs = 2 # eats up two arguments; puts the result in a Vector
help = "first argument, two " *
"entries at once"
end
parsed_args = parse_args(args, s)
println("Parsed args:")
for (key,val) in parsed_args
println(" $key => $(repr(val))")
end
end
main(ARGS)