Reputation: 97
I want to pass arguments using argparse in julia, but I'm having problems.
using ArgParse
function parse_commandline(args)
s = ArgParseSettings()
@add_arg_table s begin
"--hour"
help = "value in hour"
arg_type = Float64
required = true
#default = 0
"--minute"
help = "value in minute"
arg_type = Float64
required = true
#default = 0
"--second"
help = "value in second"
arg_type = Float64
required = true
#default = 0
end
return parsed_args(args, s)
end
pa = parse_commandline()
function ConvRAToDeg(hour, minutes, second)
return (hour + minutes/60 + second/3600)*15
end
h = pa["hour"]
m = pa["minute"]
s = pa["second"]
RA = ConvRAToDeg(h, m, s)
println(RA)
I get the following error: ERROR: LoadError: MethodError: no method matching parse_commandline() Closest candidates are: parse_commandline(!Matched::Any) at /home/usuario/practice_julia ProperMotion.jl:6 in include_from_node1(::String) at ./loading.jl:488 in process_options(::Base.JLOptions) at ./client.jl:265 in _start() at ./client.jl:321 while loading /home/usuario/practice_julia/ProperMotion.jl, in expression starting on line 27
Upvotes: 1
Views: 696
Reputation: 97
The next code works correctly.
function ConvRAToDeg(hour, minutes, second)
return (hour + minutes/60 + second/3600)*15
end
using ArgParse
function parse_commandline(args)
s = ArgParseSettings()
@add_arg_table s begin
"--h"
help = "value in hour"
arg_type = Float64
required = true
#default = 0
"--m"
help = "value in minute"
arg_type = Float64
required = true
#default = 0
"--s"
help = "value in second"
arg_type = Float64
required = true
#default = 0
end
pa = parse_args(args, s)
h = pa["h"]
m = pa["m"]
s = pa["s"]
RA = ConvRAToDeg(h, m, s)
println(RA)
end
parse_commandline(ARGS)
Upvotes: 1