carlobaldassi / ArgParse.jl

Package for parsing command-line arguments to Julia programs.
Other
231 stars 36 forks source link

Argument missing from parsed dict #116

Closed albheim closed 2 years ago

albheim commented 2 years ago

For some reason it does not seem to recognize the second argument in the arg parse table.

File test.jl

using ArgParse

parse_settings = ArgParseSettings()
@add_arg_table parse_settings begin
    "--status"
        action = :store_true,
    "--kill"
        action = :store_true
end

args = parse_args(ARGS, parse_settings)
@show args

if args["status"]
    println("hello")
end
if args["kill"]
    println("bye")
end

Running with no arguments I expected both arguments to exist and to be false which does not seem to be the case.

> julia test.jl
args = Dict{String, Any}("status" => false)
ERROR: LoadError: KeyError: key "kill" not found
Stacktrace:
 [1] getindex(h::Dict{String, Any}, key::String)
   @ Base ./dict.jl:482
 [2] top-level scope
   @ test.jl:17
in expression starting at test.jl:17
carlobaldassi commented 2 years ago

Probably the trailing comma in the first action line?

albheim commented 2 years ago

Yeah, that seems to be it. I just wrote comma out of habit when listing things.

Maybe it should error on this instead of silently accepting what is before the comma and discarding rest? In this case the application errored later anyway, when not finding the value. But if you for example used to to send kwargs to some other function it could easily continue working, but not as intended.