Help screen:
$ julia argparse_example6.jl --help
usage: argparse_example_6.jl [-h] {run|jump}
Example 6 for argparse.jl: commands and their associated subtables.
commands:
run start running mode
jump start jumping mode
optional arguments:
-h, --help show this help message and exit
Passing a wrong command:
$ julia argparse_example6.jl fly
unknown command: fly
usage: argparse_example_6.jl [-h] {run|jump}
Commands have their own sub-helps:
$ julia argparse_example6.jl run --help
usage: argparse_example_6.jl run [--speed SPEED] [-h]
optional arguments:
--speed SPEED running speed, in Å/month (type: Float64, default:
10.0)
-h, --help show this help message and exit
$ julia argparse_example6.jl jump --help
usage: argparse_example_6.jl jump [--higher] [-h]
[--somersault|--clap-feet]
Jump mode for example 6
commands:
--somersault somersault jumping mode
--clap-feet clap feet jumping mode
optional arguments:
--higher enhance jumping
-h, --help show this help message and exit
$ julia argparse_example6.jl jump --clap-feet --help
usage: argparse_example_6.jl jump --clap-feet [-h]
optional arguments:
-h, --help show this help message and exit
The --clap-feet
sub-command has only the auto-added help, since we didn't provide and arg table.
Here is how the resulting Dict
looks like:
$ julia argparse_example6.jl run --speed "3*10^8"
Parsed args:
run => {"speed"=>3.0e8}
%COMMAND% => run
Command: run
Parsed command args:
speed => 3.0e8
Aside note: we passed an integer expression as option, it was evaluated and converted to Float64
.
Another run:
$ julia argparse_example6.jl jump --higher
Parsed args:
%COMMAND% => jump
jump => {"%COMMAND%"=>nothing,"higher"=>true}
Command: jump
Parsed command args:
%COMMAND% => nothing
higher => true
Need to go deeper?
$ julia argparse_example6.jl jump --clap-feet
Parsed args:
%COMMAND% => jump
jump => {"clap-feet"=>Dict{String,Any}(),"%COMMAND%"=>"clap-feet","higher"=>false}
Command: jump
Parsed command args:
clap-feet => Dict{String,Any}()
%COMMAND% => clap-feet
higher => false