-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathargparse_example5.jl
55 lines (45 loc) · 1.95 KB
/
argparse_example5.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
# example 5: manual help/version, import another parser
using ArgParse
function main(args)
s0 = ArgParseSettings() # a "parent" structure e.g. one with some useful set of rules
# which we want to extend
# So we just add a simple table
@add_arg_table! s0 begin
"--parent-flag", "-o"
action=>"store_true"
help=>"parent flag"
"--flag"
action=>"store_true"
help=>"another parent flag"
"parent-argument"
help = "parent argument"
end
s = ArgParseSettings("Example 5 for argparse.jl: " *
"importing another parser, " *
"manual help and version.",
add_help = false, # disable auto-add of --help option
version = "Version 1.0") # we set the version info, but --version won't be added
import_settings!(s, s0) # now s has all of s0 arguments (except help/version)
s.error_on_conflict = false # do not error-out when trying to override an option
@add_arg_table! s begin
"-o" # this will partially override s0's --parent-flag
action = :store_true
help = "child flag"
"--flag" # this will fully override s0's --flag
action = :store_true
help = "another child flag"
"-?", "--HELP", "--¡ḧëļṕ" # (almost) all characters allowed
action = :show_help # will invoke the help generator
help = "this will help you"
"-v", "--VERSION"
action = :show_version # will show version information
help = "show version information" *
"and exit"
end
parsed_args = parse_args(args, s)
println("Parsed args:")
for (key,val) in parsed_args
println(" $key => $(repr(val))")
end
end
main(ARGS)