-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathargparse_example7.jl
67 lines (57 loc) · 2.18 KB
/
argparse_example7.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# example 7: argument groups
using ArgParse
function main(args)
s = ArgParseSettings("Example 7 for argparse.jl: " *
"argument groups.")
add_arg_group!(s, "stack options") # add a group and sets it as the default
@add_arg_table! s begin # all options (and arguments) in this table
# will be assigned to the newly added group
"--opt1"
action = :append_const
arg_type = String
constant = "O1"
dest_name = "O_stack"
help = "append O1 to the stack"
"--opt2"
action = :append_const
arg_type = String
constant = "O2"
dest_name = "O_stack"
help = "append O2 to the stack"
end
add_arg_group!(s, "weird options", "weird") # another group, this time with a tag which allows
# to refer to it
set_default_arg_group!(s, "weird") # set the default group (useless here, since we just added it)
@add_arg_table! s begin
"--awkward-option"
nargs = '+'
action = :append_arg
dest_name = "awk"
arg_type = String
range_tester = (x->x=="X"||x=="Y")
metavar = "XY"
help = "either X or Y; all XY's are " *
"stored in chunks"
end
set_default_arg_group!(s) # reset the default arg group (which means arguments
# are automatically assigned to commands/options/pos.args
# groups)
@add_arg_table! s begin
"-k"
action = :store_const
default = 0
constant = 42
help = "provide the answer"
"--şİłłÿ"
action = :store_true
help = "an option with a silly name"
group = "weird" # this overrides the default group: this option
# will be grouped together with --awkward-option
end
parsed_args = parse_args(args, s)
println("Parsed args:")
for (key,val) in parsed_args
println(" $key => $(repr(val))")
end
end
main(ARGS)