使用argparse在julia中通过终端传递参数的正确方法是什么?

时间:2017-05-03 20:56:37

标签: julia argparse.jl

我想在julia中使用argparse传递参数,但我遇到了问题。

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)

我收到以下错误: 错误:LoadError:MethodError:没有匹配parse_commandline()的方法 最近的候选人是: parse_commandline(!Matched :: Any)at / home / usuario / practice_julia ProperMotion.jl:6 in include_from_node1(:: String)at ./loading.jl:488 在./client.jl:265的process_options(:: Base.JLOptions)中 在_start()at ./client.jl:321 加载/home/usuario/practice_julia/ProperMotion.jl时,从第27行开始的表达式

1 个答案:

答案 0 :(得分:0)

下一个代码可以正常工作。

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)